Exemplo n.º 1
0
 def test_newmediumgame(self):
     """ Testing new_game on a medium board """
     result = lab.MinesGame(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/test_newmediumgame.json") as f:
         expected = json.load(f)
     for name in expected:
         self.assertEqual(getattr(result, name), expected[name])
Exemplo n.º 2
0
 def test_newsmallgame(self):
     """ Testing new_game on a small board """
     result = lab.MinesGame(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(getattr(result, name), expected[name])
Exemplo n.º 3
0
 def test_newlargegame(self):
     """ Testing new_game on a medium board """
     with open("test_outputs/test_newlargegame.json") as f:
         expected = json.load(f)
     with open("test_inputs/test_newlargegame.json") as f:
         inputs = json.load(f)
     result = lab.MinesGame(inputs["num_rows"], inputs["num_cols"],
                            inputs["bombs"])
     for name in expected:
         self.assertEqual(getattr(result, name), expected[name])
Exemplo n.º 4
0
def game_from_dict(d):
    """
    Create an instance of `lab.MinesGame` from a dictionary representation of
    the game.
    """
    r, c = d['dimensions']
    bombs = []
    for i in range(r):
        for j in range(c):
            if d['board'][i][j] == '.':
                bombs.append((i, j))
    game = lab.MinesGame(r, c, bombs)
    for i in ('board', 'state', 'mask'):
        setattr(game, i, d[i])
    return game
Exemplo n.º 5
0
 def test_init_board(self):
     g = lab.MinesGame(5, 5, [(0, 3), (2, 0), (3, 0), (3, 3)])
     results = g.board
     expected = [[0, 0, 1, '.', 1], [1, 1, 1, 1, 1], ['.', 2, 1, 1, 1],
                 ['.', 2, 1, '.', 1], [1, 1, 1, 1, 1]]
     self.assertEqual(results, expected)