Esempio n. 1
0
class Strategy_Tester():
    """
    Class to parse test input and get output for a strategy
    """
    def __init__(self, pid):
        """
        Initializes a strategy test parser
        """
        self.board = GameBoard()
        self.strategy = Strategy(pid, init=self.board)
        self.__cmd_handler = Cmd_Handler(lambda x: x[0])
        self.__cmd_handler.register_cmd("move", lambda x: strat_move(x, self))
        self.__cmd_handler.register_cmd("+build", lambda x: strat_build(x, self))
        self.prev_move = None

    def set_board(self, cells):
        """
        Sets up the board to be used with this test parser

        :param cells:   JSON representing the state of the board from given spec
        """
        build_board(cells, self)

    def parse(self, cmd):
        """
        Parses the given command and invokes the appropriate function to run

        :param cmd: JSON that represents a valid query according to given spec
        """
        return self.__cmd_handler.handle_cmd(cmd)
Esempio n. 2
0
class Board_Tester():
    """
    Class to parse test input and get output for a board
    """
    def __init__(self):
        """
        Initializes a board test parser
        """
        self.board = GameBoard()
        self.__cmd_handler = Cmd_Handler(lambda x: x[0])
        self.__cmd_handler.register_cmd("move", lambda x: board_move(x, self))
        self.__cmd_handler.register_cmd("build",
                                        lambda x: board_build(x, self))
        self.__cmd_handler.register_cmd("neighbors",
                                        lambda x: neighbors_func(x, self))
        self.__cmd_handler.register_cmd("occupied?",
                                        lambda x: occupied_func(x, self))
        self.__cmd_handler.register_cmd("height",
                                        lambda x: height_func(x, self))

    def set_board(self, cells):
        """
        Sets up the board to be used with this test parser

        :param cells:   JSON representing the state of the board from given spec
        """
        build_board(cells, self)

    def parse(self, cmd):
        """
        Parses the given command and invokes the appropriate function to run

        :param cmd: JSON that represents a valid query according to given spec
        """
        return self.__cmd_handler.handle_cmd(cmd)
Esempio n. 3
0
    def __init__(self, pid, rule_checker, init):
        """
        Initializes a strategy object for use

        :param pid:     String identifing a player
        :param init:    Optional Santoini GameBoard that represents initial state
        """
        self.__pid = pid
        self.__rule_checker = rule_checker

        cmd_handler = Cmd_Handler(lambda x: x['type'])
        cmd_handler.register_cmd('place', self.decide_place)
        self.__cmd_handler = cmd_handler

        self.__state = init
    def __init__(self, pid, init=None):
        """
        Initializes a strategy object for use

        :param pid:     String identifing a player
        :param init:    Optional Santoini GameBoard that represents initial state
        """
        self.__pid = pid

        cmd_handler = Cmd_Handler(lambda x: x['type'])
        cmd_handler.register_cmd('place', self.decide_place)
        self.__cmd_handler = cmd_handler

        if not init:
            self.init_state(init)
        else:
            self.__state = None
Esempio n. 5
0
    def __init__(self, pid, init=None):
        """
        Initializes a strategy object for use

        :param pid:     String identifing a player
        :param init:    Optional Santoini GameBoard that represents initial state
        """
        self.__pid = pid

        cmd_handler = Cmd_Handler(lambda x: x['type'])
        cmd_handler.register_cmd('build', self.decide_build)
        cmd_handler.register_cmd('move', self.decide_move)
        self.__cmd_handler = cmd_handler

        self.__opponent = None
        self.look_ahead = 0

        self.__state = None

        if init:
            self.init_state(init)
Esempio n. 6
0
    def __init__(self, board):
        """
        Initializes a StackBoard

        :param board: A GameBoard
        Attributes:
            _action_storage: list of actions on this 'stack'
            __fwd_cmd: How to deal with an action while pushing
            __rev_cmd: how to deal with an action while popping
        """
        self._action_storage = []
        self.board = board

        fwd_cmd = Cmd_Handler(lambda x: x['type'])
        fwd_cmd.register_cmd('place', self.__place_worker)
        fwd_cmd.register_cmd('move', self.__move_worker)
        fwd_cmd.register_cmd('build', self.__build_floor)
        self.__fwd_cmd = fwd_cmd

        rev_cmd = Cmd_Handler(lambda x: x['type'])
        rev_cmd.register_cmd('place', self.__remove_worker)
        rev_cmd.register_cmd('move', self.__reverse_worker)
        rev_cmd.register_cmd('build', self.__remove_floor)
        self.__rev_cmd = rev_cmd