From 615f4a970a2fa5c91766ee585a7d531b083f4bff Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 23 Sep 2017 19:30:00 -0700 Subject: 4003 --- html/chessboard.mu.html | 603 +++++++++++++++++++++++------------------------- 1 file changed, 295 insertions(+), 308 deletions(-) (limited to 'html/chessboard.mu.html') diff --git a/html/chessboard.mu.html b/html/chessboard.mu.html index 4d77517e..7376039a 100644 --- a/html/chessboard.mu.html +++ b/html/chessboard.mu.html @@ -159,7 +159,7 @@ if ('onhashchange' in window) { 95 ¦ ¦ buffered-stdin-in <- clear buffered-stdin-in # cleanup after error. todo: test this? 96 ¦ ¦ loop-if error 97 ¦ } - 98 ¦ board <- make-move board, m + 98 ¦ board <- make-move board, m 99 ¦ screen <- clear-screen screen 100 ¦ loop 101 } @@ -308,21 +308,21 @@ if ('onhashchange' in window) { 244 # construct the move object 245 result:&:move <- new move:type 246 *result <- put *result, from-file:offset, from-file -247 from-rank:num, quit?, error? <- read-rank stdin, screen +247 from-rank:num, quit?, error? <- read-rank stdin, screen 248 return-if quit?, 0/dummy 249 return-if error?, 0/dummy 250 *result <- put *result, from-rank:offset, from-rank -251 error? <- expect-from-channel stdin, 45/dash, screen +251 error? <- expect-from-channel stdin, 45/dash, screen 252 return-if error?, 0/dummy, 0/quit 253 to-file:num, quit?, error? <- read-file stdin, screen 254 return-if quit?, 0/dummy 255 return-if error?, 0/dummy 256 *result <- put *result, to-file:offset, to-file -257 to-rank:num, quit?, error? <- read-rank stdin, screen +257 to-rank:num, quit?, error? <- read-rank stdin, screen 258 return-if quit?, 0/dummy 259 return-if error?, 0/dummy 260 *result <- put *result, to-rank:offset, to-rank -261 error? <- expect-from-channel stdin, 10/newline, screen +261 error? <- expect-from-channel stdin, 10/newline, screen 262 return-if error?, 0/dummy, 0/quit 263 ] 264 @@ -332,311 +332,298 @@ if ('onhashchange' in window) { 268 load-ingredients 269 c:char, eof?:bool, stdin <- read stdin 270 return-if eof?, 0/dummy, 1/quit, 0/error -271 { -272 ¦ q-pressed?:bool <- equal c, 81/Q -273 ¦ break-unless q-pressed? -274 ¦ return 0/dummy, 1/quit, 0/error -275 } -276 { -277 ¦ q-pressed? <- equal c, 113/q -278 ¦ break-unless q-pressed? -279 ¦ return 0/dummy, 1/quit, 0/error -280 } -281 { -282 ¦ empty-fake-keyboard?:bool <- equal c, 0/eof -283 ¦ break-unless empty-fake-keyboard? -284 ¦ return 0/dummy, 1/quit, 0/error -285 } -286 { -287 ¦ newline?:bool <- equal c, 10/newline -288 ¦ break-unless newline? -289 ¦ print screen, [that's not enough] -290 ¦ return 0/dummy, 0/quit, 1/error -291 } -292 file:num <- subtract c, 97/a -293 # 'a' <= file <= 'h' -294 { -295 ¦ above-min:bool <- greater-or-equal file, 0 -296 ¦ break-if above-min -297 ¦ print screen, [file too low: ] -298 ¦ print screen, c -299 ¦ cursor-to-next-line screen -300 ¦ return 0/dummy, 0/quit, 1/error -301 } -302 { -303 ¦ below-max:bool <- lesser-than file, 8 -304 ¦ break-if below-max -305 ¦ print screen, [file too high: ] -306 ¦ print screen, c -307 ¦ return 0/dummy, 0/quit, 1/error -308 } -309 return file, 0/quit, 0/error -310 ] -311 -312 # valid values for rank: 0-7 -313 def read-rank stdin:&:source:char, screen:&:screen -> rank:num, quit?:bool, error?:bool, stdin:&:source:char, screen:&:screen [ -314 local-scope -315 load-ingredients -316 c:char, eof?:bool, stdin <- read stdin -317 return-if eof?, 0/dummy, 1/quit, 0/error -318 { -319 ¦ q-pressed?:bool <- equal c, 8/Q -320 ¦ break-unless q-pressed? -321 ¦ return 0/dummy, 1/quit, 0/error -322 } +271 q-pressed?:bool <- equal c, 81/Q +272 return-if q-pressed?, 0/dummy, 1/quit, 0/error +273 q-pressed? <- equal c, 113/q +274 return-if q-pressed?, 0/dummy, 1/quit, 0/error +275 empty-fake-keyboard?:bool <- equal c, 0/eof +276 return-if empty-fake-keyboard?, 0/dummy, 1/quit, 0/error +277 { +278 ¦ newline?:bool <- equal c, 10/newline +279 ¦ break-unless newline? +280 ¦ print screen, [that's not enough] +281 ¦ return 0/dummy, 0/quit, 1/error +282 } +283 file:num <- subtract c, 97/a +284 # 'a' <= file <= 'h' +285 { +286 ¦ above-min:bool <- greater-or-equal file, 0 +287 ¦ break-if above-min +288 ¦ print screen, [file too low: ] +289 ¦ print screen, c +290 ¦ cursor-to-next-line screen +291 ¦ return 0/dummy, 0/quit, 1/error +292 } +293 { +294 ¦ below-max:bool <- lesser-than file, 8 +295 ¦ break-if below-max +296 ¦ print screen, [file too high: ] +297 ¦ print screen, c +298 ¦ return 0/dummy, 0/quit, 1/error +299 } +300 return file, 0/quit, 0/error +301 ] +302 +303 # valid values for rank: 0-7 +304 def read-rank stdin:&:source:char, screen:&:screen -> rank:num, quit?:bool, error?:bool, stdin:&:source:char, screen:&:screen [ +305 local-scope +306 load-ingredients +307 c:char, eof?:bool, stdin <- read stdin +308 return-if eof?, 0/dummy, 1/quit, 0/error +309 q-pressed?:bool <- equal c, 81/Q +310 return-if q-pressed?, 0/dummy, 1/quit, 0/error +311 q-pressed? <- equal c, 113/q +312 return-if q-pressed?, 0/dummy, 1/quit, 0/error +313 empty-fake-keyboard?:bool <- equal c, 0/eof +314 return-if empty-fake-keyboard?, 0/dummy, 1/quit, 0/error +315 { +316 ¦ newline?:bool <- equal c, 10 # newline +317 ¦ break-unless newline? +318 ¦ print screen, [that's not enough] +319 ¦ return 0/dummy, 0/quit, 1/error +320 } +321 rank:num <- subtract c, 49/'1' +322 # assert'1' <= rank <= '8' 323 { -324 ¦ q-pressed? <- equal c, 113/q -325 ¦ break-unless q-pressed? -326 ¦ return 0/dummy, 1/quit, 0/error -327 } -328 { -329 ¦ newline?:bool <- equal c, 10 # newline -330 ¦ break-unless newline? -331 ¦ print screen, [that's not enough] -332 ¦ return 0/dummy, 0/quit, 1/error -333 } -334 rank:num <- subtract c, 49/'1' -335 # assert'1' <= rank <= '8' -336 { -337 ¦ above-min:bool <- greater-or-equal rank, 0 -338 ¦ break-if above-min -339 ¦ print screen, [rank too low: ] -340 ¦ print screen, c -341 ¦ return 0/dummy, 0/quit, 1/error -342 } -343 { -344 ¦ below-max:bool <- lesser-or-equal rank, 7 -345 ¦ break-if below-max -346 ¦ print screen, [rank too high: ] -347 ¦ print screen, c -348 ¦ return 0/dummy, 0/quit, 1/error -349 } -350 return rank, 0/quit, 0/error -351 ] -352 -353 # read a character from the given channel and check that it's what we expect -354 # return true on error -355 def expect-from-channel stdin:&:source:char, expected:char, screen:&:screen -> result:bool, stdin:&:source:char, screen:&:screen [ +324 ¦ above-min:bool <- greater-or-equal rank, 0 +325 ¦ break-if above-min +326 ¦ print screen, [rank too low: ] +327 ¦ print screen, c +328 ¦ return 0/dummy, 0/quit, 1/error +329 } +330 { +331 ¦ below-max:bool <- lesser-or-equal rank, 7 +332 ¦ break-if below-max +333 ¦ print screen, [rank too high: ] +334 ¦ print screen, c +335 ¦ return 0/dummy, 0/quit, 1/error +336 } +337 return rank, 0/quit, 0/error +338 ] +339 +340 # read a character from the given channel and check that it's what we expect +341 # return true on error +342 def expect-from-channel stdin:&:source:char, expected:char, screen:&:screen -> result:bool, stdin:&:source:char, screen:&:screen [ +343 local-scope +344 load-ingredients +345 c:char, eof?:bool, stdin <- read stdin +346 return-if eof? 1/true +347 { +348 ¦ match?:bool <- equal c, expected +349 ¦ break-if match? +350 ¦ print screen, [expected character not found] +351 } +352 result <- not match? +353 ] +354 +355 scenario read-move-blocking [ 356 local-scope -357 load-ingredients -358 c:char, eof?:bool, stdin <- read stdin -359 return-if eof? 1/true -360 { -361 ¦ match?:bool <- equal c, expected -362 ¦ break-if match? -363 ¦ print screen, [expected character not found] -364 } -365 result <- not match? -366 ] -367 -368 scenario read-move-blocking [ -369 local-scope -370 assume-screen 20/width, 2/height -371 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity -372 read-move-routine:num/routine <- start-running read-move, source, screen:&:screen -373 run [ -374 ¦ # 'read-move' is waiting for input -375 ¦ wait-for-routine-to-block read-move-routine -376 ¦ read-move-state:num <- routine-state read-move-routine -377 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued -378 ¦ assert waiting?, [ -379 F read-move-blocking: routine failed to pause after coming up (before any keys were pressed)] -380 ¦ # press 'a' -381 ¦ sink <- write sink, 97/a -382 ¦ restart read-move-routine -383 ¦ # 'read-move' still waiting for input -384 ¦ wait-for-routine-to-block read-move-routine -385 ¦ read-move-state <- routine-state read-move-routine -386 ¦ waiting? <- not-equal read-move-state, 2/discontinued -387 ¦ assert waiting?, [ -388 F read-move-blocking: routine failed to pause after rank 'a'] -389 ¦ # press '2' -390 ¦ sink <- write sink, 50/'2' -391 ¦ restart read-move-routine -392 ¦ # 'read-move' still waiting for input -393 ¦ wait-for-routine-to-block read-move-routine -394 ¦ read-move-state <- routine-state read-move-routine -395 ¦ waiting? <- not-equal read-move-state, 2/discontinued -396 ¦ assert waiting?, [ -397 F read-move-blocking: routine failed to pause after file 'a2'] -398 ¦ # press '-' -399 ¦ sink <- write sink, 45/'-' -400 ¦ restart read-move-routine -401 ¦ # 'read-move' still waiting for input -402 ¦ wait-for-routine-to-block read-move-routine -403 ¦ read-move-state <- routine-state read-move-routine -404 ¦ waiting? <- not-equal read-move-state, 2/discontinued -405 ¦ assert waiting?, [ -406 F read-move-blocking: routine failed to pause after hyphen 'a2-'] -407 ¦ # press 'a' -408 ¦ sink <- write sink, 97/a -409 ¦ restart read-move-routine -410 ¦ # 'read-move' still waiting for input -411 ¦ wait-for-routine-to-block read-move-routine -412 ¦ read-move-state <- routine-state read-move-routine -413 ¦ waiting? <- not-equal read-move-state, 2/discontinued -414 ¦ assert waiting?, [ -415 F read-move-blocking: routine failed to pause after rank 'a2-a'] -416 ¦ # press '4' -417 ¦ sink <- write sink, 52/'4' -418 ¦ restart read-move-routine -419 ¦ # 'read-move' still waiting for input -420 ¦ wait-for-routine-to-block read-move-routine -421 ¦ read-move-state <- routine-state read-move-routine -422 ¦ waiting? <- not-equal read-move-state, 2/discontinued -423 ¦ assert waiting?, [ -424 F read-move-blocking: routine failed to pause after file 'a2-a4'] -425 ¦ # press 'newline' -426 ¦ sink <- write sink, 10 # newline -427 ¦ restart read-move-routine -428 ¦ # 'read-move' now completes -429 ¦ wait-for-routine-to-block read-move-routine -430 ¦ read-move-state <- routine-state read-move-routine -431 ¦ completed?:bool <- equal read-move-state, 1/completed -432 ¦ assert completed?, [ -433 F read-move-blocking: routine failed to terminate on newline] -434 ¦ trace 1, [test], [reached end] -435 ] -436 trace-should-contain [ -437 ¦ test: reached end -438 ] -439 ] -440 -441 scenario read-move-quit [ -442 local-scope -443 assume-screen 20/width, 2/height -444 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity -445 read-move-routine:num <- start-running read-move, source, screen:&:screen -446 run [ -447 ¦ # 'read-move' is waiting for input -448 ¦ wait-for-routine-to-block read-move-routine -449 ¦ read-move-state:num <- routine-state read-move-routine -450 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued -451 ¦ assert waiting?, [ -452 F read-move-quit: routine failed to pause after coming up (before any keys were pressed)] -453 ¦ # press 'q' -454 ¦ sink <- write sink, 113/q -455 ¦ restart read-move-routine -456 ¦ # 'read-move' completes -457 ¦ wait-for-routine-to-block read-move-routine -458 ¦ read-move-state <- routine-state read-move-routine -459 ¦ completed?:bool <- equal read-move-state, 1/completed -460 ¦ assert completed?, [ -461 F read-move-quit: routine failed to terminate on 'q'] -462 ¦ trace 1, [test], [reached end] -463 ] -464 trace-should-contain [ -465 ¦ test: reached end -466 ] -467 ] -468 -469 scenario read-move-illegal-file [ -470 local-scope -471 assume-screen 20/width, 2/height -472 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity -473 read-move-routine:num <- start-running read-move, source, screen:&:screen -474 run [ -475 ¦ # 'read-move' is waiting for input -476 ¦ wait-for-routine-to-block read-move-routine -477 ¦ read-move-state:num <- routine-state read-move-routine -478 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued -479 ¦ assert waiting?, [ -480 F read-move-illegal-file: routine failed to pause after coming up (before any keys were pressed)] -481 ¦ sink <- write sink, 50/'2' -482 ¦ restart read-move-routine -483 ¦ wait-for-routine-to-block read-move-routine -484 ] -485 screen-should-contain [ -486 ¦ .file too low: 2 . -487 ¦ . . -488 ] -489 ] -490 -491 scenario read-move-illegal-rank [ -492 local-scope -493 assume-screen 20/width, 2/height -494 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity -495 read-move-routine:num <- start-running read-move, source, screen:&:screen -496 run [ -497 ¦ # 'read-move' is waiting for input -498 ¦ wait-for-routine-to-block read-move-routine -499 ¦ read-move-state:num <- routine-state read-move-routine -500 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued -501 ¦ assert waiting?, [ -502 F read-move-illegal-rank: routine failed to pause after coming up (before any keys were pressed)] -503 ¦ sink <- write sink, 97/a -504 ¦ sink <- write sink, 97/a -505 ¦ restart read-move-routine -506 ¦ wait-for-routine-to-block read-move-routine -507 ] -508 screen-should-contain [ -509 ¦ .rank too high: a . -510 ¦ . . -511 ] -512 ] -513 -514 scenario read-move-empty [ -515 local-scope -516 assume-screen 20/width, 2/height -517 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity -518 read-move-routine:num <- start-running read-move, source, screen:&:screen -519 run [ -520 ¦ # 'read-move' is waiting for input -521 ¦ wait-for-routine-to-block read-move-routine -522 ¦ read-move-state:num <- routine-state read-move-routine -523 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued -524 ¦ assert waiting?, [ -525 F read-move-empty: routine failed to pause after coming up (before any keys were pressed)] -526 ¦ sink <- write sink, 10/newline -527 ¦ sink <- write sink, 97/a -528 ¦ restart read-move-routine -529 ¦ wait-for-routine-to-block read-move-routine -530 ] -531 screen-should-contain [ -532 ¦ .that's not enough . -533 ¦ . . -534 ] -535 ] -536 -537 def make-move board:board, m:&:move -> board:board [ -538 local-scope -539 load-ingredients -540 from-file:num <- get *m, from-file:offset -541 from-rank:num <- get *m, from-rank:offset -542 to-file:num <- get *m, to-file:offset -543 to-rank:num <- get *m, to-rank:offset -544 from-f:&:@:char <- index *board, from-file -545 to-f:&:@:char <- index *board, to-file -546 src:char/square <- index *from-f, from-rank -547 *to-f <- put-index *to-f, to-rank, src -548 *from-f <- put-index *from-f, from-rank, 32/space -549 ] -550 -551 scenario making-a-move [ -552 local-scope -553 assume-screen 30/width, 12/height -554 board:board <- initial-position -555 move:&:move <- new move:type -556 *move <- merge 6/g, 1/'2', 6/g, 3/'4' -557 run [ -558 ¦ board <- make-move board, move -559 ¦ screen:&:screen <- print-board screen:&:screen, board -560 ] -561 screen-should-contain [ -562 # 012345678901234567890123456789 -563 ¦ .8 | r n b q k b n r . -564 ¦ .7 | p p p p p p p p . -565 ¦ .6 | . -566 ¦ .5 | . -567 ¦ .4 | P . -568 ¦ .3 | . -569 ¦ .2 | P P P P P P P . -570 ¦ .1 | R N B Q K B N R . -571 ¦ . +---------------- . -572 ¦ . a b c d e f g h . -573 ¦ . . -574 ] -575 ] +357 assume-screen 20/width, 2/height +358 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity +359 read-move-routine:num/routine <- start-running read-move, source, screen:&:screen +360 run [ +361 ¦ # 'read-move' is waiting for input +362 ¦ wait-for-routine-to-block read-move-routine +363 ¦ read-move-state:num <- routine-state read-move-routine +364 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued +365 ¦ assert waiting?, [ +366 F read-move-blocking: routine failed to pause after coming up (before any keys were pressed)] +367 ¦ # press 'a' +368 ¦ sink <- write sink, 97/a +369 ¦ restart read-move-routine +370 ¦ # 'read-move' still waiting for input +371 ¦ wait-for-routine-to-block read-move-routine +372 ¦ read-move-state <- routine-state read-move-routine +373 ¦ waiting? <- not-equal read-move-state, 2/discontinued +374 ¦ assert waiting?, [ +375 F read-move-blocking: routine failed to pause after rank 'a'] +376 ¦ # press '2' +377 ¦ sink <- write sink, 50/'2' +378 ¦ restart read-move-routine +379 ¦ # 'read-move' still waiting for input +380 ¦ wait-for-routine-to-block read-move-routine +381 ¦ read-move-state <- routine-state read-move-routine +382 ¦ waiting? <- not-equal read-move-state, 2/discontinued +383 ¦ assert waiting?, [ +384 F read-move-blocking: routine failed to pause after file 'a2'] +385 ¦ # press '-' +386 ¦ sink <- write sink, 45/'-' +387 ¦ restart read-move-routine +388 ¦ # 'read-move' still waiting for input +389 ¦ wait-for-routine-to-block read-move-routine +390 ¦ read-move-state <- routine-state read-move-routine +391 ¦ waiting? <- not-equal read-move-state, 2/discontinued +392 ¦ assert waiting?, [ +393 F read-move-blocking: routine failed to pause after hyphen 'a2-'] +394 ¦ # press 'a' +395 ¦ sink <- write sink, 97/a +396 ¦ restart read-move-routine +397 ¦ # 'read-move' still waiting for input +398 ¦ wait-for-routine-to-block read-move-routine +399 ¦ read-move-state <- routine-state read-move-routine +400 ¦ waiting? <- not-equal read-move-state, 2/discontinued +401 ¦ assert waiting?, [ +402 F read-move-blocking: routine failed to pause after rank 'a2-a'] +403 ¦ # press '4' +404 ¦ sink <- write sink, 52/'4' +405 ¦ restart read-move-routine +406 ¦ # 'read-move' still waiting for input +407 ¦ wait-for-routine-to-block read-move-routine +408 ¦ read-move-state <- routine-state read-move-routine +409 ¦ waiting? <- not-equal read-move-state, 2/discontinued +410 ¦ assert waiting?, [ +411 F read-move-blocking: routine failed to pause after file 'a2-a4'] +412 ¦ # press 'newline' +413 ¦ sink <- write sink, 10 # newline +414 ¦ restart read-move-routine +415 ¦ # 'read-move' now completes +416 ¦ wait-for-routine-to-block read-move-routine +417 ¦ read-move-state <- routine-state read-move-routine +418 ¦ completed?:bool <- equal read-move-state, 1/completed +419 ¦ assert completed?, [ +420 F read-move-blocking: routine failed to terminate on newline] +421 ¦ trace 1, [test], [reached end] +422 ] +423 trace-should-contain [ +424 ¦ test: reached end +425 ] +426 ] +427 +428 scenario read-move-quit [ +429 local-scope +430 assume-screen 20/width, 2/height +431 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity +432 read-move-routine:num <- start-running read-move, source, screen:&:screen +433 run [ +434 ¦ # 'read-move' is waiting for input +435 ¦ wait-for-routine-to-block read-move-routine +436 ¦ read-move-state:num <- routine-state read-move-routine +437 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued +438 ¦ assert waiting?, [ +439 F read-move-quit: routine failed to pause after coming up (before any keys were pressed)] +440 ¦ # press 'q' +441 ¦ sink <- write sink, 113/q +442 ¦ restart read-move-routine +443 ¦ # 'read-move' completes +444 ¦ wait-for-routine-to-block read-move-routine +445 ¦ read-move-state <- routine-state read-move-routine +446 ¦ completed?:bool <- equal read-move-state, 1/completed +447 ¦ assert completed?, [ +448 F read-move-quit: routine failed to terminate on 'q'] +449 ¦ trace 1, [test], [reached end] +450 ] +451 trace-should-contain [ +452 ¦ test: reached end +453 ] +454 ] +455 +456 scenario read-move-illegal-file [ +457 local-scope +458 assume-screen 20/width, 2/height +459 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity +460 read-move-routine:num <- start-running read-move, source, screen:&:screen +461 run [ +462 ¦ # 'read-move' is waiting for input +463 ¦ wait-for-routine-to-block read-move-routine +464 ¦ read-move-state:num <- routine-state read-move-routine +465 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued +466 ¦ assert waiting?, [ +467 F read-move-illegal-file: routine failed to pause after coming up (before any keys were pressed)] +468 ¦ sink <- write sink, 50/'2' +469 ¦ restart read-move-routine +470 ¦ wait-for-routine-to-block read-move-routine +471 ] +472 screen-should-contain [ +473 ¦ .file too low: 2 . +474 ¦ . . +475 ] +476 ] +477 +478 scenario read-move-illegal-rank [ +479 local-scope +480 assume-screen 20/width, 2/height +481 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity +482 read-move-routine:num <- start-running read-move, source, screen:&:screen +483 run [ +484 ¦ # 'read-move' is waiting for input +485 ¦ wait-for-routine-to-block read-move-routine +486 ¦ read-move-state:num <- routine-state read-move-routine +487 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued +488 ¦ assert waiting?, [ +489 F read-move-illegal-rank: routine failed to pause after coming up (before any keys were pressed)] +490 ¦ sink <- write sink, 97/a +491 ¦ sink <- write sink, 97/a +492 ¦ restart read-move-routine +493 ¦ wait-for-routine-to-block read-move-routine +494 ] +495 screen-should-contain [ +496 ¦ .rank too high: a . +497 ¦ . . +498 ] +499 ] +500 +501 scenario read-move-empty [ +502 local-scope +503 assume-screen 20/width, 2/height +504 source:&:source:char, sink:&:sink:char <- new-channel 2/capacity +505 read-move-routine:num <- start-running read-move, source, screen:&:screen +506 run [ +507 ¦ # 'read-move' is waiting for input +508 ¦ wait-for-routine-to-block read-move-routine +509 ¦ read-move-state:num <- routine-state read-move-routine +510 ¦ waiting?:bool <- not-equal read-move-state, 2/discontinued +511 ¦ assert waiting?, [ +512 F read-move-empty: routine failed to pause after coming up (before any keys were pressed)] +513 ¦ sink <- write sink, 10/newline +514 ¦ sink <- write sink, 97/a +515 ¦ restart read-move-routine +516 ¦ wait-for-routine-to-block read-move-routine +517 ] +518 screen-should-contain [ +519 ¦ .that's not enough . +520 ¦ . . +521 ] +522 ] +523 +524 def make-move board:board, m:&:move -> board:board [ +525 local-scope +526 load-ingredients +527 from-file:num <- get *m, from-file:offset +528 from-rank:num <- get *m, from-rank:offset +529 to-file:num <- get *m, to-file:offset +530 to-rank:num <- get *m, to-rank:offset +531 from-f:&:@:char <- index *board, from-file +532 to-f:&:@:char <- index *board, to-file +533 src:char/square <- index *from-f, from-rank +534 *to-f <- put-index *to-f, to-rank, src +535 *from-f <- put-index *from-f, from-rank, 32/space +536 ] +537 +538 scenario making-a-move [ +539 local-scope +540 assume-screen 30/width, 12/height +541 board:board <- initial-position +542 move:&:move <- new move:type +543 *move <- merge 6/g, 1/'2', 6/g, 3/'4' +544 run [ +545 ¦ board <- make-move board, move +546 ¦ screen:&:screen <- print-board screen:&:screen, board +547 ] +548 screen-should-contain [ +549 # 012345678901234567890123456789 +550 ¦ .8 | r n b q k b n r . +551 ¦ .7 | p p p p p p p p . +552 ¦ .6 | . +553 ¦ .5 | . +554 ¦ .4 | P . +555 ¦ .3 | . +556 ¦ .2 | P P P P P P P . +557 ¦ .1 | R N B Q K B N R . +558 ¦ . +---------------- . +559 ¦ . a b c d e f g h . +560 ¦ . . +561 ] +562 ] -- cgit 1.4.1-2-gfad0