#import "testutil.typ": assert-eq #import "../game.typ": apply-moves, initial-state #import "../rules.typ": has-legal-move, is-in-check // no one is in check at the start #assert(not is-in-check(initial-state().grid, "white")) #assert(not is-in-check(initial-state().grid, "black")) // queen gives check without bishop cover: Qxf7+ after e4 e5 Qh5 Nc6 // and black king can escape by capturing the queen (king on e8, queen on f7) #let st = apply-moves(("e4", "e5", "Qh5", "Nc6", "Qxf7+")).last() #assert(is-in-check(st.grid, st.turn)) #assert(has-legal-move(st.grid, st.turn)) #assert(not st.checkmate) // scholar's mate #let st = apply-moves(("e4", "e5", "Qh5", "a6", "Bc4", "a5", "Qxf7")).last() #assert(is-in-check(st.grid, st.turn)) #assert(not has-legal-move(st.grid, st.turn)) #assert(st.checkmate) // stalemate #let stale = ( ..initial-state(), grid: ( ("k", ".", ".", ".", ".", ".", ".", "."), (".", ".", ".", ".", ".", ".", ".", "."), (".", "Q", ".", ".", ".", ".", ".", "."), (".", ".", ".", ".", ".", ".", ".", "."), (".", ".", ".", ".", ".", ".", ".", "."), (".", ".", ".", ".", ".", ".", ".", "."), (".", ".", ".", ".", ".", ".", ".", "."), ("K", ".", ".", ".", ".", ".", ".", "."), ), turn: "black", castles: "", ep: none, ) #assert(not is-in-check(stale.grid, stale.turn)) #assert(not has-legal-move(stale.grid, stale.turn))