package chess import ( "mchess_server/types" "testing" "github.com/stretchr/testify/assert" ) func Test_Board_WhiteCastlesLeft_QueenCoversSquareInBetween(t *testing.T) { board := newBoard() board.position[types.Coordinate{Col: 5, Row: 1}] = King{Color: types.White} board.position[types.Coordinate{Col: 1, Row: 1}] = Rook{Color: types.White} board.position[types.Coordinate{Col: 4, Row: 5}] = Queen{Color: types.Black} castling := types.Move{ StartSquare: types.Coordinate{Col: 5, Row: 1}, EndSquare: types.Coordinate{Col: 3, Row: 1}, ColorMoved: types.White, } valid, _ := board.CheckAndPlay(&castling) assert.False(t, valid) } func Test_Board_WhiteCastlesRight_QueenCoversSquareInBetween(t *testing.T) { board := newBoard() board.position[types.Coordinate{Col: 5, Row: 1}] = King{Color: types.White} board.position[types.Coordinate{Col: 8, Row: 1}] = Rook{Color: types.White} board.position[types.Coordinate{Col: 6, Row: 5}] = Queen{Color: types.Black} castling := types.Move{ StartSquare: types.Coordinate{Col: 5, Row: 1}, EndSquare: types.Coordinate{Col: 7, Row: 1}, ColorMoved: types.White, } valid, _ := board.CheckAndPlay(&castling) assert.False(t, valid) } func Test_Board_WhiteCastlesLeft_KingInCheck(t *testing.T) { board := newBoard() board.position[types.Coordinate{Col: 5, Row: 1}] = King{Color: types.White} board.position[types.Coordinate{Col: 1, Row: 1}] = Rook{Color: types.White} board.position[types.Coordinate{Col: 5, Row: 5}] = Queen{Color: types.Black} castling := types.Move{ StartSquare: types.Coordinate{Col: 5, Row: 1}, EndSquare: types.Coordinate{Col: 3, Row: 1}, ColorMoved: types.White, } valid, violation := board.CheckAndPlay(&castling) assert.False(t, valid) assert.Equal(t, CastlingWhileKingInCheck, violation) } func Test_Board_WhiteCastlesLeft_QueenCoversKingsSquare(t *testing.T) { board := newBoard() board.position[types.Coordinate{Col: 5, Row: 1}] = King{Color: types.White} board.position[types.Coordinate{Col: 1, Row: 1}] = Rook{Color: types.White} board.position[types.Coordinate{Col: 3, Row: 5}] = Queen{Color: types.Black} castling := types.Move{ StartSquare: types.Coordinate{Col: 5, Row: 1}, EndSquare: types.Coordinate{Col: 3, Row: 1}, ColorMoved: types.White, } valid, _ := board.CheckAndPlay(&castling) assert.False(t, valid) } func Test_Board_BlackCastlesLeft_QueenCoversSquareInBetween(t *testing.T) { board := newBoard() board.colorToMove = types.Black board.position[types.Coordinate{Col: 5, Row: 8}] = King{Color: types.Black} board.position[types.Coordinate{Col: 1, Row: 8}] = Rook{Color: types.Black} board.position[types.Coordinate{Col: 4, Row: 4}] = Queen{Color: types.White} castling := types.Move{ StartSquare: types.Coordinate{Col: 5, Row: 8}, EndSquare: types.Coordinate{Col: 3, Row: 8}, ColorMoved: types.Black, } valid, _ := board.CheckAndPlay(&castling) assert.False(t, valid) } func Test_Board_BlackCastlesRight_QueenCoversSquareInBetween(t *testing.T) { board := newBoard() board.colorToMove = types.Black board.position[types.Coordinate{Col: 5, Row: 8}] = King{Color: types.Black} board.position[types.Coordinate{Col: 8, Row: 8}] = Rook{Color: types.Black} board.position[types.Coordinate{Col: 6, Row: 4}] = Queen{Color: types.White} castling := types.Move{ StartSquare: types.Coordinate{Col: 5, Row: 8}, EndSquare: types.Coordinate{Col: 7, Row: 8}, ColorMoved: types.Black, } valid, _ := board.CheckAndPlay(&castling) assert.False(t, valid) } func Test_Board_BlackCastlesLeft_KingInCheck(t *testing.T) { board := newBoard() board.colorToMove = types.Black board.position[types.Coordinate{Col: 5, Row: 8}] = King{Color: types.Black} board.position[types.Coordinate{Col: 1, Row: 8}] = Rook{Color: types.Black} board.position[types.Coordinate{Col: 5, Row: 4}] = Queen{Color: types.White} castling := types.Move{ StartSquare: types.Coordinate{Col: 5, Row: 8}, EndSquare: types.Coordinate{Col: 3, Row: 8}, ColorMoved: types.Black, } valid, violation := board.CheckAndPlay(&castling) assert.False(t, valid) assert.Equal(t, CastlingWhileKingInCheck, violation) } func Test_Board_BlackCastlesLeft_QueenCoversKingsSquare(t *testing.T) { board := newBoard() board.colorToMove = types.Black board.position[types.Coordinate{Col: 5, Row: 8}] = King{Color: types.Black} board.position[types.Coordinate{Col: 1, Row: 8}] = Rook{Color: types.Black} board.position[types.Coordinate{Col: 3, Row: 4}] = Queen{Color: types.White} castling := types.Move{ StartSquare: types.Coordinate{Col: 5, Row: 8}, EndSquare: types.Coordinate{Col: 3, Row: 8}, ColorMoved: types.Black, } valid, _ := board.CheckAndPlay(&castling) assert.False(t, valid) }