Skip to content

Instantly share code, notes, and snippets.

@akkartik
Last active September 27, 2015 15:27
Show Gist options
  • Save akkartik/1291243 to your computer and use it in GitHub Desktop.
Save akkartik/1291243 to your computer and use it in GitHub Desktop.
Simple chessboard app. Nothing funky, just putting wart through its paces. (Compare with python version at http://gist.github.com/1218667)
# Requirements: g++
# $ git clone http://github.com/akkartik/wart.git
# $ cd wart
# $ git checkout b5fb9cbccb
# $ wget --no-check-certificate https://raw.github.com/gist/1291243/080chessboard.wart
# $ wart
# Use the 'm' function to make a move. P-K4 is m.5254, etc. m.-1 is undo.
# type chessboard
# Uppercase is white, lowercase is black
<- Board (tag 'chessboard '((r n b q k b n r)
(p p p p p p p p)
(_ _ _ _ _ _ _ _)
(_ _ _ _ _ _ _ _)
(_ _ _ _ _ _ _ _)
(_ _ _ _ _ _ _ _)
(P P P P P P P P)
(R N B Q K B N R)))
# print chessboard objects
def (pr x) :case (isa chessboard x)
let board rep.x
each row board
each square row
pr square
pr " "
prn ""
# setup indexing for objects of type chessboard: board.row.col
defcall chessboard (board n)
rep.board.n
# each move consists of from-square to-square piece-captured
<- Moves nil
# make a move. P-K4 is m.5254, etc.
proc (m n)
<- r2 (8 - n%10) n n/10
<- c2 (n%10 - 1) n n/10
<- r1 (8 - n%10) n n/10
<- c1 n-1
push (list r1 c1 r2 c2 Board.r2.c2) Moves
Board.r2.c2 <- Board.r1.c1
Board.r1.c1 <- '_
# undo
proc (m n) :case (n = -1)
let (r1 c1 r2 c2 old_piece) car.Moves
Board.r1.c1 <- Board.r2.c2
Board.r2.c2 <- old_piece
zap cdr Moves
after_calling (m n)
prn Board
prn Board
$ wart
r n b q k b n r
p p p p p p p p
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
P P P P P P P P
R N B Q K B N R
wart> m.5254
r n b q k b n r
p p p p p p p p
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ P _ _ _
_ _ _ _ _ _ _ _
P P P P _ P P P
R N B Q K B N R
nil
wart> m.5755
r n b q k b n r
p p p p _ p p p
_ _ _ _ _ _ _ _
_ _ _ _ p _ _ _
_ _ _ _ P _ _ _
_ _ _ _ _ _ _ _
P P P P _ P P P
R N B Q K B N R
nil
wart> m.-1
r n b q k b n r
p p p p p p p p
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ P _ _ _
_ _ _ _ _ _ _ _
P P P P _ P P P
R N B Q K B N R
nil
wart> m.3735
r n b q k b n r
p p _ p p p p p
_ _ _ _ _ _ _ _
_ _ p _ _ _ _ _
_ _ _ _ P _ _ _
_ _ _ _ _ _ _ _
P P P P _ P P P
R N B Q K B N R
nil
wart>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment