# Chessboard program: you type in moves in algebraic notation, and it'll # display the position after each move. # recipes are mu's names for functions recipe main [ open-console # take control of screen, keyboard and mouse # The chessboard recipe takes keyboard and screen objects as 'ingredients'. # # In mu it is good form (though not required) to explicitly show the # hardware you rely on. # # The chessboard also returns the same keyboard and screen objects. In mu it # is good form to not modify ingredients of a recipe unless they are also # results. Here we clearly modify both keyboard and screen, so we return # both. # # Here the console and screen are both 0, which usually indicates real # hardware rather than a fake for testing as you'll see below. 0:literal/screen, 0:literal/console <- chessboard 0:literal/screen, 0:literal/console close-console # cleanup screen, keyboard and mouse ] ## But enough about mu. Here's what it looks like to run the chessboard program. scenario print-board-and-read-move [ $close-trace # administrivia: most scenarios save and check traces, but this one gets too large/slow # we'll make the screen really wide because the program currently prints out a long line assume-screen 120:literal/width, 20:literal/height # initialize keyboard to type in a move assume-console [ type [a2-a4 ] ] run [ screen:address, console:address <- chessboard screen:address, console:address #? $browse-trace #? 1 #? $close-trace #? 1 # icon for the cursor screen:address <- print-character screen:address, 9251:literal # '␣' ] screen-should-contain [ # 1 2 3 4 5 6 7 8 9 10 11 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 .Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves. . . . .8 | r n b q k b n r . .7 | p p p p p p p p . .6 | . .5 | . .4 | P . .3 | . .2 | P P P P P P P . .1 | R N B Q K B N R . . +----------------
textfile.txt