\ LowDrawStrategies.4th -- compiles under any ANS Forth system 
\ written by Hugh Aguilar --- BSD license
\ These are the Strategy surrogates for LowDraw.4th

\ We need NOVICE.4TH and LowDraw.4th included.

decimal

marker LowDrawStrategies.4th


\ *********************************************************************************************************************
\ ************ These are some contrived hands 
\ *********************************************************************************************************************

: MalmuthOne  \ --
    0
    club    ace     Crunch
    club    three   Crunch
    spade   five    Crunch
    heart   nine    Crunch
    0
    diamond king    Crunch
                    CountContrived ;

: MalmuthTwo  \ --
    0
    club    ace     Crunch
    club    three   Crunch
    spade   five    Crunch
    0
    heart   nine    Crunch
    diamond king    Crunch
                    CountContrived ;

: SeeMalmuth  \ --
    club    ace     Crunch  SeeCard
    club    three   Crunch  SeeCard
    spade   five    Crunch  SeeCard
    heart   nine    Crunch  SeeCard
    diamond king    Crunch  SeeCard ;


\ *********************************************************************************************************************
\ ************ These are support routines for the strategies concerned with drawing cards 
\ *********************************************************************************************************************

item RiskyRank          \ RiskyRank is the highest rank that is acceptable to draw two cards to. 
item AcceptRank         \ AcceptRank is the highest rank that is acceptable; any rank greater is bad. 
item HedgyRank          \ HedgyRank is the highest rank that is acceptable to stand on.

item PairRank           \ this is the rank of the paired cards
item HighRank           \ for high_card, this is the highest rank before discarding, for the others, after discarding 
item UnderRank          \ rank under HighRank 
item ThirdRank          \ rank under UnderRank

\ *********************************************************************************************************************

: StandPat  \ cardA cardB cardC cardD cardE --
    ThirdRank UnderRank HighRank Count_high ;

\ If we have already stored HighRank etc. into the items, we need to put them back on the stack for Count_high.

: BigThreeDraw  \ cardX cardY cardZ cardA cardB high_rank risky_rank --
    to RiskyRank
    to HighRank
    HighRank RiskyRank <= if   ThreeDraw  exit then
    Count_folded ;

\ Draw three (risky_rank) cards to break quads or full_house.

: BigTwoDraw  \ cardX cardY cardZ cardA cardB high_rank risky_rank --
    to RiskyRank
    to HighRank
    HighRank RiskyRank <= if   TwoDraw  exit then
    Count_folded ;

\ Draw two (risky_rank) cards to break trips or two_pair.

: PairOneDraw  \ cardX cardY cardZ cardA cardB under_rank high_rank pair_rank accept_rank --
    to AcceptRank
    to PairRank  to HighRank  to UnderRank
    HighRank AcceptRank <= if  OneDraw  exit then
    Count_folded ;

\ Draw one (accept_rank) card to break pair.

: PairChooser  \ cardX cardY cardZ cardA cardB -- good good good bad bad
    PairRank HighRank <> if  rot  then ;    \ -- cardX cardY cardA cardB cardZ

\ If pair is high ranking, then discard both of pair; if high card not in pair, then discard it and one of pair.

: PairTwoDraw  \ cardX cardY cardZ cardA cardB under_rank high_rank pair_rank risky_rank accept_rank --
    to AcceptRank  to RiskyRank
    to PairRank  to HighRank  to UnderRank
    HighRank AcceptRank <= if  OneDraw  exit then
    UnderRank RiskyRank <= if  PairChooser TwoDraw  exit then
    Count_folded ;

\ Draw one (accept_rank) or two (risky_rank) cards to pair.

: HighOneDraw  \ cardA cardB cardC cardD cardE third_rank under_rank high_rank accept_rank hedgy_rank --
    to HedgyRank  to AcceptRank
    to HighRank  to UnderRank  to ThirdRank
    HighRank HedgyRank <= if  StandPat  exit then
    UnderRank AcceptRank <= if  OneDraw  exit then
    Count_folded ;

\ Draw zero (hedgy_rank) or one (accept_rank) cards to high hand.

: HighTwoDraw  \ cardA cardB cardC cardD cardE third_rank under_rank high_rank risky_rank accept_rank hedgy_rank --
    to HedgyRank  to AcceptRank  to RiskyRank
    to HighRank  to UnderRank  to ThirdRank
    HighRank HedgyRank <= if  StandPat  exit then
    UnderRank AcceptRank <= if  OneDraw  exit then
    ThirdRank RiskyRank <= if  TwoDraw  exit then
    Count_folded ;

