24-game: fixing game to use formatting vocab
parent
6a76bf9084
commit
eeaffb14b8
|
@ -1,8 +1,7 @@
|
||||||
! Copyright © 2008 Reginald Keith Ford II
|
! Copyright © 2008 Reginald Keith Ford II
|
||||||
! 24, the Factor game!
|
! 24, the Factor game!
|
||||||
USING: accessors backtrack combinators continuations io kernel
|
USING: accessors backtrack combinators continuations formatting io
|
||||||
math math.parser prettyprint quotations random sequences shuffle
|
kernel math prettyprint quotations random sequences shuffle ;
|
||||||
;
|
|
||||||
IN: 24-game
|
IN: 24-game
|
||||||
|
|
||||||
: nop ( -- ) ;
|
: nop ( -- ) ;
|
||||||
|
@ -43,9 +42,9 @@ CONSTANT: (operators) { + - * / rot swap q }
|
||||||
[ name>> = ] with find nip ;
|
[ name>> = ] with find nip ;
|
||||||
|
|
||||||
: get-operator ( operators -- word )
|
: get-operator ( operators -- word )
|
||||||
"Operators: " write dup pprint nl flush
|
dup "Operators: %u\n" printf flush
|
||||||
readln over find-operator dup
|
readln over find-operator dup
|
||||||
[ "Command not found..." print get-operator ] unless nip ;
|
[ "Operator not found..." print get-operator ] unless nip ;
|
||||||
|
|
||||||
: try-operator ( array -- array )
|
: try-operator ( array -- array )
|
||||||
[ pprint nl ]
|
[ pprint nl ]
|
||||||
|
@ -53,10 +52,10 @@ CONSTANT: (operators) { + - * / rot swap q }
|
||||||
bi ;
|
bi ;
|
||||||
|
|
||||||
: end-game ( array -- )
|
: end-game ( array -- )
|
||||||
dup { 24 } = [
|
first dup 24 = [
|
||||||
drop "You WON!"
|
drop "You WON!"
|
||||||
] [
|
] [
|
||||||
first number>string " is not 24... You lose." append
|
"%d is not 24... You lose." sprintf
|
||||||
] if print ;
|
] if print ;
|
||||||
|
|
||||||
: quit-game ( array -- )
|
: quit-game ( array -- )
|
||||||
|
|
Loading…
Reference in New Issue