#import "../game.typ": apply-moves, initial-state #import "../board.typ": is-dark-sq, starting-grid #import "../notation.typ": parse-move #import "../rules.typ": has-legal-move, is-in-check #import "testutil.typ": assert-eq, assert-grid, assert-no-error // pawn advances and turn switching #let st = apply-moves(("e4",)).last() #assert-eq(st.turn, "black") #assert-no-error(st, "e4") #let st = apply-moves(("e4", "e5")).last() #assert-eq(st.turn, "white") #assert-grid(st, 5, 2, ".") // e2 empty #assert-grid(st, 5, 4, "P") // e4 #assert-grid(st, 5, 7, ".") // e7 empty #assert-grid(st, 5, 5, "p") // e5 // "how knight moves?" #let st = apply-moves(("e4", "e5", "Nf3")).last() #assert-grid(st, 6, 3, "N") // f3 #assert-grid(st, 7, 1, ".") // g1 empty // bishop + pawn + capture #let st = apply-moves(("e4", "e5", "Nf3", "Nc6", "Bb5", "a6", "Bxc6")).last() #assert-no-error(st, "Bxc6") #assert-grid(st, 3, 6, "B") // bishop on c6 // took move after clearing a pawn #let st = apply-moves(("a4", "d6", "Ra3")).last() #assert-no-error(st, "Ra3") #assert-grid(st, 1, 3, "R") // a3 #assert-grid(st, 1, 1, ".") // a1 empty // lowercase notation #let st = apply-moves(("e4", "d5", "nf3")).last() #assert-no-error(st, "nf3") #assert-grid(st, 6, 3, "N") // castling white, kingside #let castling-setup = ("e4", "e5", "Nf3", "Nc6", "Bb5", "a6", "Bxc6", "dxc6") #let st = apply-moves(castling-setup + ("O-O",)).last() #assert-no-error(st, "O-O") #assert-grid(st, 5, 1, ".") // e1 empty #assert-grid(st, 7, 1, "K") // g1 #assert-grid(st, 6, 1, "R") // f1 rook #assert-grid(st, 8, 1, ".") // h1 empty #assert(st.castles.find("K") == none) #assert(st.castles.find("Q") == none) // castling blac, kingside #let st = apply-moves(castling-setup + ("O-O", "O-O")).last() #assert-no-error(st, "O-O") #assert-grid(st, 5, 8, ".") // e8 empty #assert-grid(st, 7, 8, "k") // g8 #assert-grid(st, 6, 8, "r") // f8 rook // en passant #let ep = apply-moves(("a4", "b5", "axb6")).last() #assert-eq(ep.turn, "black") #assert-grid(ep, 1, 4, ".") // a4 empty #assert-grid(ep, 2, 6, "P") // b6 #assert-grid(ep, 2, 5, ".") // b5 captured #let ep = apply-moves(("e4", "d5", "e5", "d4", "c4", "dxc3")).last() #assert-grid(ep, 4, 4, ".") // d4 empty #assert-grid(ep, 3, 3, "p") // c3 #assert-grid(ep, 3, 4, ".") // c4 captured #let st = apply-moves(("a4", "b5", "a5")).last() #assert-eq(st.ep, none) #let st = apply-moves(("e4", "d5", "e5", "d4", "exd6")).last() #assert-eq(st.error, "exd6: illegal move")