Ejemplo n.º 1
0
    def test_consistent_parse(self):
        boards = [
            "NNNNOOOOXXXXNNNNOOOOXXXX", "NOXNXOXNOXNOXOXOXNOXONON",
            "OOONXNOXNONXONOXNXNNONOX", "NNNNNNNNNNNNNNNNNNNNNNNN",
            "OOOOOOOOOOOOOOOOOOOOOOOO", "XXXXXXXXXXXXXXXXXXXXXXXX"
        ]

        for board in boards:
            self.assertEqual(
                board,
                interface.construct_board(
                    interface.construct_grid(
                        interface.construct_board(
                            interface.construct_grid(board)))))
Ejemplo n.º 2
0
    def test_can_make_any_move(self):
        grid = interface.construct_grid("NONNNNNNNNNNNNNNNNNNNNXN")

        self.assertEqual(mechanics.check_moves("O", grid), True)
        self.assertEqual(mechanics.check_moves("X", grid), True)

        grid = interface.construct_grid("XXXXXXOXXXXXXXXXXXXXXXNX")

        self.assertEqual(mechanics.check_moves("O", grid), False)
        self.assertEqual(mechanics.check_moves("X", grid), True)

        grid = interface.construct_grid("NXNNNNNNNNNNNNNNNNNNNNNN")

        self.assertEqual(mechanics.check_moves("O", grid), False)
        self.assertEqual(mechanics.check_moves("X", grid), True)
Ejemplo n.º 3
0
    def test_can_make_any_move(self):
        grid = interface.construct_grid("NONNNNNNNNNNNNNNNNNNNNXN")

        self.assertEqual(mechanics.check_moves("O", grid), True)
        self.assertEqual(mechanics.check_moves("X", grid), True)

        grid = interface.construct_grid("XXXXXXOXXXXXXXXXXXXXXXNX")

        self.assertEqual(mechanics.check_moves("O", grid), False)
        self.assertEqual(mechanics.check_moves("X", grid), True)

        grid = interface.construct_grid("NXNNNNNNNNNNNNNNNNNNNNNN")

        self.assertEqual(mechanics.check_moves("O", grid), False)
        self.assertEqual(mechanics.check_moves("X", grid), True)
Ejemplo n.º 4
0
    def test_consistent_parse(self):
        boards = ["NNNNOOOOXXXXNNNNOOOOXXXX",
                  "NOXNXOXNOXNOXOXOXNOXONON",
                  "OOONXNOXNONXONOXNXNNONOX",
                  "NNNNNNNNNNNNNNNNNNNNNNNN",
                  "OOOOOOOOOOOOOOOOOOOOOOOO",
                  "XXXXXXXXXXXXXXXXXXXXXXXX"]

        for board in boards:
            self.assertEqual(board, interface.construct_board(
                interface.construct_grid(
                    interface.construct_board(
                        interface.construct_grid(board)
                    )
                )
            )
            )
Ejemplo n.º 5
0
    def test_no_diagonal_hills(self):
        grid = interface.construct_grid("XXXNNXOONXXXXNNOOOXXXNNN")

        hills_uid = "0356"

        mechanics.move_man_legal(3, 4, 2, 4, grid)

        updated_hills_uid = mechanics.get_hills_numbers(grid)

        self.assertEqual(updated_hills_uid, hills_uid)
Ejemplo n.º 6
0
    def test_no_diagonal_hills(self):
        grid = interface.construct_grid("XXXNNXOONXXXXNNOOOXXXNNN")

        hills_uid = "0356"

        mechanics.move_man_legal(3, 4, 2, 4, grid)

        updated_hills_uid = mechanics.get_hills_numbers(grid)

        self.assertEqual(updated_hills_uid, hills_uid)
Ejemplo n.º 7
0
    def test_unchanged_hills(self):
        grid = interface.construct_grid("XXXNNNOOOXXXXNNOOOXXXNNN")

        hills_uid = "02356"

        mechanics.move_man_legal(3, 4, 3, 5, grid)

        updated_hills_uid = mechanics.get_hills_numbers(grid)

        self.assertEqual(updated_hills_uid, hills_uid)
Ejemplo n.º 8
0
    def test_unchanged_hills(self):
        grid = interface.construct_grid("XXXNNNOOOXXXXNNOOOXXXNNN")

        hills_uid = "02356"

        mechanics.move_man_legal(3, 4, 3, 5, grid)

        updated_hills_uid = mechanics.get_hills_numbers(grid)

        self.assertEqual(updated_hills_uid, hills_uid)
Ejemplo n.º 9
0
    def test_not_populated_move(self):
        grid = interface.construct_grid("XXXNNNOOOXXXNNNOOOXXXNNN")

        moves = [[0, 0, 1, 1], [0, 3, 1, 3], [5, 1, 5, 3], [0, 0, 0, 3],
                 [0, 0, 3, 0]]

        expected_outcomes = [True, True, False, False, False]

        test_outcomes = [mechanics.is_empty(move[2], move[3], grid) for move in
                         moves]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 10
