def test_newsmallgame(self): result = lab.new_game_2d(10, 8, [(7, 3), (2, 6), (8, 7), (4, 4), (3, 5), (4, 6), (6, 2), (9, 4), (4, 2), (4, 0), (8, 6), (9, 7), (8, 5), (5, 0), (7, 2), (5, 3)]) expected = {"board": [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 1, 2, ".", 1], [1, 2, 1, 2, 2, ".", 3, 2], [".", 3, ".", 3, ".", 3, ".", 1], [".", 4, 3, ".", 2, 2, 1, 1], [1, 3, ".", 4, 2, 0, 0, 0], [0, 2, ".", ".", 2, 2, 3, 2], [0, 1, 2, 3, 3, ".", ".", "."], [0, 0, 0, 1, ".", 3, 4, "."]], "dimensions": (10, 8), "mask": [[False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False]], "state": "ongoing"} for name in expected: self.assertEqual(result[name], expected[name])
def test_newmediumgame(self): result = lab.new_game_2d(30, 16, [(16, 6), (17, 7), (14, 4), (13, 4), (0, 7), (21, 6), (2, 5), (5, 5), (6, 10), (12, 6), (24, 14), (14, 1), (24, 1), (26, 12), (8, 15), (9, 3), (16, 0), (19, 13), (15, 14), (13, 10), (18, 10), (21, 15), (28, 15), (29, 14), (11, 15), (14, 8), (17, 8), (24, 8), (25, 5), (2, 1), (10, 3), (27, 2), (17, 6), (7, 15), (15, 0), (21, 8), (20, 0), (1, 10), (10, 4), (14, 6), (1, 0), (4, 11), (27, 0), (9, 13), (23, 5), (14, 12), (20, 15), (3, 15), (26, 14), (4, 8), (10, 15), (7, 11), (18, 1), (25, 4), (26, 3), (22, 14), (28, 2), (13, 2), (19, 6), (1, 4), (21, 4), (1, 9), (8, 7), (23, 1), (22, 11), (19, 5), (18, 7), (0, 6), (26, 4), (3, 4), (5, 9), (24, 13), (20, 8), (19, 0), (0, 3), (21, 13), (3, 3), (28, 9), (11, 1), (12, 10), (24, 10), (18, 13), (0, 0), (21, 0), (3, 13), (27, 13), (5, 15), (26, 9), (17, 4), (7, 9), (19, 9), (24, 7), (22, 5), (3, 8), (27, 8), (9, 5), (23, 13), (5, 2), (10, 2)]) with open('test_outputs/test2d_newmediumgame.pickle', 'rb') as f: expected = pickle.load(f) for name in expected: self.assertEqual(result[name], expected[name])
def test_newmediumgame(): result = lab.new_game_2d(30, 16, [(16, 6), (17, 7), (14, 4), (13, 4), (0, 7), (21, 6), (2, 5), (5, 5), (6, 10), (12, 6), (24, 14), (14, 1), (24, 1), (26, 12), (8, 15), (9, 3), (16, 0), (19, 13), (15, 14), (13, 10), (18, 10), (21, 15), (28, 15), (29, 14), (11, 15), (14, 8), (17, 8), (24, 8), (25, 5), (2, 1), (10, 3), (27, 2), (17, 6), (7, 15), (15, 0), (21, 8), (20, 0), (1, 10), (10, 4), (14, 6), (1, 0), (4, 11), (27, 0), (9, 13), (23, 5), (14, 12), (20, 15), (3, 15), (26, 14), (4, 8), (10, 15), (7, 11), (18, 1), (25, 4), (26, 3), (22, 14), (28, 2), (13, 2), (19, 6), (1, 4), (21, 4), (1, 9), (8, 7), (23, 1), (22, 11), (19, 5), (18, 7), (0, 6), (26, 4), (3, 4), (5, 9), (24, 13), (20, 8), (19, 0), (0, 3), (21, 13), (3, 3), (28, 9), (11, 1), (12, 10), (24, 10), (18, 13), (0, 0), (21, 0), (3, 13), (27, 13), (5, 15), (26, 9), (17, 4), (7, 9), (19, 9), (24, 7), (22, 5), (3, 8), (27, 8), (9, 5), (23, 13), (5, 2), (10, 2)]) exp_fname = os.path.join(TEST_DIRECTORY, 'test_outputs', 'test2d_newmediumgame.pickle') with open(exp_fname, 'rb') as f: expected = pickle.load(f) for name in expected: assert result[name] == expected[name]
def _do_test_2d_integration(test): """ dig, render, and render_2d_board on boards """ exp_fname = os.path.join(TEST_DIRECTORY, 'test_outputs', f'test2d_integration_{test:02d}.pickle') inp_fname = os.path.join(TEST_DIRECTORY, 'test_inputs', f'test2d_integration_{test:02d}.pickle') with open(inp_fname, 'rb') as f: inputs = pickle.load(f) with open(exp_fname, 'rb') as f: expected = pickle.load(f) game = lab.new_game_2d(*inputs[0]) for location, exp in zip(inputs[1], expected): num, g, render, renderx, ascii_, ascii_x = exp assert lab.dig_2d(game, *location) == num for key in g: assert game[key] == g[key] assert lab.render_2d_locations(game) == render assert lab.render_2d_locations(game, xray=True) == renderx assert lab.render_2d_board(game) == ascii_ assert lab.render_2d_board(game, xray=True) == ascii_x last_state = game['state'] if last_state in {'victory', 'defeat'}: for r in range(game['dimensions'][0]): for c in range(game['dimensions'][1]): assert lab.dig_2d(game, *location) == 0 assert game['state'] == last_state else: for r in range(game['dimensions'][0]): for c in range(game['dimensions'][1]): if game['mask'][r][c]: assert lab.dig_2d(game, *location) == 0 assert game['state'] == 'ongoing'''
def test_newlargegame(self): with open('test_outputs/test2d_newlargegame.pickle', 'rb') as f: expected = pickle.load(f) with open('test_inputs/test2d_newlargegame.pickle', 'rb') as f: inputs = pickle.load(f) result = lab.new_game_2d(inputs['num_rows'], inputs['num_cols'], inputs['bombs']) for name in expected: self.assertEqual(result[name], expected[name])
def test_newlargegame(): exp_fname = os.path.join(TEST_DIRECTORY, 'test_outputs', 'test2d_newlargegame.pickle') inp_fname = os.path.join(TEST_DIRECTORY, 'test_inputs', 'test2d_newlargegame.pickle') with open(exp_fname, 'rb') as f: expected = pickle.load(f) with open(inp_fname, 'rb') as f: inputs = pickle.load(f) result = lab.new_game_2d(inputs['num_rows'], inputs['num_cols'], inputs['bombs']) for name in expected: assert result[name] == expected[name]
def handle_new_game_2d(params): global current_game_2d current_game_2d = lab.new_game_2d(params['num_rows'], params['num_cols'], [tuple(i) for i in params['bombs']])
def ui_new_game_2d(d): return lab.new_game_2d(d['num_rows'], d['num_cols'], [tuple(i) for i in d['bombs']])