# 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. chessboard 0/screen, 0/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 [ trace-until 100/app # we'll make the screen really wide because the program currently prints out a long line assume-screen 120/width, 20/height # initialize keyboard to type in a move assume-console [ type [a2-a4 ] ] run [ screen:address:shared:screen, console:address:shared:console <- chessboard screen:address:shared:screen, console:address:shared:console # icon for the cursor screen <- print screen, 9251/␣ ] 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 . . +---------------- . . a b c d e f g h . . . .Type in your move as -. For example: 'a2-a4'. Then press . . . . .Hit 'q' to exit. . . . .move: ␣ . .
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: package ranger.ext</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.ext</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/work/ranger/ranger/ext/__init__.py">/home/hut/work/ranger/ranger/ext/__init__.py</a></font></td></tr></table>
    <p><tt>This&nbsp;package&nbsp;includes&nbsp;extensions&nbsp;with&nbsp;broader&nbsp;usability</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Package Contents</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="ranger.ext.accumulator.html">accumulator</a><br>
<a href="ranger.ext.debug.html">debug</a><br>
</td><td width="25%" valign=top><a href="ranger.ext.get_all_modules.html">get_all_modules</a><br>
<a href="ranger.ext.human_readable.html">human_readable</a><br>
</td><td width="25%" valign=top><a href="ranger.ext.openstruct.html">openstruct</a><br>
<a href="ranger.ext.relpath.html">relpath</a><br>
</td><td width="25%" valign=top><a href="ranger.ext.shutil_generatorized.html">shutil_generatorized</a><br>
<a href="ranger.ext.waitpid_no_intr.html">waitpid_no_intr</a><br>
</td></tr></table></td></tr></table>
</body></html>
un [ 2:address:shared:array:address:shared:array:character/board <- initial-position 3:address:shared:move <- new move:type 4:address:number <- get-address *3:address:shared:move, from-file:offset *4:address:number <- copy 6/g 5:address:number <- get-address *3:address:shared:move, from-rank:offset *5:address:number <- copy 1/'2' 6:address:number <- get-address *3:address:shared:move, to-file:offset *6:address:number <- copy 6/g 7:address:number <- get-address *3:address:shared:move, to-rank:offset *7:address:number <- copy 3/'4' 2:address:shared:array:address:shared:array:character/board <- make-move 2:address:shared:array:address:shared:array:character/board, 3:address:shared:move screen:address:shared:screen <- print-board screen:address:shared:screen, 2:address:shared:array:address:shared:array:character/board ] screen-should-contain [ # 012345678901234567890123456789 .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 . . +---------------- . . a b c d e f g h . . . ] ]