import unittest
import pygame
from checkers.game import Game
from checkers.board import Board
from checkers.piece import Piece
from checkers.constants import WIDTH, HEIGHT, BLACK


class Test(unittest.TestCase):

    def test_return_value(self):
        """
        Test that it can move two fields by every players
        """
        WIN = pygame.display.set_mode((WIDTH, HEIGHT))
        game = Game(WIN)
        game.select(5, 4)
        game._move(4, 3)
        game.select(2, 5)
        game._move(3, 4)
        game.select(4, 3)
        coordinates1 = game._move(3, 2)
        game.select(3, 4)
        coordinates2 = game._move(4, 3)
        self.assertEqual((coordinates1[1], coordinates2[1]), ((3, 2), (4, 3)))
        pygame.quit()

    def test_invalid_move(self):
        """
        Test that piece cant move
        """
        WIN = pygame.display.set_mode((WIDTH, HEIGHT))
        game = Game(WIN)
        game.select(5, 4)
        coordinates = game._move(6, 5)
        self.assertEqual(coordinates[1], ())
        pygame.quit()

    def test_beat_a_pawn(self):
        """
        Test if a pawn has been knocked down
        """
        WIN = pygame.display.set_mode((WIDTH, HEIGHT))
        game = Game(WIN)
        board = Board()
        game.select(5, 4)
        game._move(4, 5)
        game.select(2, 3)
        game._move(3, 4)
        game.select(4, 5)
        piece = game._move(2, 3)[2]
        self.assertIsInstance(piece, list)

    def test_beat_two_pawns(self):
        """
        Test if two pawns have been knocked down
        """
        WIN = pygame.display.set_mode((WIDTH, HEIGHT))
        game = Game(WIN)
        board = Board()
        game.select(5, 0)
        game._move(4, 1)
        game.select(2, 5)
        game._move(3, 4)
        game.select(4, 1)
        game._move(3, 0)
        game.select(3, 4)
        game._move(4, 3)
        game.select(5, 6)
        game._move(4, 7)
        game.select(1, 6)
        game._move(2, 5)
        game.select(5, 2)
        piece = game._move(1, 6)[2]
        self.assertIsInstance(piece, list)

    def test_make_a_king(self):
        """
        Test whether a lady will rise
        """
        WIN = pygame.display.set_mode((WIDTH, HEIGHT))
        game = Game(WIN)
        board = Board()
        game.select(5, 6)
        game._move(4, 7)
        game.select(2, 1)
        game._move(3, 2)
        game.select(5, 0)
        game._move(4, 1)
        game.select(3, 2)
        game._move(4, 3)
        game.select(4, 7)
        game._move(3, 6)
        game.select(1, 0)
        game._move(2, 1)
        game.select(6, 1)
        game._move(5, 0)
        game.select(2, 1)
        game._move(3, 0)
        game.select(6, 5)
        game._move(5, 6)
        game.select(0, 1)
        game._move(1, 0)
        game.select(5, 6)
        game._move(4, 5)
        game.select(1, 0)
        game._move(2, 1)
        game.select(5, 4)
        game._move(1, 0)
        game.select(2, 3)
        game._move(3, 2)
        game.select(1, 0)
        kings = game._move(0, 1)[3]
        self.assertEqual(kings, 1)

    def test_beat_a_lady(self):
        WIN = pygame.display.set_mode((WIDTH, HEIGHT))
        game = Game(WIN)
        board = Board()
        game.select(5, 6)
        game._move(4, 7)
        game.select(2, 1)
        game._move(3, 2)
        game.select(5, 0)
        game._move(4, 1)
        game.select(3, 2)
        game._move(4, 3)
        game.select(4, 7)
        game._move(3, 6)
        game.select(1, 0)
        game._move(2, 1)
        game.select(6, 1)
        game._move(5, 0)
        game.select(2, 1)
        game._move(3, 0)
        game.select(6, 5)
        game._move(5, 6)
        game.select(0, 1)
        game._move(1, 0)
        game.select(5, 6)
        game._move(4, 5)
        game.select(1, 0)
        game._move(2, 1)
        game.select(5, 4)
        game._move(1, 0)
        game.select(2, 3)
        game._move(3, 2)
        game.select(1, 0)
        game._move(0, 1)
        game.select(3, 2)
        game._move(4, 3)
        game.select(0, 1)
        piece = game._move(2, 3)[2]
        self.assertIsInstance(piece, list)

    def test_black_win(self):
        WIN = pygame.display.set_mode((WIDTH, HEIGHT))
        game = Game(WIN)
        board = Board()
        game.select(5, 0)
        game._move(4, 1)
        game.select(2, 1)
        game._move(3, 2)
        game.select(4, 1)
        game._move(3, 0)
        game.select(3, 2)
        game._move(4, 3)
        game.select(5, 4)
        game._move(3, 2)
        game.select(2, 3)
        game._move(4, 1)
        game.select(6, 1)
        game._move(5, 0)
        game.select(2, 5)
        game._move(3, 4)
        game.select(6, 3)
        game._move(5, 4)
        game.select(1, 4)
        game._move(2, 3)
        game.select(5, 0)
        game._move(1, 4)
        game.select(3, 4)
        game._move(4, 5)
        game.select(5, 2)
        game._move(4, 3)
        game.select(1, 2)
        game._move(2, 3)
        game.select(5, 6)
        game._move(1, 2)
        game.select(1, 6)
        game._move(2, 5)
        game.select(5, 4)
        game._move(4, 5)
        game.select(2, 5)
        game._move(3, 4)
        game.select(7, 0)
        game._move(6, 1)
        game.select(0, 7)
        game._move(1, 6)
        game.select(4, 3)
        game._move(2, 5)
        game.select(2, 7)
        game._move(3, 6)
        game.select(2, 5)
        game._move(0, 7)
        game.select(0, 5)
        game._move(1, 6)
        game.select(0, 7)
        game._move(4, 7)
        game.select(0, 1)
        game._move(2, 3)
        game.select(4, 5)
        game._move(3, 4)
        game.select(1, 0)
        game._move(2, 1)
        game.select(3, 4)
        game._move(1, 2)
        game.select(0, 3)
        game._move(2, 5)
        game.select(1, 2)
        game._move(0, 1)
        game.select(2, 5)
        game._move(3, 6)
        game.select(3, 0)
        game._move(1, 2)
        game.select(3, 6)
        game._move(4, 5)
        game.select(6, 5)
        game._move(5, 4)
        game.select(4, 5)
        game._move(6, 3)
        game.select(7, 2)
        game._move(5, 4)
        result = game.winner()
        self.assertEqual(result, BLACK)

    def test_reset_when_win(self):
        WIN = pygame.display.set_mode((WIDTH, HEIGHT))
        game = Game(WIN)
        board = Board()
        game.select(5, 0)
        game._move(4, 1)
        game.select(2, 1)
        game._move(3, 2)
        game.select(4, 1)
        game._move(3, 0)
        game.select(3, 2)
        game._move(4, 3)
        game.select(5, 4)
        game._move(3, 2)
        game.select(2, 3)
        game._move(4, 1)
        game.select(6, 1)
        game._move(5, 0)
        game.select(2, 5)
        game._move(3, 4)
        game.select(6, 3)
        game._move(5, 4)
        game.select(1, 4)
        game._move(2, 3)
        game.select(5, 0)
        game._move(1, 4)
        game.select(3, 4)
        game._move(4, 5)
        game.select(5, 2)
        game._move(4, 3)
        game.select(1, 2)
        game._move(2, 3)
        game.select(5, 6)
        game._move(1, 2)
        game.select(1, 6)
        game._move(2, 5)
        game.select(5, 4)
        game._move(4, 5)
        game.select(2, 5)
        game._move(3, 4)
        game.select(7, 0)
        game._move(6, 1)
        game.select(0, 7)
        game._move(1, 6)
        game.select(4, 3)
        game._move(2, 5)
        game.select(2, 7)
        game._move(3, 6)
        game.select(2, 5)
        game._move(0, 7)
        game.select(0, 5)
        game._move(1, 6)
        game.select(0, 7)
        game._move(4, 7)
        game.select(0, 1)
        game._move(2, 3)
        game.select(4, 5)
        game._move(3, 4)
        game.select(1, 0)
        game._move(2, 1)
        game.select(3, 4)
        game._move(1, 2)
        game.select(0, 3)
        game._move(2, 5)
        game.select(1, 2)
        game._move(0, 1)
        game.select(2, 5)
        game._move(3, 6)
        game.select(3, 0)
        game._move(1, 2)
        game.select(3, 6)
        game._move(4, 5)
        game.select(6, 5)
        game._move(5, 4)
        game.select(4, 5)
        game._move(6, 3)
        game.select(7, 2)
        game._move(5, 4)
        if(game.winner() != None):
            game.reset()
        result = game.winner()
        self.assertEqual(result, None)


if __name__ == '__main__':
    unittest.main()
