Paste: homework assignment - valid-bishop?
Author: | kobi |
Mode: | factor |
Date: | Sat, 3 Oct 2009 20:37:09 |
Plain Text |
MEMO: (col-number-hash) ( -- hashtable )
CHAR: a CHAR: h [a,b]
1 8 [a,b] zip >hashtable ;
: col>number ( letter -- number )
(col-number-hash) at ;
:: valid-incline? ( move-x current-x move-y current-y -- ? )
move-x current-x - :> dx
move-y col>number current-y col>number - :> dy
dy dx =
dy dx -1 * = or ;
:: inside-board? ( move-x move-y -- ? )
8 [1,b] move-x move-y col>number
[ swap member? ] bi-curry@ bi and ;
:: valid-bishop? ( current-x current-y move-x move-y -- ? )
{
[ move-x current-x = not ]
[ move-x move-y inside-board? ]
[ move-x current-x move-y current-y valid-incline? ]
} 0&& ;
New Annotation