about summary refs log tree commit diff stats
path: root/chessboard.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-10 13:09:53 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-10 13:09:53 -0700
commitd9fbe9c1ca8919f0dba5d5b606b1d5609d3ee73a (patch)
tree2cb065c43ef186c91c8a43f23568539ff55cc7a2 /chessboard.mu
parent7f34d0f7067ce1576f3a4e9d7f23ada18e8ca0d1 (diff)
downloadmu-d9fbe9c1ca8919f0dba5d5b606b1d5609d3ee73a.tar.gz
1339
Diffstat (limited to 'chessboard.mu')
-rw-r--r--chessboard.mu84
1 files changed, 42 insertions, 42 deletions
diff --git a/chessboard.mu b/chessboard.mu
index 5bef4146..16b03773 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -19,6 +19,48 @@ recipe main [
   return-to-console  # cleanup screen and keyboard
 ]
 
+recipe chessboard [
+  default-space:address:array:location <- new location:type, 30:literal
+  screen:address <- next-ingredient
+  keyboard:address <- next-ingredient
+  board:address:array:address:array:character <- initial-position
+  # hook up stdin
+  stdin:address:channel <- init-channel 10:literal/capacity
+  start-running send-keys-to-channel:recipe, keyboard:address, stdin:address:channel, screen:address
+  # buffer lines in stdin
+  buffered-stdin:address:channel <- init-channel 10:literal/capacity
+  start-running buffer-lines:recipe, stdin:address:channel, buffered-stdin:address:channel
+  {
+    msg:address:array:character <- new [Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves.
+]
+    print-string screen:address, msg:address:array:character
+    cursor-to-next-line screen:address
+    print-board screen:address, board:address:array:address:array:character
+    cursor-to-next-line screen:address
+    msg:address:array:character <- new [Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>.
+]
+    print-string screen:address, msg:address:array:character
+    cursor-to-next-line screen:address
+    msg:address:array:character <- new [Hit 'q' to exit.
+]
+    print-string screen:address, msg:address:array:character
+    {
+      cursor-to-next-line screen:address
+      msg:address:array:character <- new [move: ]
+      print-string screen:address, msg:address:array:character
+      m:address:move, quit:boolean, error:boolean <- read-move buffered-stdin:address:channel, screen:address
+      break-if quit:boolean, +quit:offset
+      buffered-stdin:address:channel <- clear-channel buffered-stdin:address:channel  # cleanup after error. todo: test this?
+      loop-if error:boolean
+    }
+    board:address:array:address:array:character <- make-move board:address:array:address:array:character, m:address:move
+    clear-screen screen:address
+    loop
+  }
+  +quit
+#?   $print [aaa] #? 1
+]
+
 ## a board is an array of files, a file is an array of characters (squares)
 
 recipe init-board [
@@ -552,45 +594,3 @@ scenario making-a-move [
     .                              .
   ]
 ]
-
-recipe chessboard [
-  default-space:address:array:location <- new location:type, 30:literal
-  screen:address <- next-ingredient
-  keyboard:address <- next-ingredient
-  board:address:array:address:array:character <- initial-position
-  # hook up stdin
-  stdin:address:channel <- init-channel 10:literal/capacity
-  start-running send-keys-to-channel:recipe, keyboard:address, stdin:address:channel, screen:address
-  # buffer lines in stdin
-  buffered-stdin:address:channel <- init-channel 10:literal/capacity
-  start-running buffer-lines:recipe, stdin:address:channel, buffered-stdin:address:channel
-  {
-    msg:address:array:character <- new [Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves.
-]
-    print-string screen:address, msg:address:array:character
-    cursor-to-next-line screen:address
-    print-board screen:address, board:address:array:address:array:character
-    cursor-to-next-line screen:address
-    msg:address:array:character <- new [Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>.
-]
-    print-string screen:address, msg:address:array:character
-    cursor-to-next-line screen:address
-    msg:address:array:character <- new [Hit 'q' to exit.
-]
-    print-string screen:address, msg:address:array:character
-    {
-      cursor-to-next-line screen:address
-      msg:address:array:character <- new [move: ]
-      print-string screen:address, msg:address:array:character
-      m:address:move, quit:boolean, error:boolean <- read-move buffered-stdin:address:channel, screen:address
-      break-if quit:boolean, +quit:offset
-      buffered-stdin:address:channel <- clear-channel buffered-stdin:address:channel  # cleanup after error. todo: test this?
-      loop-if error:boolean
-    }
-    board:address:array:address:array:character <- make-move board:address:array:address:array:character, m:address:move
-    clear-screen screen:address
-    loop
-  }
-  +quit
-#?   $print [aaa] #? 1
-]