예제 #1
0
    def getGameEnded(self, board, player, turn, end_Evaluate=False):
        """
        Input:
            board: cannoical board
            player: int, 1 = white, -1 = black
            turn: [0.......23] = 24 turns in total = for i in range(0,24)
        return:
            0 nothing
            1 player Won
            -1 player Lost
        """
        if turn < 24:
            return 0
        else:
            if end_Evaluate:
                print("Start Board:\n%s" % (np.array(board).reshape(8, 8)))
                result = endEvaluator.playGame(board)
                return result
            else:
                b = Board(self.n)
                b.pieces = np.copy(board)
                if b.countDiff(player) > 0:
                    return 1
                elif b.countDiff == 0:
                    return 1e-4  #tie condiitiion

                return -1
예제 #2
0
 def getScore(self, board, player):
     """
     Input:
         board: np array
         player: WHITE BLACK
     return:
         score of player
     """
     b = Board(self.n)
     b.pieces = np.copy(board)
     return b.countDiff(player)
예제 #3
0
 def getValidMoves(self, board, player):
     # return a fixed size binary vector
     # moves, on the same ROWWWWWWWWWWW are grouped together
     valids = [0] * self.getActionSize()
     b = Board(self.n)
     b.pieces = np.copy(board)
     legalMoves = b.get_legal_moves(player)  #in the form (column, row)
     if len(legalMoves) == 0:
         valids[-1] = 1
         return np.array(valids)
     for x, y in legalMoves:
         valids[self.n * y + x] = 1  #since all rows are grouped together
     return np.array(valids)
예제 #4
0
    def getNextState(self, board, player, action):
        # if player takes action on board, return next (board,player)
        # action must be a valid move
        # 2 = (2,0)
        # currently action = an Integer
        if action == self.n * self.n:
            return (board, -player)
        b = Board(self.n)
        b.pieces = np.copy(board)
        #even in string representation, we concat column by column
        #picese are grouped by column
        move = (
            action % self.n,
            action // self.n,
        )  #(column, row) (int(a/b))
        b.execute_move(move, player)

        return (b.pieces, -player)
예제 #5
0
    def getGameEnded(self, board, player, turn):
        """
        Input:
            board: cannoical board
            player: int, 1 = white, -1 = black
            turn: [0.......23] = 24 turns in total = for i in range(0,24)
        return:
            0 nothing
            1 player Won
            -1 player Lost
        """
        b = Board(self.n)
        b.pieces = np.copy(board)
        if turn < 24:  #4: for adding turn parameter
            return 0
        else:
            if b.countDiff(player) > 0:
                return 1
            elif b.countDiff == 0:
                return 1e-4  #tie condiitiion

        return -1
예제 #6
0
 def getInitBoard(self):
     # return initial board (numpy board)
     b = Board(self.n)
     return np.array(b.pieces)