def test_minmax_alpha_beta_breaking_min_max_block(): alpha_beta = Game() min_max = Game() alpha_beta.current_color = "2" min_max.current_color = "2" alpha_beta.do_alpha_beta_pruning = True min_max.do_alpha_beta_pruning = False alpha_beta.set_heuristic_score = check_potential_win min_max.set_heuristic_score = check_potential_win alpha_beta.board.board = [ ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '2'], ['1', '?', '1', '1', '?', '2', '2']] min_max.board.board = [ ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '2'], ['1', '?', '1', '1', '?', '2', '2']] _score_1, column_1 = alpha_beta.min_max(alpha_beta.board,"2", 5, -math.inf, math.inf) _score_2, column_2 = min_max.min_max(min_max.board,"2", 5, -math.inf, math.inf) assert column_1 == column_2 assert column_1 == 1 assert column_2 == 1
def test_heuristic_2_w(): game = Game() board = Board() game.set_heuristic_score = check_potential_win_two_weighted board.board = [['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '2', '?', '?'], ['?', '?', '2', '?', '2', '2', '?'], ['?', '2', '2', '?', '2', '2', '2']] assert game.heuristic_score(board) == -29
def test_heuristic_3_complex(): game = Game() board = Board() game.set_heuristic_score = check_potential_win board.board = [['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '1', '?', '1', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '1', '?', '1', '1', '?'], ['?', '1', '1', '?', '1', '?', '?']] assert game.heuristic_score(board) == 5
def test_heuristic_is_diagonal_getting_double_counted_2(): game = Game() board = Board() game.set_heuristic_score = check_potential_win board.board = [['?', '?', '?', '?', '?', '?', '1'], ['?', '?', '?', '?', '?', '1', '?'], ['?', '?', '?', '?', '1', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?', '?']] assert game.heuristic_score(board) == 1
def test_minmax_diminishing_future_returns(): new_game = Game() new_game.board.last_placed_column = 2 new_game.board.last_placed_row = 1 new_game.board.last_placed_player = "1" new_game.current_color = "2" new_game.set_heuristic_score = check_potential_win new_game.board.board = [ ['?', '?', '?', '?', '?', '?', '?'], ['2', '?', '1', '?', '?', '?', '?'], ['1', '?', '1', '?', '?', '2', '?'], ['2', '?', '2', '1', '?', '1', '?'], ['2', '?', '1', '2', '?', '1', '?'], ['2', '?', '2', '1', '1', '1', '2']] _score, column = new_game.min_max(new_game.board,"2", 5, -math.inf, math.inf) assert column == 4