def test_load_game(self): expected_board = [['R', '0', 'G', '0', 'Y'], ['0', '0', 'B', '0', 'O'], ['0', '0', '0', '0', '0'], ['0', 'G', '0', 'Y', '0'], ['0', 'R', 'B', 'O', '0']] loaded_game = utilities.load_game(TEST_PATH + "easy5x5.txt") self.assertTrue( utilities.equal_boards(loaded_game.get_board_copy(), expected_board))
def test_load_game(self): expected_board = [['R', '0', 'G', '0', 'Y'], ['0', '0', 'B', '0', 'O'], ['0', '0', '0', '0', '0'], ['0', 'G', '0', 'Y', '0'], ['0', 'R', 'B', 'O', '0']] loaded_game = utilities.load_game(TEST_PATH + "easy5x5.txt") self.assertTrue(utilities.equal_boards(loaded_game.get_board_copy(), expected_board))
def solve_file(self, filename, method="RR"): start = utils.load_game(filename) if method.lower() == "RR": return self.solve_rr(start) else: return self.solve_single_gp(start)
def test_is_empty(self): flow_instance = utils.load_game(TEST_PATH + "easy5x5.txt") self.assertFalse(flow_instance.is_empty(0, 0)) self.assertTrue(flow_instance.is_empty(0, 1))
def test_is_valid(self): flow_instance = utils.load_game(TEST_PATH + "easy5x5.txt") self.assertFalse(flow_instance.is_valid(-1, 0), "Negative row value test") self.assertFalse(flow_instance.is_valid(0, 5), "5x5 grid only has values up to index 4. (0,5) is invalid") self.assertTrue(flow_instance.is_valid(4, 4), "(4, 4) last valid position in 5x5 Grid")
import flow_game.utilities as utils import time def time_run(method, board, number_of_runs): total_time = 0 for x in range(0, number_of_runs): startTime = time.time() method(board) total_time += (time.time() - startTime) return str(total_time / number_of_runs) if __name__ == '__main__': PATH_TO_TEST_FILES = "../TestBoards/" simpleFlow = utils.load_game(PATH_TO_TEST_FILES + "simpleBoard.txt") mediumFlow = utils.load_game(PATH_TO_TEST_FILES + "mediumBoard.txt") firstFlow = utils.load_game(PATH_TO_TEST_FILES + "easy5x5.txt") hardFlow = utils.load_game(PATH_TO_TEST_FILES + "7x7board.txt") hardestFlow = utils.load_game(PATH_TO_TEST_FILES + "9x9board.txt") bfsAI = bfs.BFS() astarAI = astar.AStarNick() backtrackingAI = back_tracking.BackTrackSolver() print "3x3 2 colors" print "bfs:", time_run(bfsAI.solve_single_gp, simpleFlow, 100) print "astar:", time_run(astarAI.solve, simpleFlow, 100) print "backtracking:", time_run(backtrackingAI.solve, simpleFlow, 100) print