0
    def test_not_populated_move(self):
        grid = interface.construct_grid("XXXNNNOOOXXXNNNOOOXXXNNN")

        moves = [[0, 0, 1, 1], [0, 3, 1, 3], [5, 1, 5, 3], [0, 0, 0, 3],
                 [0, 0, 3, 0]]

        expected_outcomes = [True, True, False, False, False]

        test_outcomes = [mechanics.is_empty(move[2], move[3], grid) for move in
                         moves]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 11
0
    def test_own_piece(self):
        grid = interface.construct_grid("XXXNNNOOOXXXNNNOOOXXXNNN")

        presets = [[0, 0, "X"], [0, 0, "O"], [0, 6, "X"], [0, 6, "O"],
                   [1, 1, "X"], [1, 1, "O"]]

        expected_outcomes = [True, False, True, False, False, False]

        test_outcomes = [
            mechanics.is_own_piece(preset[0], preset[1], preset[2], grid) for
            preset in presets]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 12
0
    def test_own_piece(self):
        grid = interface.construct_grid("XXXNNNOOOXXXNNNOOOXXXNNN")

        presets = [[0, 0, "X"], [0, 0, "O"], [0, 6, "X"], [0, 6, "O"],
                   [1, 1, "X"], [1, 1, "O"]]

        expected_outcomes = [True, False, True, False, False, False]

        test_outcomes = [
            mechanics.is_own_piece(preset[0], preset[1], preset[2], grid) for
            preset in presets]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 13
0
    def test_legal_put(self):
        grid = interface.construct_grid("XXXNNNOOOXXXNNNOOOXXXNNN")

        presets = [[0, 0, 1], [0, 3, 2], [0, 6, 3], [1, 1, 2], [1, 3, 1],
                   [1, 6, 1], [1, 5, 1]]

        expected_outcomes = [False, False, False, False, True, False, True]

        test_outcomes = [
            mechanics.is_legal_put(preset[0], preset[1], grid, preset[2]) for
            preset in presets]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 14
0
    def test_legal_put(self):
        grid = interface.construct_grid("XXXNNNOOOXXXNNNOOOXXXNNN")

        presets = [[0, 0, 1], [0, 3, 2], [0, 6, 3], [1, 1, 2], [1, 3, 1],
                   [1, 6, 1], [1, 5, 1]]

        expected_outcomes = [False, False, False, False, True, False, True]

        test_outcomes = [
            mechanics.is_legal_put(preset[0], preset[1], grid, preset[2]) for
            preset in presets]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 15
0
    def test_legal_move(self):
        grid = interface.construct_grid("XXXNNNOOONNNNNNOOONNNNNN")

        presets = [[0, 0, 0, 3, "X", 1], [0, 0, 0, 6, "X", 2],
                   [0, 0, 3, 6, "X", 3], [0, 0, 2, 2, "X", 3]]

        expected_outcomes = [False, False, True, False]

        test_outcomes = [
            mechanics.is_legal_move(preset[0], preset[1], preset[2], preset[3],
                                    preset[4], preset[5], grid)
            for preset in presets]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 16
0
    def test_legal_move(self):
        grid = interface.construct_grid("XXXNNNOOONNNNNNOOONNNNNN")

        presets = [[0, 0, 0, 3, "X", 1], [0, 0, 0, 6, "X", 2],
                   [0, 0, 3, 6, "X", 3], [0, 0, 2, 2, "X", 3]]

        expected_outcomes = [False, False, True, False]

        test_outcomes = [
            mechanics.is_legal_move(preset[0], preset[1], preset[2], preset[3],
                                    preset[4], preset[5], grid)
            for preset in presets]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 17
0
 def test_empty_layout_arrangement(self):
     grid = interface.construct_grid("NNNNNNNNNNNNNNNNNNNNNNNN")
     self.assertEqual(interface.graph_grid(grid), '''`      0     1     2     3     4     5     6
 0 [ ]---------------[ ]---------------[ ]
    |                 |                 |
 1  |    [ ]---------[ ]---------[ ]    |
    |     |           |           |     |
 2  |     |    [ ]---[ ]---[ ]    |     |
    |     |     |           |     |     |
 3 [ ]---[ ]---[ ]         [ ]---[ ]---[ ]
    |     |     |           |     |     |
 4  |     |    [ ]---[ ]---[ ]    |     |
    |     |           |           |     |
 5  |    [ ]---------[ ]---------[ ]    |
    |                 |                 |
 6 [ ]---------------[ ]---------------[ ]`''')
Ejemplo n.º 18
0
    def test_legal_take(self):
        grid = interface.construct_grid("XXXNNNOOOXXXNNNOOOXXXNNN")

        presets = [[0, 0, "X", 1], [0, 1, "X", 1], [0, 0, "O", 1],
                   [0, 0, "O", 0], [0, 1, "O", 1], [2, 2, "X", 1],
                   [2, 3, "X", 1], [2, 4, "O", 1]]

        expected_outcomes = [False, False, True, False, False, True, True,
                             False]

        test_outcomes = [
            mechanics.is_legal_take(preset[0], preset[1], preset[2], grid,
                                    preset[3]) for preset in
            presets]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 19
