( Problems, page 230 )

variable pies
0 pies !
: bake-pie   1 pies +! ;
: eat-pie   pies @ if -1 pies +! ." Thank you!" else
                     ." What pie?" then ;

variable frozen-pies
0 frozen-pies !
: freeze-pies   pies @ frozen-pies !
                0 pies ! ;


: .base   base @  decimal . ;


( I looked at the answer for problem 3, didn't know you could embed code between
  the <# #> tags!
)


create pencil-types 0 , 0 , 0 , 0 ,
: red 0 ; : blue 1 ; : green 2 ; : orange 3 ;
: pencils   8 * pencil-types + ;
( Usage: <val> <colour> pencils ! - sets the pencil colour value
         <colour> pencils ? - prints the pencil colour value
)


: stars   0 do 42 emit loop ;
create values  1 , 52 , 13 , 20 , 18 , 14 , 8 , 6 , 2 ,
: plot  9 0 do
          cr  i 1+ .  space  values i 8 * + @ stars
        loop ;


create board  1 allot
: reset   board 9 0 fill ;
: line    cr  9 0 do 45 emit loop  cr ;
: bar   ." | " ;
: sqr  board + ;
: .box  ( i -- )
  sqr c@  dup  0= if 2 spaces else
                    dup  1 = if ." X " else
                                ." O " then then drop ;
: show-board   ( adr -- )
  cr  9 0 do
    i if  i 3 mod 0= if line else bar then then
    i .box
  loop  cr quit ;
(                    v oops!! This is really important!! )
: x!  board + 1 swap c!  show-board ;
: o!  board + -1 swap c!  show-board ;

reset
