def action(self, turns):
        self.minimax.update_board(self.board)

        if turns == 0 and self.board.phase == constant.MOVING_PHASE:
            self.board.move_counter = 0
            self.board.phase = constant.MOVING_PHASE

        # find the best move
        best_move = self.minimax.itr_negascout()
        # if the best move we have found so far is a Forfeit -- return this
        if best_move is None:
            self.board.update_board(best_move, self.colour)
            self.minimax.update_board(self.board)
            return None

        self.depth_eval = self.minimax.eval_depth
        self.minimax_val = self.minimax.minimax_val

        # once we have found the best move we must apply it to the board representation
        if self.board.phase == constant.PLACEMENT_PHASE:
            # print(best_move)
            self.board.update_board(best_move, self.colour)
            self.minimax.update_board(self.board)
            return best_move
        else:
            # (best_move is None)
            # print(best_move[0],best_move[1])
            new_pos = Board.convert_direction_to_coord(best_move[0], best_move[1])
            self.board.update_board(best_move, self.colour)
            self.minimax.update_board(self.board)
            return best_move[0], new_pos
class Player:
    def __init__(self, colour):
        if colour == 'white':
            self.colour = constant.WHITE_PIECE
        elif colour == 'black':
            self.colour = constant.BLACK_PIECE

        # each players internal board representation
        self.board = Board()

        self.opponent = self.board.get_opp_piece_type(self.colour)

    def update(self, action):

        # update the board based on the action of the opponent
        # get move type
        if self.board.phase == constant.PLACEMENT_PHASE:
            self.board.update_board(action, self.opponent)

        elif self.board.phase == constant.MOVING_PHASE:
            if isinstance(action[0], tuple) is False:
                raise InvalidAction

            direction = self.board.convert_coord_to_direction(
                action[0], action[1])
            self.board.update_board((action[0], direction), self.opponent)

    def action(self, turns):
        available_actions = self.board.update_actions(self.colour)
        available_actions.sort()

        for i, action in enumerate(available_actions):
            print(str(i) + " : " + str(action))

        print("+" * 50)
        index = int(input("Enter move for {}: ".format(self.colour)))
        next_move = available_actions[index]
        print("+" * 50)

        print(self.board.move_counter)
        if self.board.phase == constant.PLACEMENT_PHASE:

            # making moves during the placement phase
            self.board.update_board(next_move, self.colour)
            return next_move
        else:
            new_pos = self.board.convert_direction_to_coord(
                next_move[0], next_move[1])
            # making moves during the placement phase
            self.board.update_board(next_move, self.colour)
            return next_move[0], new_pos
Esempio n. 3
0
    def action(self, turns):

        # update the negamax/minimax board representation
        self.minimax.update_board(self.board)

        # reset the move counter of the board
        if turns == 0 and self.board.phase == constant.MOVING_PHASE:
            self.board.move_counter = 0
            self.board.phase = constant.MOVING_PHASE

        # check the action book to see if there is a state
        board_state = self.board.board_state
        if self.board.phase == constant.PLACEMENT_PHASE:
            action = self.action_book.check_state(board_state)

            # check if the action is legal
            if action is not None and self.board.check_free_square(
                    action) is True:
                # return the action found and update the board representations
                self.board.update_board(action, self.colour)
                self.minimax.update_board(self.board)
                return action

        # if there is no found state in the action book, therefore we just do a negamax search
        best_move = self.minimax.itr_negamax()

        self.depth_eval = self.minimax.eval_depth
        self.minimax_val = self.minimax.minimax_val

        # do an alpha beta search on this node
        # once we have found the best move we must apply it to the board representation
        if self.board.phase == constant.PLACEMENT_PHASE:
            self.board.update_board(best_move, self.colour)
            self.minimax.update_board(self.board)
            return best_move
        else:
            # if we are in moving phase, return the correctly formatted positions
            if best_move is None:
                self.board.update_board(best_move, self.colour)
                self.minimax.update_board(self.board)
                return None

            new_pos = Board.convert_direction_to_coord(best_move[0],
                                                       best_move[1])
            self.board.update_board(best_move, self.colour)
            self.minimax.update_board(self.board)
            return best_move[0], new_pos
Esempio n. 4
0
class Player:
    def __init__(self, colour):
        if colour == 'white':
            self.colour = constant.WHITE_PIECE
        elif colour == 'black':
            self.colour = constant.BLACK_PIECE

        # each players internal board representation
        self.board = Board()

        self.opponent = self.board.get_opp_piece_type(self.colour)

    def update(self, action):

        # update the board based on the action of the opponent
        # get move type
        if self.board.phase == constant.PLACEMENT_PHASE:
            self.board.update_board(action, self.opponent)

        elif self.board.phase == constant.MOVING_PHASE:
            if isinstance(action[0], tuple) is False:
                raise InvalidAction

            direction = self.board.convert_coord_to_direction(
                action[0], action[1])
            self.board.update_board((action[0], direction), self.opponent)
        # print("UPDATE BOARD _______________________________")
        # print(self.board)
        # print("UPDATE BOARD _______________________________")

    def action(self, turns):
        available_actions = self.board.update_actions(self.colour)
        next_action = available_actions[randint(0, len(available_actions) - 1)]

        if self.board.phase == constant.PLACEMENT_PHASE:
            # making moves during the placement phase
            self.board.update_board(next_action, self.colour)
            # print(next_action)
            return next_action
        else:
            new_pos = self.board.convert_direction_to_coord(
                next_action[0], next_action[1])
            # making moves during the placement phase
            # print(next_action)
            self.board.update_board(next_action, self.colour)
            #print(next_action)
            return next_action[0], new_pos