0
 def test_illegal_character_arrangement(self):
     grid = interface.construct_grid("ABCDABCDABCDABCDABCDXXOO")
     self.assertEqual(interface.graph_grid(grid), '''`      0     1     2     3     4     5     6
 0 [ ]---------------[ ]---------------[ ]
    |                 |                 |
 1  |    [ ]---------[ ]---------[ ]    |
    |     |           |           |     |
 2  |     |    [ ]---[ ]---[ ]    |     |
    |     |     |           |     |     |
 3 [ ]---[ ]---[ ]         [ ]---[ ]---[ ]
    |     |     |           |     |     |
 4  |     |    [ ]---[ ]---[ ]    |     |
    |     |           |           |     |
 5  |    [ ]---------[ ]---------[X]    |
    |                 |                 |
 6 [X]---------------[O]---------------[O]`''')
Ejemplo n.º 20
0
 def test_full_layout_arragement(self):
     grid = interface.construct_grid("NXONXONXONXONXONXONXONXO")
     self.assertEqual(interface.graph_grid(grid), '''`      0     1     2     3     4     5     6
 0 [ ]---------------[X]---------------[O]
    |                 |                 |
 1  |    [ ]---------[X]---------[O]    |
    |     |           |           |     |
 2  |     |    [ ]---[X]---[O]    |     |
    |     |     |           |     |     |
 3 [ ]---[X]---[O]         [ ]---[X]---[O]
    |     |     |           |     |     |
 4  |     |    [ ]---[X]---[O]    |     |
    |     |           |           |     |
 5  |    [ ]---------[X]---------[O]    |
    |                 |                 |
 6 [ ]---------------[X]---------------[O]`''')
Ejemplo n.º 21
0
    def test_legal_take(self):
        grid = interface.construct_grid("XXXNNNOOOXXXNNNOOOXXXNNN")

        presets = [[0, 0, "X", 1], [0, 1, "X", 1], [0, 0, "O", 1],
                   [0, 0, "O", 0], [0, 1, "O", 1], [2, 2, "X", 1],
                   [2, 3, "X", 1], [2, 4, "O", 1]]

        expected_outcomes = [False, False, True, False, False, True, True,
                             False]

        test_outcomes = [
            mechanics.is_legal_take(preset[0], preset[1], preset[2], grid,
                                    preset[3]) for preset in
            presets]

        self.assertListEqual(test_outcomes, expected_outcomes)
Ejemplo n.º 22
0
 def test_full_layout_arragement(self):
     grid = interface.construct_grid("NXONXONXONXONXONXONXONXO")
     self.assertEqual(
         interface.graph_grid(grid),
         '''`      0     1     2     3     4     5     6
 0 [ ]---------------[X]---------------[O]
    |                 |                 |
 1  |    [ ]---------[X]---------[O]    |
    |     |           |           |     |
 2  |     |    [ ]---[X]---[O]    |     |
    |     |     |           |     |     |
 3 [ ]---[X]---[O]         [ ]---[X]---[O]
    |     |     |           |     |     |
 4  |     |    [ ]---[X]---[O]    |     |
    |     |           |           |     |
 5  |    [ ]---------[X]---------[O]    |
    |                 |                 |
 6 [ ]---------------[X]---------------[O]`''')
Ejemplo n.º 23
0
 def test_empty_layout_arrangement(self):
     grid = interface.construct_grid("NNNNNNNNNNNNNNNNNNNNNNNN")
     self.assertEqual(
         interface.graph_grid(grid),
         '''`      0     1     2     3     4     5     6
 0 [ ]---------------[ ]---------------[ ]
    |                 |                 |
 1  |    [ ]---------[ ]---------[ ]    |
    |     |           |           |     |
 2  |     |    [ ]---[ ]---[ ]    |     |
    |     |     |           |     |     |
 3 [ ]---[ ]---[ ]         [ ]---[ ]---[ ]
    |     |     |           |     |     |
 4  |     |    [ ]---[ ]---[ ]    |     |
    |     |           |           |     |
 5  |    [ ]---------[ ]---------[ ]    |
    |                 |                 |
 6 [ ]---------------[ ]---------------[ ]`''')
Ejemplo n.º 24
0
 def test_illegal_character_arrangement(self):
     grid = interface.construct_grid("ABCDABCDABCDABCDABCDXXOO")
     self.assertEqual(
         interface.graph_grid(grid),
         '''`      0     1     2     3     4     5     6
 0 [ ]---------------[ ]---------------[ ]
    |                 |                 |
 1  |    [ ]---------[ ]---------[ ]    |
    |     |           |           |     |
 2  |     |    [ ]---[ ]---[ ]    |     |
    |     |     |           |     |     |
 3 [ ]---[ ]---[ ]         [ ]---[ ]---[ ]
    |     |     |           |     |     |
 4  |     |    [ ]---[ ]---[ ]    |     |
    |     |           |           |     |
 5  |    [ ]---------[ ]---------[X]    |
    |                 |                 |
 6 [X]---------------[O]---------------[O]`''')