Trans
10/25/2008 11:48:00 PM
On Oct 25, 5:58=A0pm, Paul <pedra...@gmail.com> wrote:
> I am writing a blackjack simulator. =A0I have classes like Dealer,
> Player, Deck, and Play_Strategy. =A0Play_Strategy describes the strategy
> a player will use.
> The strategy basically says what a player should do (hit, stand, etc)
> depending on the cards they are dealt and the dealer's upcard.
>
> I created a new object for a basic strategy
> (basic.Play_Strategy.new). =A0Then I have a series of hashes that I have
> set as instance variables instantiated as new hashes (ex. @lookuptable
> =3D Hash.new).
>
> The idea is that player1 (player1 =3D Player.new) will look up their
> hand as the key in the basic.action hash. =A0Then it will lookup the
> correct action in another hash based on the dealer.upcard.
>
> Here is the structure of the hashes.
>
> basic.lookup5 =3D {2 =3D> "Hit",3 =3D> "Hit",4 =3D> "Hit",5 =3D> "Hit",6 =
=3D>
> "Hit",7 =3D> "Hit",8 =3D> "Hit",9 =3D> "Hit","T" =3D> "Hit","A" =3D> "Hit=
"}
> ...(removed the full list of arrays to shorten the post)...
> basic.lookupAA =3D {2 =3D> "Split",3 =3D> "Split",4 =3D> "Split",5 =3D> "=
Split",
> 6 =3D> "Split",7 =3D> "Split",8 =3D> "Split",9 =3D> "Split","T" =3D> "Spl=
it","A"
> =3D> "Split"}
>
> basic.action =3D {5 =3D> basic.lookup5[dealer.upcard],6 =3D>
> basic.lookup6[dealer.upcard],7 =3D> basic.lookup7[dealer.upcard],8=3D>
> basic.lookup8[dealer.upcard],
> =A09=3D> basic.lookup9[dealer.upcard],10=3D> basic.lookup10[dealer.upcard=
],
> 11 =3D> basic.lookup11[dealer.upcard],12=3D>
> basic.lookup12[dealer.upcard],
> =A013 =3D> basic.lookup13[dealer.upcard],14=3D>
> basic.lookup14[dealer.upcard],15 =3D> basic.lookup15[dealer.upcard],16
> =3D> basic.lookup16[dealer.upcard],
> =A017 =3D> basic.lookup17[dealer.upcard], 18 =3D>
> basic.lookup18[dealer.upcard], 19 =3D> basic.lookup19[dealer.upcard], 20
> =3D> basic.lookup20[dealer.upcard],
> =A021 =3D> basic.lookup21[dealer.upcard],"A2" =3D>
> basic.lookupA2[dealer.upcard],"A3" =3D>
> basic.lookupA3[dealer.upcard],"A4" =3D> basic.lookupA4[dealer.upcard],
> =A0"A5"=3D> basic.lookupA5[dealer.upcard], "A6"=3D>
> basic.lookupA6[dealer.upcard],"A7"=3D>
> basic.lookupA7[dealer.upcard],"A8" =3D> basic.lookupA8[dealer.upcard],
> =A0"A9"=3D> basic.lookupA9[dealer.upcard], "22" =3D>
> basic.lookup22[dealer.upcard],"33"=3D>
> basic.lookup33[dealer.upcard],"44" =3D> basic.lookup44[dealer.upcard],
> =A0"55" =3D> basic.lookup55[dealer.upcard], "66" =3D>
> basic.lookup66[dealer.upcard],"77" =3D>
> basic.lookup77[dealer.upcard],"88" =3D> basic.lookup88[dealer.upcard],
> =A0"99" =3D> basic.lookup99[dealer.upcard], "TT"=3D>
> basic.lookupTT[dealer.upcard], "AA"=3D> basic.lookupAA[dealer.upcard]}
>
> Here is what I get...
> puts "Player should #{basic.action[player1.hand.cards]}." #This is the
> problem! =A0It is as if player.1.hand.cards is an empty array. =A0I get
> "nil".
>
> I ran some basic testing by seeing if other variables work, and they
> do as follows:
>
> puts player1.hand.inspect # returns an array of two cards. =A0As
> expected.
If player1.hand is an array, why do you think player1.hand.cards will
return anything at all?
t