about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--014types.cc10
-rw-r--r--chessboard.mu84
2 files changed, 49 insertions, 45 deletions
diff --git a/014types.cc b/014types.cc
index 775db323..ca089a64 100644
--- a/014types.cc
+++ b/014types.cc
@@ -22,9 +22,13 @@ void insert_container(const string& command, kind_of_type kind, istream& in) {
   skip_whitespace(in);
   string name = next_word(in);
   trace("parse") << "reading " << command << ' ' << name;
-//?   cout << name << '\n'; //? 1
-  assert(Type_number.find(name) == Type_number.end());
-  Type_number[name] = Next_type_number++;
+//?   cout << name << '\n'; //? 2
+//?   if (Type_number.find(name) != Type_number.end()) //? 1
+//?     cerr << Type_number[name] << '\n'; //? 1
+  if (Type_number.find(name) == Type_number.end()
+      || Type_number[name] == 0) {
+    Type_number[name] = Next_type_number++;
+  }
   skip_bracket(in, "'container' must begin with '['");
   assert(Type.find(Type_number[name]) == Type.end());
   type_info& t = Type[Type_number[name]];
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
-]
28 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415