我正在写代码来自动模拟Theseus和Minoutaur的行为,如此逻辑游戏中所示; http://www.logicmazes.com/theseus.htmlJava迷宫解决和强化学习
对于每个迷宫,我提供迷宫的位置,以及哪些位置可用,例如从位置0开始,下一个状态是1,2或停留在0上。我运行一个QLearning实例化,计算最佳路径Theseus逃离迷宫,假设没有牛头怪。然后引入牛头怪。 Theseus第一次走向出口,不可避免地被抓住,导致重新调整最佳路径。在游戏中使用迷宫3作为测试,这种方法导致他们在中间线上无限地上下移动,因为这是唯一没有被杀死的移动。
根据在过去几天内收到的建议,我调整了我的代码,将状态视为在给定时间既是thesesus也是minotaur的位置。当这些动作移动时,状态将被添加到“访问状态”列表中。通过将所建议的动作所产生的状态与访问状态列表进行比较,我能够确保这些动作不会导致以前的状态。
问题是我需要能够在某些情况下重新访问。例如使用迷宫3作为例子,牛头怪为每个移动移动2x。忒修斯移动4 - > 5,添加状态(t5,m1)。 mino移动1-> 5。忒修斯抓住了,重置。 4-> 5是一个糟糕的举动,所以他们会移动4-> 3,米诺在轮到他。 (t5,m1)和(t3 m1)都在访问列表中
发生什么是所有可能的状态从初始状态添加到不访问列表,这意味着我的代码无限循环并且不能提供解决方案。
public void move()
{
int randomness =10;
State tempState = new State();
boolean rejectMove = true;
int keepCurrent = currentPosition;
int keepMinotaur = minotaurPosition;
previousPosition = currentPosition;
do
{
minotaurPosition = keepMinotaur;
currentPosition = keepCurrent;
rejectMove = false;
if (states.size() > 10)
{
states.clear();
}
if(this.policy(currentPosition) == this.minotaurPosition)
{
randomness = 100;
}
if(Math.random()*100 <= randomness)
{
System.out.println("Random move");
int[] actionsFromState = actions[currentPosition];
int max = actionsFromState.length;
Random r = new Random();
int s = r.nextInt(max);
previousPosition = currentPosition;
currentPosition = actions[currentPosition][s];
}
else
{
previousPosition = currentPosition;
currentPosition = policy(currentPosition);
}
tempState.setAttributes(minotaurPosition, currentPosition);
randomness = 10;
for(int i=0; i<states.size(); i++)
{
if(states.get(i).getMinotaurPosition() == tempState.getMinotaurPosition() && states.get(i).theseusPosition == tempState.getTheseusPosition())
{
rejectMove = true;
changeReward(100);
}
}
}
while(rejectMove == true);
states.add(tempState);
}
以上是忒修斯的移动方法;显示它偶尔会暗示一个随机移动
我不希望任何人为我编写这个代码,我只是在寻找如何解决这个问题的想法。显然我需要能够阻止重访以前的状态,但处理重置时被捕获是问题 – confusified 2012-03-25 17:22:14