\ VP-hand
\ Player's hand
\ 
\ $Id: VP-hand.txt,v 1.1 2000/10/25 00:17:43 kris_johnson Exp $

\ Copyright 2000
\ Kristopher D. Johnson
\ 
\ See LICENSE-JacksOrBetter for the
\ conditions under which you may
\ use, redistribute, or modify this 
\ code, or create derived works.

docneeds VP-cards

.( VP-hand... )

\ Return address of nth element
\ of player's hand
: Hand ( n -- adr )
  cells [ g >hand ] literal + ;

0 Hand constant 0Hand
#Hand Hand constant LimHand

: HandBounds ( -- LimHand 0Hand )
  LimHand 0Hand ;

\ Print contents of Hand
: .Hand ( -- )
  0Hand .card
  LimHand [ 1 Hand ] literal do
    space i .card
  cell +loop
;

\ Return address of flag indicating
\ whether player wants to keep
\ specified card of hand
: HandHold ( n -- adr )
  cells [ g >hold ] literal + ;

0 HandHold constant 0HandHold

#Hand HandHold
constant LimHandHold

: HandHoldBounds ( -- LimHandHold 0HandHold )
  LimHandHold 0HandHold ;

\ Print contents of HandHold
: .HandHold ( -- )
  HandHoldBounds do
    i @ .
  cell +loop
;

: hold? ( n -- f )
  HandHold @ ;

\ Return true if all cards in hand
\ are being held
: all-held? ( -- f )
  HandHoldBounds do
    i @ not if
      unloop false exit
    then
  cell +loop
  true
;

: hold ( n --  )
  HandHold 1 swap ! ;

: -hold ( n --  )
  HandHold 0 swap ! ;

: zero-Hand ( -- )
  0Hand
  [ LimHand 0Hand - ] literal
  0 fill
;

: zero-HandHold ( -- )
  0HandHold
  [ LimHandHold 0HandHold - ] literal
  0 fill
;

: init-hand ( -- )
  zero-Hand
  zero-HandHold
;

\ Deal a card to each element of
\ Hand that is not marked to be held
: deal-hand ( -- )
  #Hand 0 do
    i HandHold @ not if
      i Hand draw-card!
    then
  loop
;
