def test_different_situation(self): game = Game(10, 10) self.assertEqual(game.turn, Cell.RED) game.make_step(2, 3) game.make_step(1, 4) game.change_turn_player() self.assertEqual(game.turn, Cell.BLUE) game.make_step(1, 3) game.make_step(2, 2) game.change_turn_player() self.assertEqual(game.turn, Cell.RED) game.make_step(0, 3) game.make_step(1, 2) self.assertEqual(game.lines, [(([(1, 2), (0, 3), (1, 4), (2, 3), (1, 2)], Cell.RED, [((1, 3), Cell.BLUE)], 2.0))]) game.make_step(3, 2) game.make_step(4, 3) game.make_step(2, 1) self.assertEqual(game.lines, [(([(1, 2), (0, 3), (1, 4), (2, 3), (1, 2)], Cell.RED, [((1, 3), Cell.BLUE)], 2.0)), (([(2, 1), (1, 2), (2, 3), (3, 2), (2, 1)], Cell.RED, [((2, 2), Cell.BLUE)], 2.0))]) game.change_turn_player() self.assertEqual(game.turn, Cell.BLUE) game.make_step(9, 9) game.make_step(9, 8) game.change_turn_player() self.assertEqual(game.turn, Cell.RED) game.make_step(8, 9) game.make_step(8, 8) game.make_step(7, 8) game.change_turn_player() self.assertEqual(game.turn, Cell.BLUE) game.make_step(7, 7) game.make_step(8, 7) game.make_step(7, 9) game.make_step(6, 8) game.make_step(8, 0) self.assertEqual(game.lines, [(([(1, 2), (0, 3), (1, 4), (2, 3), (1, 2)], Cell.RED, [((1, 3), Cell.BLUE)], 2.0)), (([(2, 1), (1, 2), (2, 3), (3, 2), (2, 1)], Cell.RED, [((2, 2), Cell.BLUE)], 2.0)), (([(8, 0), (7, 9), (6, 8), (7, 7), (8, 7), (9, 8), (9, 9), (8, 0)], Cell.BLUE, [((7, 8), Cell.RED), ((8, 8), Cell.RED), ((8, 9), Cell.RED)], 5.5))]) self.assertEqual(game.score_red, 4.0) self.assertEqual(game.score_blue, 5.5) self.assertEqual(game.get_winner(), Cell.BLUE)
def test_undo_redo(self): game = Game(2, 3) game.make_step(0, 0) game.change_turn_player() game.make_step(1, 1) game.change_turn_player() game.make_step(0, 1) game.change_turn_player() game.make_step(1, 0) game.change_turn_player() game.make_step(0, 2) game.change_turn_player() game.make_step(1, 2) enemy = Rival.AInormal for _i in range(4): with contextlib.suppress(IndexError): game.undo(enemy) try: game.undo(enemy) except IndexError: game.redo(enemy) for i in range(game.width): for j in range(game.height): if i != 0 or j != 0: self.assertEqual(game.field[i][j], Cell.EMPTY) for _i in range(4): with contextlib.suppress(IndexError): game.redo(enemy) game.redo(enemy) for i in range(game.width): for j in range(game.height): if (i, j) in [(0, 0), (0, 1), (0, 2)]: self.assertEqual(game.field[i][j], Cell.RED) elif (i, j) in [(1, 1), (1, 0), (1, 2)]: self.assertEqual(game.field[i][j], Cell.BLUE) else: self.assertEqual(game.field[i][j], Cell.EMPTY)
def test_change_turn(self): game = Game(3, 3) start_turn = game.turn game.change_turn_player() self.assertFalse(start_turn == game.turn)