大家好,我正在战斗中编码一个狩猎阶段(人工智能做棋盘格局)。在此之后,我必须进行定位阶段。但是我的狩猎阶段的问题是,当连续两次点击时,游戏只会经历一个无限循环,我不确定我哪里出错了。这是我到目前为止的计算机移动代码:
def compMove(game):
moveLigit = False
pick = True
while (not moveLigit):
while game.previousTurn == '#'
and pick == True:
if game.twohits == 'no':
for i in range(10):
for j in range(10):
if game.userBoard[i][j] == '#':
c = random.randint(0, 1)
if c == 0:
x = random.randint(i - 1, i + 1)
y = j
game.twohits = 'yes'
pick = False
else :
x = i
y = random.randint(j - 1, j + 1)
game.twohits = 'sure'
pick = False
if game.twohits == 'yes':
for i in range(10):
for j in range(10):
if game.userBoard[i][j] == '#':
x = random.randint(i - 1, i + 1)
y = j
pick = False
else :
for i in range(10):
for j in range(10):
if game.userBoard[i][j] == '#':
x = i
y = random.randint(j - 1, j + 1)
pick = False
pick = False
if game.previousTurn != '#':
x = random.choice([1, 3, 5, 7, 9]) - 1# Make a checkerboard pattern of random selection
y = random.choice([2, 4, 6, 8, 10]) - 1
beforeDropped = game.makeA_Move(True, x, y)# displaying current boards
game.drawBoards(True)
labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
if beforeDropped == "*"
or beforeDropped == "#":
moveLigit = False
elif beforeDropped == " ":
print("Sorry computer, " + labels[x] + " " + str(y + 1) + " is a miss.")
game.twohits = 'no'
moveLigit = True
else :
print("Computer did a Hit at " + labels[x] + " " + str(y + 1))
if game.checkIfSunk(True, beforeDropped):
print(whatShip(beforeDropped) + " sunk")
game.twohits = 'no'
game.previousTurn = ' '
moveLigit = True
return game.checkWinning(True)
对此的任何帮助将不胜感激。提前谢谢。