我有一块6x6(一个多维数组)板,我想为每一块产生下一步动作,它允许回来,转到垂直,水平和垂直位置,一个方格,如果有&# 39;在一个给定的方向上有一个正方形的n个方格,并且在相同的方向上有一个n + 1个空方格,可以跳过"跳跃"在这件作品之上并停在n + 1平方。
如何生成可能的移动树? 我有以下代码:
def generate_children(depth,board,move):
tree = []
# node = board[move[2]][move[3]]
# if(node in board): #if exists in the board
for i in range(6):
for j in range(6):
newboard = printBoard(board[i][j])
if(is_allowed(newboard,move,"x")):
tree.append(move)
print tree
return tree
def is_allowed(board,move,player):
if((board[move[2]][move[3]] == "x") or (board[move[2]][move[3]] == "o")):
return False
if(board[move[0]][move[1]] == player):
if(
((move[2] == (move[0] + 1)) or (move[2] == (move[0] - 1)) or ( (move[2] == move[0]) and (move[3] != move[1])))
and ((move[3] == (move[1] -1)) or (move[3] == (move[1]+1)) or( (move[3] == move[1]) and (move[2] != move[0]) ) ) ):
return True
else:
return False
else:
return False