From a83d8656063a908ef48a0852126888163ead5673 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 31 Dec 2014 00:58:31 -0800 Subject: 473 - print chessboard Once we started printing we uncovered that we were storing positions by rank rather than by file as we'd planned. Amazing how slow it is. Might be interesting to try to compile it down to straightforward assembler and see how fast it gets. --- chessboard.mu | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'chessboard.mu') diff --git a/chessboard.mu b/chessboard.mu index efbec20c..e0a79656 100644 --- a/chessboard.mu +++ b/chessboard.mu @@ -1,13 +1,13 @@ (function read-board [ (default-scope:scope-address <- new scope:literal 30:literal) - (initial-position:list-address <- init-list R:literal N:literal B:literal Q:literal K:literal B:literal N:literal R:literal - P:literal P:literal P:literal P:literal P:literal P:literal P:literal P:literal - _:literal _:literal _:literal _:literal _:literal _:literal _:literal _:literal - _:literal _:literal _:literal _:literal _:literal _:literal _:literal _:literal - _:literal _:literal _:literal _:literal _:literal _:literal _:literal _:literal - _:literal _:literal _:literal _:literal _:literal _:literal _:literal _:literal - p:literal p:literal p:literal p:literal p:literal p:literal p:literal p:literal - r:literal n:literal b:literal q:literal k:literal b:literal n:literal r:literal) + (initial-position:list-address <- init-list R:literal P:literal _:literal _:literal _:literal _:literal p:literal r:literal + N:literal P:literal _:literal _:literal _:literal _:literal p:literal n:literal + B:literal P:literal _:literal _:literal _:literal _:literal p:literal b:literal + Q:literal P:literal _:literal _:literal _:literal _:literal p:literal q:literal + K:literal P:literal _:literal _:literal _:literal _:literal p:literal k:literal + B:literal P:literal _:literal _:literal _:literal _:literal p:literal b:literal + N:literal P:literal _:literal _:literal _:literal _:literal p:literal n:literal + R:literal P:literal _:literal _:literal _:literal _:literal p:literal r:literal) ; assert(length(initial-position) == 64) ;? (print-primitive (("list-length\n" literal))) (len:integer <- list-length initial-position:list-address) @@ -51,10 +51,33 @@ ]) (function print-board [ - (reply) + (default-scope:scope-address <- new scope:literal 30:literal) + (b:board-address <- next-input) + (row:integer <- copy 7:literal) + ; print each row + { begin + (done?:boolean <- less-than row:integer 0:literal) + (break-if done?:boolean) + ; print each square in the row + (col:integer <- copy 0:literal) + { begin + (done?:boolean <- equal col:integer 8:literal) + (break-if done?:boolean) + (f:file-address <- index b:board-address/deref col:integer) + (s:square <- index f:file-address/deref row:integer) + (print-primitive s:square) + (print-primitive ((" " literal))) + (col:integer <- add col:integer 1:literal) + (loop) + } + (print-primitive (("\n" literal))) + (row:integer <- subtract row:integer 1:literal) + (loop) + } ]) (function main [ +;? (print-primitive (("\u2654 \u265a" literal))) (b:board-address <- read-board) (print-board b:board-address) ]) -- cgit 1.4.1-2-gfad0