def TEST_MINIMAX():
    from basicplayer import minimax
    tup_tree = ("A", None,
                ("B", None,
                 ("C", None,
                  ("D", 2),
                  ("E", 2)),
                 ("F", None,
                  ("G", 0),
                  ("H", 4))
                 ),
                ("I", None,
                 ("J", None,
                  ("K", 6),
                  ("L", 8)),
                 ("M", None,
                  ("N", 4),
                  ("O", 6))
                 )
                )
    tree = make_tree(tup_tree)
    print "%s:\n%s" % ("TREE_1", tree_as_string(tree))
    v = minimax(tree, 10,
                tree_eval_minimax,
                tree_get_next_move,
                is_leaf)
    print "NEXT STEP: %s" % (v)
def TEST_4(expected):
    from basicplayer import minimax
    tup_tree = ("A", None,
        ("B", None,
         ("C", None,
          ("D", 2),
          ("E", 2)),
         ("F", None,
          ("G", 0),
          ("H", 4))
         ),
        ("I", None,
         ("J", None,
          ("K", 6),
          ("L", 8)),
         ("M", None,
          ("N", 4),
          ("O", 6))
         )
        )
    tree = make_tree(tup_tree)
    print "%s:\n%s" %("TREE_1", tree_as_string(tree))
    v,x = minimax(tree, 10,
              tree_eval,
              tree_get_next_move,
              is_leaf)
    print "BEST MOVE: %s" %(v)
    print "EXPECTED: %s" %(expected)
Exemple #3
0
def TEST_MINIMAX():
    from basicplayer import minimax
    tup_tree = ("A", None, ("B", None, ("C", None, ("D", 2), ("E", 2)),
                            ("F", None, ("G", 0), ("H", 4))),
                ("I", None, ("J", None, ("K", 6), ("L", 8)),
                 ("M", None, ("N", 4), ("O", 6))))
    tree = make_tree(tup_tree)
    print "%s:\n%s" % ("TREE_1", tree_as_string(tree))
    v = minimax(tree, 10, tree_eval_minimax, tree_get_next_move, is_leaf)
    print "NEXT STEP: %s" % (v)
Exemple #4
0
def TEST_4(expected):
    from basicplayer import minimax
    tup_tree = ("A", None, ("B", None, ("C", None, ("D", 2), ("E", 2)),
                            ("F", None, ("G", 0), ("H", 4))),
                ("I", None, ("J", None, ("K", 6), ("L", 8)),
                 ("M", None, ("N", 4), ("O", 6))))
    tree = make_tree(tup_tree)
    print "%s:\n%s" % ("TREE_1", tree_as_string(tree))
    v, x = minimax(tree, 10, tree_eval, tree_get_next_move, is_leaf)
    print "BEST MOVE: %s" % (v)
    print "EXPECTED: %s" % (expected)
def TEST_3(expected):
    from basicplayer import minimax
    tup_tree = ("A", None,
		("B", None,
		 ("E", None,
		  ("K", 8),
		  ("L", 2)),
		 ("F", 6)
		 ),
		("C", None,
		 ("G", None,
		  ("M", None,
		   ("S", 4),
		   ("T", 5)),
		  ("N", 3)),
		 ("H", None,
		  ("O", 9),
		  ("P", None,
		   ("U", 10),
		   ("V", 8))
		  ),
		 ),
		("D", None,
		 ("I", 1),
		 ("J", None,
		  ("Q", None,
		   ("W", 7),
		   ("X", 12)),
		  ("K", None,
		   ("Y", 11),
		   ("Z", 15)
		   ),
		  )
		 )
		)
    tree = make_tree(tup_tree)
    print "%s:\n%s" %("TREE_3",
		      tree_as_string(tree))
    v,x = minimax(tree, 10,
			  tree_eval,
			  tree_get_next_move,
			  is_leaf)
    print "BEST-MOVE: %s" %(v)
    print "EXPECTED: %s" %(expected)
Exemple #6
0
def TEST_3(expected):
    from basicplayer import minimax
    tup_tree = ("A", None,
                ("B", None, ("E", None, ("K", 8), ("L", 2)), ("F", 6)), (
                    "C",
                    None,
                    ("G", None, ("M", None, ("S", 4), ("T", 5)), ("N", 3)),
                    ("H", None, ("O", 9), ("P", None, ("U", 10), ("V", 8))),
                ), ("D", None, ("I", 1), (
                    "J",
                    None,
                    ("Q", None, ("W", 7), ("X", 12)),
                    ("K", None, ("Y", 11), ("Z", 15)),
                )))
    tree = make_tree(tup_tree)
    print "%s:\n%s" % ("TREE_3", tree_as_string(tree))
    v, x = minimax(tree, 10, tree_eval, tree_get_next_move, is_leaf)
    print "BEST-MOVE: %s" % (v)
    print "EXPECTED: %s" % (expected)
Exemple #7
0
    else:
        score = board.longest_chain(board.get_current_player_id()) * 10
        # Prefer having your pieces in the center of the board.
        for row in range(6):
            for col in range(7):
                if board.get_cell(row, col) == board.get_current_player_id():
                    score -= abs(3 - col)
                elif board.get_cell(row, col) == board.get_other_player_id():
                    score += abs(3 - col)

    return score


# Create a "player" function that uses the focused_evaluate function
# You can test this player by choosing 'quick' in the main program.
quick_to_win_player = lambda board: minimax(
    board, depth=4, eval_fn=focused_evaluate)

# TODO Write an alpha-beta-search procedure that acts like the minimax-search
# procedure, but uses alpha-beta pruning to avoid searching bad ideas
# that can't improve the result. The tester will check your pruning by
# counting the number of static evaluations you make.


# You can use minimax() in basicplayer.py as an example.
# NOTE: You should use get_next_moves_fn when generating
# next board configurations, and is_terminal_fn when
# checking game termination.
# The default functions for get_next_moves_fn and is_terminal_fn set here will work for connect_four.
def alphabeta_find_board_value(alpha,
                               beta,
                               maxTurn,
Exemple #8
0
 def test_search_2(self):
     actual_score = minimax(self.BARELY_WINNING_BOARD, 2, focused_evaluate)
     expected_score = 3
     self.assertEqual(actual_score, expected_score)