コード例 #1
0
 def get_next_state(self, board, player, move):
     if (action == 8 * 8):
         return (board, player)
     b = Board()
     b.pieces = np.copy(board)
     move = (int(action / 8), action % 8)
     b.executeMove(player, move)
     return (b.pieces, -player)
コード例 #2
0
 def getNextState(self, board, player, action):
     # if player takes action on board, return next (board,player)
     # action must be a valid move
     if action == self.n * self.n:
         return (board, -player)
     b = Board(self.n)
     b.pieces = np.copy(board)
     move = (int(action / self.n), action % self.n)
     b.execute_move(move, player)
     return (b.pieces, -player)
コード例 #3
0
 def getGameEnded(self, board, player):
     # return 0 if not ended, 1 if player 1 won, -1 if player 1 lost
     # player = 1
     b = Board(self.n)
     b.pieces = np.copy(board)
     if b.has_legal_moves(player):
         return 0
     if b.has_legal_moves(-player):
         return 0
     if b.countDiff(player) > 0:
         return 1
     return -1
コード例 #4
0
 def getValidMoves(self, board, player):
     # return a fixed size binary vector
     valids = [0] * self.getActionSize()
     b = Board(self.n)
     b.pieces = np.copy(board)
     legalMoves = b.get_legal_moves(player)
     if len(legalMoves) == 0:
         valids[-1] = 1
         return np.array(valids)
     for x, y in legalMoves:
         valids[self.n * x + y] = 1
     return np.array(valids)
コード例 #5
0
 def getScore(self, board, player):
     b = Board(self.n)
     b.pieces = np.copy(board)
     return b.countDiff(player)