def reset(self):
     '''
     reset all stateful things
     which is only the statemachine
     in command line players
     '''
     self.statemachine = state_machine.StateMachine()
Beispiel #2
0
 def reset(self):
     '''
     re-initialise all stateful things
     '''
     del self.statemachine
     self.statemachine = state_machine.StateMachine()
     self._init_tree()
Beispiel #3
0
def black_tree():
    statemachine = state_machine.StateMachine()
    model = mock_model.MockModel()
    tree = azts_tree.AztsTree(model=model, \
            color=BLACK, \
            rollouts_per_move=10)
    return tree
Beispiel #4
0
def rollout_node():
    model = mock_model.MockModel()
    # testing: model responds with all ones
    when(model).inference(...).thenReturn((np.ones(MOVE_TENSOR_SHAPE), 1))
    statemachine = state_machine.StateMachine()
    node = azts_node.AztsNode(statemachine, model)
    for i in range(10):
        node.rollout()
    return node
 def __init__(self, name="THEMIGHTYFISH", color=WHITE, time_limit=0.1, **kwargs):
     '''
     CLIPlayer is indeed keeping state,
     because there is no azts_tree
     involved to keep state
     '''
     # super().__init__(name, color, **kwargs) # necessary??
     self.name = name
     self.color = color
     self.statemachine = state_machine.StateMachine()
     self.limit = time_limit
     self.tree = None
 def __init__(self,
              other_player,
              name="UNNAMED PLAYER",
              color=WHITE):
     '''
     CLIPlayer is indeed keeping state,
     because there is no azts_tree
     involved to keep state
     '''
     self.other_player = other_player
     self.name = name
     self.color = color
     self.statemachine = state_machine.StateMachine()
Beispiel #7
0
def set_up(color=WHITE):
    '''
    helper function to initialise all
    data structures
    :return tuple: containing a state machine,
    a model and an azts tree that has been
    initialised with that state machine and model.
    '''
    statemachine = state_machine.StateMachine()
    model = mock_model.MockModel()
    tree = AztsTree(statemachine=statemachine, \
                model=model, \
                color=color, \
                rollouts_per_move=200)

    np.set_printoptions(suppress=True, precision=3)

    return statemachine, model, tree
Beispiel #8
0
    def __init__(self, \
                 model, \
                 color=WHITE, \
                 rollouts_per_move=ROLLOUTS_PER_MOVE, \
                 exploration=EXPLORATION, \
                 payoffs=ROLLOUT_PAYOFFS, \
                 heat=HEAT):

        self.color = color

        self.statemachine = state_machine.StateMachine()
        self.model = model
        self.rollouts_per_move = rollouts_per_move
        self.heat = heat

        # for initialising azts nodes:
        self.exploration = exploration
        self.payoffs = payoffs 

        self._init_tree()
Beispiel #9
0
def initial_node():
    model = mock_model.MockModel()
    statemachine = state_machine.StateMachine()
    node = azts_node.AztsNode(statemachine, model)
    return node
Beispiel #10
0
def suspension_draw():
    suspended_draw = "7K/k7/7R/8/8/8/8/1R6 b - - 10 20"
    statemachine = state_machine.StateMachine()
    statemachine.set_to_fen_state(suspended_draw)
    return statemachine
Beispiel #11
0
def sm_noblacksuspense():
    no_black_suspense = "7k/K7/8/8/8/8/R7/8 w - - 10 20"
    statemachine = state_machine.StateMachine()
    statemachine.set_to_fen_state(no_black_suspense)
    return statemachine
Beispiel #12
0
def statemachine_suspended():
    suspended_win = "7K/k7/8/8/8/8/7R/8 b - - 10 20"
    statemachine = state_machine.StateMachine()
    statemachine.set_to_fen_state(suspended_win)
    return statemachine
Beispiel #13
0
def statemachine_win():
    statemachine = state_machine.StateMachine()
    win_state = "7k/8/8/8/8/8/R7/5K2 w - - 10 20"
    statemachine.set_to_fen_state(win_state)
    return statemachine
Beispiel #14
0
def statemachine_stalemate():
    statemachine = state_machine.StateMachine()
    new_state = "8/8/8/8/8/8/R7/5K1k b - - 10 20"
    statemachine.set_to_fen_state(new_state)
    return statemachine
Beispiel #15
0
def statemachine_init():
    return state_machine.StateMachine()
Beispiel #16
0
def stale_node():
    model = mock_model.MockModel()
    statemachine = state_machine.StateMachine()
    statemachine.set_to_fen_state(STALE_MATE)
    node = azts_node.AztsNode(statemachine, model, BLACK)
    return node
Beispiel #17
0
def lose_node():
    model = mock_model.MockModel()
    statemachine = state_machine.StateMachine()
    statemachine.set_to_fen_state(WIN_STATE)
    node = azts_node.AztsNode(statemachine, model, WHITE)
    return node
Beispiel #18
0
    def _position_as_tensor(self):
        """
        :return: tensor notation of current position
        :rtype: np.array
        """
        tensor = np.zeros(self.position_shape, dtype=POS_DTYPE)
        tensor[self.position] = 1
        return tensor

    def get_position(self):
        """
        :return: current position in tensor notation
        :rtype: np.array
        """
        board = np.zeros(self.position_shape, dtype=POS_DTYPE)
        board[self.position] = 1
        return board

    # pylint: enable=C0326


if __name__ == "__main__":
    statemachine = state_machine.StateMachine()
    mock_model = mock_model.MockModel()
    node = AztsNode(statemachine, mock_model)
    for i in range(25):
        node.rollout()

    print(node)
# pylint: enable=W0621