def test_malformed_tables(self): # Test a malformed table transitions = ((1, D, 2, D), (1, C, 1, D), (2, C, 1, D), (2, D, 3, C), (3, C, 3, C)) player = axelrod.FSMPlayer(transitions=transitions, initial_state=1, initial_action=C) self.assertFalse(check_state_transitions(player.fsm.state_transitions)) transitions = [(1, D, 2, D)] player = axelrod.FSMPlayer(transitions=transitions, initial_state=1, initial_action=C) self.assertFalse(check_state_transitions(player.fsm.state_transitions))
def test_defector(self): """Tests that the player defined by the table for Defector is in fact Defector.""" transitions = [(1, C, 1, D), (1, D, 1, D)] player = axelrod.FSMPlayer(transitions, initial_state=1, initial_action=D) opponent = axelrod.Alternator() for i in range(6): player.play(opponent) self.assertEqual(opponent.history, [C, D] * 3) self.assertEqual(player.history, [D] * 6)
def test_wsls(self): """Tests that the player defined by the table for TFT is in fact WSLS (also known as Pavlov.""" transitions = [(1, C, 1, C), (1, D, 2, D), (2, C, 2, D), (2, D, 1, C)] player = axelrod.FSMPlayer(transitions, initial_state=1, initial_action=C) opponent = axelrod.Alternator() for i in range(6): player.play(opponent) self.assertEqual(opponent.history, [C, D] * 3) self.assertEqual(player.history, [C, C, D, D, C, C])
(2, C, 14, D), (2, D, 9, D), (3, C, 0, C), (3, D, 1, D), (4, C, 1, D), (4, D, 2, D), (5, C, 12, C), (5, D, 6, C), (6, C, 1, C), (6, D, 14, D), (7, C, 12, D), (7, D, 2, D), (8, C, 7, D), (8, D, 9, D), (9, C, 8, D), (9, D, 0, D), (10, C, 2, C), (10, D, 15, C), (11, C, 7, D), (11, D, 13, D), (12, C, 3, C), (12, D, 8, D), (13, C, 7, C), (13, D, 10, D), (14, C, 10, D), (14, D, 7, D), (15, C, 15, C), (15, D, 11, D)], [(0, C, 0, C), (0, D, 3, C), (1, C, 5, D), (1, D, 0, C), (2, C, 3, C), (2, D, 2, D), (3, C, 4, D), (3, D, 6, D), (4, C, 3, C), (4, D, 1, D), (5, C, 6, C), (5, D, 3, D), (6, C, 6, D), (6, D, 6, D), (7, C, 7, D), (7, D, 5, C)]] fsm_players = [ axl.FSMPlayer(transitions=transitions) for transitions in fsm_transitions ] fsm_players += [ axl.FSMPlayer(transitions=transitions, initial_state=0, initial_action=C) for transitions in fsm_transitions ] fsm_players[3].classifier["memory_depth"] = float('inf') fsm_players[4].classifier["memory_depth"] = float('inf') fsm_players[5].classifier["memory_depth"] = float('inf') def selected_players(extra_players=fsm_players): """ Return a list of all players used in this paper """
def test_player(self): num_states = 2 rows = [[0, C, 1, D], [0, D, 0, D], [1, C, 1, C], [1, D, 1, D]] fsm_params = FSMParams(num_states=num_states, rows=rows) self.assertEqual(fsm_params.player(), axl.FSMPlayer(rows, initial_state=0))