def test_minimaxTreeSearch_defector(self): """ Tests the minimax_tree_search function when playing against a Defector player. The best answer to Defector is to always defect """ expected_output = [1, 1, 1, 1] for inp, out in zip(self.input_pos, expected_output): begin_node = dbs.DeterministicNode(inp[0], inp[1], depth=0) values = dbs.minimax_tree_search(begin_node, self.defector_policy, max_depth=5) self.assertEqual(values.index(max(values)), out)
def test_last_node_titForTat(self): """ Test that against TitForTat, for the last move, i.e. if tree depth is 1, the algorithms defects for all input. """ expected_output = [1, 1, 1, 1] for inp, out in zip(self.input_pos, expected_output): begin_node = dbs.DeterministicNode(inp[0], inp[1], depth=0) values = dbs.minimax_tree_search(begin_node, self.titForTat_policy, max_depth=1) self.assertEqual(values.index(max(values)), out)
def test_minimaxTreeSearch_titForTat(self): """ Tests the minimax_tree_search function when playing against a TitForTat player. The best (hence expected) answer to TitFOrTat is to cooperate whatever the input position is. """ expected_output = [0, 0, 0, 0] for inp, out in zip(self.input_pos, expected_output): begin_node = dbs.DeterministicNode(inp[0], inp[1], depth=0) values = dbs.minimax_tree_search(begin_node, self.titForTat_policy, max_depth=5) self.assertEqual(values.index(max(values)), out)
def test_minimaxTreeSearch_grudger(self): """ Tests the minimax_tree_search function when playing against a Grudger player. The best answer to Grudger is to cooperate if both cooperated at last round, else it's to defect. """ expected_output = [0, 1, 1, 1] for inp, out in zip(self.input_pos, expected_output): begin_node = dbs.DeterministicNode(inp[0], inp[1], depth=0) values = dbs.minimax_tree_search(begin_node, self.grudger_policy, max_depth=5) self.assertEqual(values.index(max(values)), out)
def test_minimaxTreeSearch_cooperator(self): """ Tests the minimax_tree_search function when playing against a Cooperator player. Output == 0 means Cooperate, 1 means Defect. The best (hence expected) answer to Cooperator is to defect whatever the input position is. """ expected_output = [1, 1, 1, 1] for inp, out in zip(self.input_pos, expected_output): begin_node = dbs.DeterministicNode(inp[0], inp[1], depth=0) values = dbs.minimax_tree_search(begin_node, self.cooperator_policy, max_depth=5) self.assertEqual(values.index(max(values)), out)