lx_chess_cr/spec/lx_chess/castling_spec.cr
2021-09-17 00:08:53 -04:00

32 lines
1,012 B
Crystal

require "../spec_helper"
require "../../src/lx_chess/board"
require "../../src/lx_chess/piece"
require "../../src/lx_chess/move_set"
require "../../src/lx_chess/game"
require "../../src/lx_chess/fen"
include LxChess
describe "Castling" do
describe "white" do
it "moves the king and the rook when castling kingside" do
fen = Fen.parse("8/8/8/8/8/8/8/R3K2R w KQkq - 0 1")
game = Game.new(board: fen.board, players: [Player.new, Player.new])
game.make_move(from: "e1", to: "g1")
debug_board(game, ["e1", "g1"])
fen.update(game)
fen.to_s.should eq("8/8/8/8/8/8/8/R4RK1 b kq - 1 1")
end
it "moves the king and the rook when castling queenside" do
fen = Fen.parse("8/8/8/8/8/8/8/R3K2R w KQkq - 0 1")
game = Game.new(board: fen.board, players: [Player.new, Player.new])
game.make_move(from: "e1", to: "c11")
debug_board(game, ["e1", "c1"])
fen.update(game)
fen.to_s.should eq("8/8/8/8/8/8/8/2KR3R b kq - 1 1")
end
end
end