Beispiel #1
0
    def play(self, board):
        # display(board)
        valid = self.game.getValidMoves(board, 1)

        print('hp: possible moves: ', end="")
        for i in range(len(valid)):
            if valid[i]:
                print(i, end=' ')
        print('')

        while True:
            # Python 3.x
            a = input()
            # Python 2.x
            # a = raw_input()

            x = 0
            for y in a.split(' '):
                x = int(y)
            a = x if x != -1 else 2 * self.game.n
            if a >= 0 and a <= self.game.n and valid[a]:
                break
            else:
                print('hp: Invalid')

        select = a
        b = Board(6)
        b.pieces = np.copy(board)
        b.check_board(select, prefix="hp: ")

        return a
Beispiel #2
0
    def play(self, board):
        '''
        :param board: the current configuration of the board
        :return: if more actions have the same value, which is the best one, it returns randomly one action from these
        '''
        valids = self.game.getValidMoves(board, 1)
        candidates = []
        for a in range(self.game.getActionSize()):
            if valids[a] == 0:
                continue
            nextBoard, _ = self.game.getNextState(board, 1, a)
            score = self.game.getScore(nextBoard, 1)
            candidates += [(-score, a)]
        candidates.sort()
        list = []
        max = candidates[0][0]
        for i in range(len(candidates)):
            if candidates[i][0] == max:
                list.append(candidates[i][1])
        select = random.choice(list)

        b = Board(6)
        b.pieces = np.copy(board)
        b.check_board(select, prefix="gp: ")

        return select
    def play(self, board):
        args1 = dotdict({'numMCTSSims': args.mcts, 'cpuct': args.cpuct})
        mcts1 = MCTS(self.game, self.n1, args1)
        actions = mcts1.getActionProb(board, temp=1)
        select = np.argmax(actions)
        #print('board: ', end="")
        #print(board)
        #print('action p-values: ' + str(actions))

        b = Board(6)
        b.pieces = np.copy(board)
        b.check_board(select, prefix="nn: ")

        return select
Beispiel #4
0
    def play(self, board):
        '''
        :param board: the configuration of the board
        :return: the action from the tuple (action, score) where this action is the best action detected by alfa-beta
        '''

        score = self.minimax((board, -1), self.depth, 1, -infinity, +infinity)
        print("mp: minmax at depth " + str(self.depth))
        select = score[0]
        print("mp: select " + str(select))

        b = Board(6)
        b.pieces = np.copy(board)
        b.check_board(select, prefix="mp: ")

        return select
Beispiel #5
0
    def play(self, board):
        select = np.random.randint(self.game.getActionSize())
        valid = self.game.getValidMoves(board, 1)
        print('rp: possible moves: ', end="")
        for i in range(len(valid)):
            if valid[i]:
                print(i, end=' ')
        print('')

        while valid[select] != 1:
            select = np.random.randint(self.game.getActionSize())
        print('rp: select ' + str(select))

        b = Board(6)
        b.pieces = np.copy(board)
        b.check_board(select, prefix="rp: ")
        return select