import unittest
from should_dsl import should
from chessboard import ChessBoard
from chesstournament.piece import Rook, Pawn, Horse, Bishop


class TestBoard(unittest.TestCase):

    def it_has_a_size(self):
        board = ChessBoard()
        board.width |should| equal_to(8)
        board.height |should| equal_to(8)

    def its_fields_have_colors(self):
        board = ChessBoard()
        corner0 = board.get_field(0, 0)
        corner0.color |should| equal_to("white")
        corner1 = board.get_field(0, 7)
        corner1.color |should| equal_to("black")
        corner2 = board.get_field(7, 0)
        corner2.color |should| equal_to("black")
        corner3 = board.get_field(7, 7)
        corner3.color |should| equal_to("white")

    def it_has_pieces(self):
        board = ChessBoard()
        corner0 = board.get_field(0, 0)
        type(corner0.piece) |should| be(Rook)
        corner0.piece.color |should| equal_to("black")
        field = board.get_field(4, 1)
        type(field.piece) |should| be(Pawn)
        field.piece.color |should| equal_to("black")
        field = board.get_field(3, 6)
        type(field.piece) |should| be(Pawn)
        field.piece.color |should| equal_to("white")

    def it_can_remove_a_piece(self):
        board = ChessBoard()
        field = board.get_field(4, 6)
        type(field.piece) |should| be(Pawn)
        white_pawn = board.get_piece(4, 6)
        field.piece |should| be(None)
        type(white_pawn) |should| be(Pawn)

    def it_only_remove_pieces_of_turn_player(self):
        board = ChessBoard()
        field1 = board.get_field(4, 1)
        type(field1.piece) |should| be(Pawn)
        board.get_piece(4, 1) |should| be(None)
        type(field1.piece) |should| be(Pawn)
        field2 = board.get_field(4, 6)
        type(field2.piece) |should| be(Pawn)
        white_pawn = board.get_piece(4, 6)
        field2.piece |should| be(None)
        type(white_pawn) |should| be(Pawn)

    def it_can_put_a_piece(self):
        board = ChessBoard()
        origin_field = board.get_field(2, 6)
        target_field = board.get_field(2, 4)
        board.turn |should| equal_to("white")
        type(origin_field.piece) |should| be(Pawn)
        target_field.piece |should| be(None)
        white_pawn = board.get_piece(2, 6)
        board.put_piece(white_pawn, 2, 4)
        board.turn |should| equal_to("black")
        origin_field.piece |should| be(None)
        type(target_field.piece) |should| be(Pawn)

    def it_knows_the_panw_movimentation(self):
        board = ChessBoard()
        pawn = board.board[1][1].piece
        type(pawn) |should| be(Pawn)
        board.movimentation_possibilities(pawn) |should| equal_to([(2, 1), (3, 1)])
        board.board[2][0].piece = board.board[6][0].piece
        board.movimentation_possibilities(pawn) |should| equal_to([(2, 1), (3, 1), (2, 0)])
        
    def it_knows_the_horse_movimentation(self):
        board = ChessBoard()
        horse = board.board[0][1].piece
        type(horse) |should| be(Horse)
        board.movimentation_possibilities(horse) |should| equal_to([(2, 2), (2, 0)])
        
    def it_knows_the_bishop_movimentation(self):
        board = ChessBoard()
        bishop = board.board[0][2].piece
        type(bishop) |should| be(Bishop)  
        board.movimentation_possibilities(bishop) |should| equal_to([])
        board.put_piece(bishop, 3, 3)
        bishop_ = board.board[3][3].piece
        type(bishop_) |should| be(Bishop)
        board.movimentation_possibilities(bishop_) |should| equal_to([(4, 4), (5, 5), (6, 6), (4, 2), (5, 1), (6, 0), (2, 4), (2, 2)])
        

@@ -2903,32 +2903,53 @@
 ovimentation
+_for_initial_position
 (self):%0A
         boar
@@ -2928,32 +2928,32 @@
 position(self):%0A
-
         board = 
@@ -3120,17 +3120,612 @@
 (2, 
-2), (2, 0
+0), (2, 2)%5D)%0A        horse = board.board%5B0%5D%5B6%5D.piece%0A        type(horse) %7Cshould%7C be(Horse)%0A        board.movimentation_possibilities(horse) %7Cshould%7C equal_to(%5B(2,5),(2,7)%5D)%0A%0A    def it_knows_the_horse_movimentation_out_initial_position(self):%0A        board = ChessBoard()%0A        board.board%5B4%5D%5B4%5D.piece = Horse('black  ', 4, 4)%0A        horse = board.board%5B4%5D%5B4%5D.piece%0A        type(horse) %7Cshould%7C be(Horse)%0A        possibilities = board.movimentation_possibilities(horse)%0A        possibilities.sort()%0A        possibilities %7Cshould%7C equal_to(%5B(2, 3), (2, 5), (3, 2),(3, 6), (5, 2), (5, 6), (6, 3), (6, 5
 )%5D)%0A

Create tests for horse movimentation