\ Draw zero (hedgy_rank), one (accept_rank) or two (risky_rank) cards to high hand.


\ *********************************************************************************************************************
\ ************ These are Strategy surrogates. 
\ *********************************************************************************************************************

: PoetEighter  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                   drop                                Count_folded        exit then
    two_pair? if                drop                                Count_folded        exit then
    pair? if                                        eight           PairOneDraw         exit then
    high_card                                       eight   eight   HighOneDraw ;

\ This is the player who follows the advice in the "Lowball Rock" poem: 
\       Roses are red, violets are blue. 
\       Don't draw to an eight, and never draw two.

\ The "Lowball Rock" poem was developed for California Lowball, which provides better hands due to the joker. 
\ It is too conservative for standard LowDraw. In LowDraw the players can be more liberal about what hand they 
\ will go in with because they don't have to worry that an opponent has the joker giving him a killer hand.

: PoetNiner  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                   drop                                Count_folded        exit then
    two_pair? if                drop                                Count_folded        exit then
    pair? if                                        nine            PairOneDraw         exit then
    high_card                                       nine    nine    HighOneDraw ;

\ This is more liberal; we draw one card to get a nine high hand.

\ *********************************************************************************************************************
\ The following compare to PoetEighter.

: Eight-NineSlide  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                   drop                                Count_folded        exit then
    two_pair? if                drop                                Count_folded        exit then
    pair? if                                        eight           PairOneDraw         exit then
    high_card                                       eight   nine    HighOneDraw ;

\ This is more liberal; we let nine-high hands slide by (stand pat on them).

: SevenEight-NineSlide  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                        eight           PairOneDraw         exit then
    high_card                                       eight   nine    HighOneDraw ;

\ This is more liberal; we draw two cards to trips or two_pair, but with a stricter criteria.

: SixSevenEight-NineSlide  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                six     eight           PairTwoDraw         exit then
    high_card                                       eight   nine    HighOneDraw ;

\ This is more liberal; we draw two cards to a pair, but with a stricter criteria.

: FiveSixSevenEight-NineSlide  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                six     eight           PairTwoDraw         exit then
    high_card                               five    eight   nine    HighTwoDraw ;

\ This is more liberal; we draw two cards to a high hand, but with a stricter criteria.

: FiveSixSevenEight  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                six     eight           PairTwoDraw         exit then
    high_card                               five    eight   eight   HighTwoDraw ;

\ This folds the same percentage, but we don't let the nine-high hands slide.

: SixSixSevenEight  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                six     eight           PairTwoDraw         exit then
    high_card                               six     eight   eight   HighTwoDraw ;

\ This is more liberal; we draw two cards to a high hand with a looser criteria.

: DesperEighter  \ --
    quads? if                               eight                   BigThreeDraw        exit then
    full_house? if                          eight                   BigThreeDraw        exit then
    trips? if                               eight                   BigTwoDraw          exit then
    two_pair? if                            eight                   BigTwoDraw          exit then
    pair? if                                eight   eight           PairTwoDraw         exit then
    high_card                               eight   eight   eight   HighTwoDraw ;

\ This is a desperate attempt to get an eight-high hand.

: SixSevenSevenEight  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                seven   eight           PairTwoDraw         exit then
    high_card                               six     eight   eight   HighTwoDraw ;

\ This is more liberal; we draw two cards to a pair with a looser criteria.

: SixSevenSevenEight-NineSlide  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                seven   eight           PairTwoDraw         exit then
    high_card                               six     eight   nine    HighTwoDraw ;

\ This is more liberal; we let nine-high hands slide by.

: SevenEight-TenSlide  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                        eight           PairOneDraw         exit then
    high_card                                       eight   ten     HighOneDraw ;

\ This is more conservative; we let the tens slide by.

: SevenEight  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                        eight           PairOneDraw         exit then
    high_card                                       eight   eight   HighOneDraw ;

\ We don't let anything slide by.

: SevenNine-NineSlide  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                        nine            PairOneDraw         exit then
    high_card                                       nine    nine    HighOneDraw ;

\ This is more liberal; we draw one card to get a nine-high hand.

: SevenNine-TenSlide  \ --
    quads? if                   drop                                Count_folded        exit then
    full_house? if              drop                                Count_folded        exit then
    trips? if                               seven                   BigTwoDraw          exit then
    two_pair? if                            seven                   BigTwoDraw          exit then
    pair? if                                        nine            PairOneDraw         exit then
    high_card                                       nine    ten     HighOneDraw ;

\ This is more liberal; we let the tens slide by.