Пример #1
0
    def __showGame(self, board):
        B = list(board)
        row_str = ""

        OKBLUE = '\033[94m'
        OKCYAN = '\033[96m'
        OKGREEN = '\033[92m'
        WARNING = '\033[93m'
        FAIL = '\033[91m'
        ENDC = '\033[0m'

        DebugUtils.space()
        for i in range(9):
            DebugUtils.info(
                "{}----- ----- ----- ----- ----- ----- ----- ----- -----{}",
                [OKGREEN, ENDC])
            row_str = ""
            for j in range(9):
                row_str += "" + OKGREEN + "| " + ENDC
                if B[i][j] == "WHITE":
                    row_str += "W"
                elif B[i][j] == "BLACK":
                    row_str += "" + WARNING + "B" + ENDC
                elif B[i][j] == "THRONE":
                    row_str += "" + OKBLUE + "T" + ENDC
                elif B[i][j] == "KING":
                    row_str += "" + FAIL + "K" + ENDC
                else:
                    row_str += " "
                row_str += "" + OKGREEN + " | " + ENDC
            DebugUtils.info(row_str, [])
            DebugUtils.info(
                "{}----- ----- ----- ----- ----- ----- ----- ----- -----{}",
                [OKGREEN, ENDC])
        DebugUtils.space()
Пример #2
0
    def getMorePromisingNode(self, tree_with_heuristics: GameTree, initialState: GameState) -> GameNode:

        root = tree_with_heuristics.root
        children = GameTree.getChildren(tree_with_heuristics.graph, root, False)

        if len(children) == 0:
            return None

        self.__elaborateNodeValues(tree_with_heuristics, initialState)

        bestNode = None
        heuristicValue = None
        #DebugUtils.info(" This root has {} children",[len(children)])
        DebugUtils.info("MinMaxAlogorithm", [])
        for node in children:
            DebugUtils.info("       next possible move {} value {}",
                            [str(node.moves), node.heuristic])
            if heuristicValue is None:
                heuristicValue = node.heuristic
                bestNode = node
            elif root.turn == self.max and node.heuristic > heuristicValue:
                heuristicValue = node.heuristic
                bestNode = node
            elif root.turn == self.min and node.heuristic < heuristicValue:
                heuristicValue = node.heuristic
                bestNode = node
        DebugUtils.info("       Best move is {}", [str(bestNode.moves)])
        DebugUtils.space()

        return bestNode
Пример #3
0
    def start(self):
        DebugUtils.space()
        initial_state = self.SocketManager.initialize()

        # try to play (if I'm the white player ...).
        self.play(initial_state)

        while not self.__is_finished():
            self.SocketManager.listen(self)
Пример #4
0
def __parse_args():
    parser = argparse.ArgumentParser(description='Fpm AI Tablut Player')
    parser.add_argument(
        '--role',
        dest='role',
        choices={CONFIGS._PLAYER_ROLE_BLACK_ID, CONFIGS._PLAYER_ROLE_WHITE_ID},
        help='player role'
    )
    parser.add_argument(
        '--timeout',
        dest='timeout',
        action='store',
        help='move timeout',
        default=CONFIGS.GAME_MOVE_TIMEOUT
    )
    parser.add_argument(
        '--server',
        dest='server',
        action='store',
        help='server ip address',
        default=CONFIGS.SERVER_HOST
    )

    arguments = parser.parse_args()

    if not arguments.role:
        parser.print_help()
        sys.exit()

    if arguments.server:
        CONFIGS.SERVER_HOST = str(arguments.server)
    if arguments.timeout:
        timeout = float(arguments.timeout)
        if timeout >= 10:
            CONFIGS.GAME_MOVE_TIMEOUT = timeout
        else:
            raise Exception("Timeout argument must be at least {:} seconds".format(10))

    computationTimeNotAvailablePercentage = float(CONFIGS._APP_COMPUTATION_TIME_NEEDED_PERCENTAGE)
    CONFIGS.GAME_TREE_GENERATION_TIMEOUT = 1 - computationTimeNotAvailablePercentage
    CONFIGS.GAME_TREE_GENERATION_TIMEOUT *= float(CONFIGS.GAME_MOVE_TIMEOUT)

    CONFIGS.APP_ROLE = str(arguments.role)

    if CONFIGS.APP_ROLE == CONFIGS._PLAYER_ROLE_BLACK_ID:
        CONFIGS.SERVER_PORT = CONFIGS._SOCKET_BLACK_PLAYER_PORT
    else:
        CONFIGS.SERVER_PORT = CONFIGS._SOCKET_WHITE_PLAYER_PORT

    DebugUtils.space()
    DebugUtils.info("ROLE         =  {}", [CONFIGS.APP_ROLE])
    DebugUtils.info("SERVER_PORT  =  {}", [CONFIGS.SERVER_PORT])
    DebugUtils.info("CPU_COUNT    =  {}", [multiprocessing.cpu_count()])
    DebugUtils.space()