Monday, April 25, 2011

Game Play Logic - ?playcard

In order to determine if a card is a "legal" move according to the rules of the Crazy 8s game, we developed this word, ?playcard. This word will place either true (-1) or false (0) on the stack.
: ?playcard
dup
13 mod 8 = if
drop ( drop dup )
true
else
discardpile
lastcard
dup
8 = if
getcardsuit
swap
getcardsuit
= if
true
else
false
then
else
2dup
13 mod
swap
13 mod
= if ( same rank/face )
drop drop ( drop 2dup )
true
else
getcardsuit
swap
getcardsuit
= if ( same suit )
true
else
false
then
then
then
then
;

No comments:

Post a Comment