def get_action(self, board: BoardInfo) -> (int, int):

        self.get_alert(board)

        self.action_number = self.action_number + 1
        self.state.update_with_board_info(board)
        maxtime = 2
        if self.action_number == 1:
            maxtime = 5
        move = UCT(rootstate=self.state, maxtime=maxtime, verbose=False)
        print("Best Move: " + str(move))
        possible_x = int(move / self.state.n)
        possible_y = int(move % self.state.n)
        if board.is_legal_action(possible_x, possible_y):
            print("Move possible: %d,%d" % (possible_x, possible_y))
            return possible_x, possible_y
        else:
            print("Move not possible: %d,%d" % (possible_x, possible_y))
            # default to easy ai for now, need another solution
            for x in range(0, board.size_x):
                for y in range(0, board.size_y):
                    if board.is_legal_action(x, y):
                        return x, y
                    else:
                        continue
示例#2
0
    def get_action(self, board: BoardInfo):

        possible_actions = self.get_possible_actions(board)
        weighted_actions = self.get_weighted_actions(board, possible_actions)

        for ((x, y), _) in weighted_actions:
            if board.is_legal_action(x, y):
                return x, y

        return 5, 5
示例#3
0
    def get_possible_actions(board: BoardInfo):

        possible_actions = set()

        for ((x, y), _) in board.steps:
            for (dx, dy) in [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (-1, 1), (1, -1)]:
                if board.is_legal_action(x + dx, y + dy):
                    possible_actions.add((x + dx, y + dy))

        return possible_actions
示例#4
0
    def get_action(self, board: BoardInfo, timeout):

        possible_actions = self.get_possible_actions(board)
        weighted_actions = self.get_weighted_actions(board, possible_actions)

        for ((x, y), _) in weighted_actions:
            #print(board.steps[:])
            if board.is_legal_action(x, y):
                return x, y

        return 5, 5
示例#5
0
    def get_action(self, board: BoardInfo) -> (int, int):
        """
            Implement your algorithm here.

            **Important**
            1. You must return (x, y)
            2. If any exception is raised, you will lose the game directly. Use try-except to handle error/exception. 
            3. To get current state of the game, you could call board.dense or board.steps to get data.

            :return: int x, int y
            """

        for x in range(0, board.size_x):
            for y in range(0, board.size_y):
                if board.is_legal_action(x, y):
                    return x, y
                else:
                    continue
    def get_critical_actions(self, board: BoardInfo):

        deffensive_actions = []
        winning_actions = []
        for ((x, y), _) in board.steps:
            for (dx, dy) in [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1),
                             (-1, -1), (-1, 1), (1, -1)]:
                if board.is_legal_action(x + dx, y + dy):
                    weight = analysis_action(board, (x + dx, y + dy),
                                             self.color)
                    if weight >= 100:
                        deffensive_actions.append(((x + dx, y + dy), weight))

                    if weight <= -1:
                        winning_actions.append(((x + dx, y + dy), weight))

        deffensive_actions = sorted(deffensive_actions,
                                    key=lambda x: x[1],
                                    reverse=True)
        return deffensive_actions, winning_actions