@@ -56,6 +56,21 @@ namespace lbj {
5656
5757Informed::Informed(Configuration &conf) : Player(conf) {
5858 // TODO: read conf
59+
60+ // TODO. move to reset
61+ decks = 1 ;
62+ remaining_cards = 52 *decks;
63+ for (int rank = 1 ; rank < 9 ; rank++) {
64+ remaining[rank] = 4 *decks;
65+ }
66+ // first 4 = 4 ranks (T,J,Q,K)
67+ // second 4 = 4 suits (H,S,C,D)
68+ remaining[10 ] = 4 *4 *decks;
69+
70+ if (decks != 0 ) {
71+ verbose = true ;
72+ }
73+
5974 return ;
6075}
6176
@@ -87,26 +102,7 @@ int Informed::play() {
87102 // -------------------------------------------------------
88103 // compute the expected values
89104 // -------------------------------------------------------
90- for (int i = 0 ; i < SIZE; i++) {
91- for (int j = 0 ; j < SIZE; j++) {
92- dealer_hard[i][j] = 0 ;
93- }
94- }
95- for (int i = 0 ; i < SIZE; i++) {
96- for (int j = 0 ; j < SIZE; j++) {
97- dealer_soft[i][j] = 0 ;
98- }
99- }
100- for (int i = 0 ; i < SIZE; i++) {
101- hard_stand[i] = -1 ;
102- soft_stand[i] = -1 ;
103- hard_hit[i] = -1 ;
104- soft_hit[i] = -1 ;
105- hard_double[i] = -2 ;
106- soft_double[i] = -2 ;
107- split[i] = -1 ;
108- }
109-
105+ init ();
110106 for (int i = 0 ; i < 8 ; i++) {
111107 dealer_bust_european_iteration ();
112108 }
@@ -139,6 +135,7 @@ int Informed::play() {
139135 break ;
140136
141137 case lbj::PlayerActionRequired::None:
138+ std::cout << " mongocho" << std::endl;
142139 // TODO: count cards!
143140 break ;
144141
@@ -148,58 +145,88 @@ int Informed::play() {
148145}
149146
150147
148+ void Informed::init (void ) {
149+ for (int i = 0 ; i < SIZE; i++) {
150+ for (int j = 0 ; j < SIZE; j++) {
151+ dealer_hard[i][j] = 0 ;
152+ }
153+ }
154+ for (int i = 0 ; i < SIZE; i++) {
155+ for (int j = 0 ; j < SIZE; j++) {
156+ dealer_soft[i][j] = 0 ;
157+ }
158+ }
159+ // assume everything is lost
160+ for (int i = 0 ; i < SIZE; i++) {
161+ hard_stand[i] = -1 ;
162+ soft_stand[i] = -1 ;
163+ hard_hit[i] = -1 ;
164+ soft_hit[i] = -1 ;
165+ hard_double[i] = -2 ;
166+ soft_double[i] = -2 ;
167+ split[i] = -1 ;
168+ }
169+ return ;
170+ }
171+
151172
152173
153- void Informed::dealer_bust_european_iteration (void )
154- {
155- // dealer's probability of getting a total equal to the first index starting from a total equal to the second
156- // double dealer_hard[SIZE][SIZE];
174+
175+ void Informed::dealer_bust_european_iteration (void ) {
176+ // dealer_hard[final][initial] stores the probability that the dealer will get
177+ // a total equal to the first (final) index given that
178+ // the current hand is equal to the second index (initial)
179+ // same thing for dealer_soft[][]
157180
158- // There's a 100% chance he will end up with a 17 because he's going to stop
181+ // if the dealer has a hard 17 he has to stand
182+ // therefore, the probability of getting a total equal to 17 given that he has 17 is one
159183 // and same thing with an 18 through a 21.
160- // With the soft hands, let's assume the rule that the dealer stands on a soft 17.
161- // TODO:
184+ // same for soft hands, and let's assume s17
185+ // TODO: h17
162186 for (int total = 17 ; total < 22 ; total++) {
163187 dealer_hard[total][total] = 1 ;
164188 dealer_soft[total][total] = 1 ;
165189 }
166190
167- // The dealer ends up with a hard 22 or more. There's a 100% chance he's going to bust.
191+ // if the dealer has hard 22 or more, chances of busting are 100%
168192 for (int total = 22 ; total < 32 ; total++) {
169193 dealer_hard[22 ][total] = 1 ;
170194 }
171195
172- for (int outcome = 17 ; outcome < 23 ; outcome++) {
173- for (int total = 16 ; total > 1 ; total--) {
196+ //
197+ for (int final_total = 17 ; final_total < 23 ; final_total++) {
198+ for (int initial = 16 ; initial > 1 ; initial--) {
199+ // the probability of getting final_total starting from initial_total is
200+ // the sum over n of the existing probabilities (initial+n)->final * chances of getting a card equal to n
174201 // TODO: real cards left
175- dealer_hard[outcome][total ] = 1.0 /13.0 *(dealer_hard[outcome][total +2 ]) +
176- 1.0 /13.0 *(dealer_hard[outcome][total +3 ]) +
177- 1.0 /13.0 *(dealer_hard[outcome][total +4 ]) +
178- 1.0 /13.0 *(dealer_hard[outcome][total +5 ]) +
179- 1.0 /13.0 *(dealer_hard[outcome][total +6 ]) +
180- 1.0 /13.0 *(dealer_hard[outcome][total +7 ]) +
181- 1.0 /13.0 *(dealer_hard[outcome][total +8 ]) +
182- 1.0 /13.0 *(dealer_hard[outcome][total +9 ]) +
183- 4.0 /13.0 *(dealer_hard[outcome][total +10 ]) +
184- 1.0 /13.0 *(dealer_soft[outcome][total +11 ]);
202+ dealer_hard[final_total][initial ] = 1.0 /13.0 *(dealer_hard[final_total][initial +2 ]) +
203+ 1.0 /13.0 *(dealer_hard[final_total][initial +3 ]) +
204+ 1.0 /13.0 *(dealer_hard[final_total][initial +4 ]) +
205+ 1.0 /13.0 *(dealer_hard[final_total][initial +5 ]) +
206+ 1.0 /13.0 *(dealer_hard[final_total][initial +6 ]) +
207+ 1.0 /13.0 *(dealer_hard[final_total][initial +7 ]) +
208+ 1.0 /13.0 *(dealer_hard[final_total][initial +8 ]) +
209+ 1.0 /13.0 *(dealer_hard[final_total][initial +9 ]) +
210+ 4.0 /13.0 *(dealer_hard[final_total][initial +10 ]) +
211+ 1.0 /13.0 *(dealer_soft[final_total][initial +11 ]);
185212 }
186213
187214 // With a soft 22, that's going to be the same thing as a hard 12.
188- for (int total = 31 ; total > 21 ; total --) {
189- dealer_soft[outcome][total ] = dealer_hard[outcome][total -10 ];
215+ for (int initial = 31 ; initial > 21 ; initial --) {
216+ dealer_soft[final_total][initial ] = dealer_hard[final_total][initial -10 ];
190217 }
191218
192- for (int total = 16 ; total > 11 ; total --) {
193- dealer_soft[outcome][total ] = 1.0 /13.0 *(dealer_soft[outcome][total +1 ]) +
194- 1.0 /13.0 *(dealer_soft[outcome][total +2 ]) +
195- 1.0 /13.0 *(dealer_soft[outcome][total +3 ]) +
196- 1.0 /13.0 *(dealer_soft[outcome][total +4 ]) +
197- 1.0 /13.0 *(dealer_soft[outcome][total +5 ]) +
198- 1.0 /13.0 *(dealer_soft[outcome][total +6 ]) +
199- 1.0 /13.0 *(dealer_soft[outcome][total +7 ]) +
200- 1.0 /13.0 *(dealer_soft[outcome][total +8 ]) +
201- 1.0 /13.0 *(dealer_soft[outcome][total +9 ]) +
202- 4.0 /13.0 *(dealer_soft[outcome][total +10 ]);
219+ for (int initial = 16 ; initial > 11 ; initial --) {
220+ dealer_soft[final_total][initial ] = 1.0 /13.0 *(dealer_soft[final_total][initial +1 ]) +
221+ 1.0 /13.0 *(dealer_soft[final_total][initial +2 ]) +
222+ 1.0 /13.0 *(dealer_soft[final_total][initial +3 ]) +
223+ 1.0 /13.0 *(dealer_soft[final_total][initial +4 ]) +
224+ 1.0 /13.0 *(dealer_soft[final_total][initial +5 ]) +
225+ 1.0 /13.0 *(dealer_soft[final_total][initial +6 ]) +
226+ 1.0 /13.0 *(dealer_soft[final_total][initial +7 ]) +
227+ 1.0 /13.0 *(dealer_soft[final_total][initial +8 ]) +
228+ 1.0 /13.0 *(dealer_soft[final_total][initial +9 ]) +
229+ 4.0 /13.0 *(dealer_soft[final_total][initial +10 ]);
203230 }
204231 }
205232
@@ -384,4 +411,133 @@ void Informed::pairs() {
384411
385412 return ;
386413}
414+
415+
416+ void Informed::info (lbj::Info msg, int p1, int p2) {
417+
418+ switch (msg) {
419+
420+ case lbj::Info::Shuffle:
421+ std::cout << " Shuffle" << std::endl;
422+ // TODO: reset()
423+
424+ remaining_cards = 52 *decks;
425+ for (int rank = 1 ; rank < 9 ; rank++) {
426+ remaining[rank] = 4 *decks;
427+ }
428+ // first 4 = 4 ranks (T,J,Q,K)
429+ // second 4 = 4 suits (H,S,C,D)
430+ remaining[10 ] = 4 *4 *decks;
431+
432+ break ;
433+
434+ case lbj::Info::NewHand:
435+ std::cout << " NewHand" << std::endl;
436+ break ;
437+
438+ case lbj::Info::BetInvalid:
439+ std::cout << " BetInvalid" << std::endl;
440+ break ;
441+
442+ case lbj::Info::CardPlayer:
443+ std::cout << " CardPlayer" << std::endl;
444+ remaining[p1]--;
445+ remaining_cards--;
446+ break ;
447+
448+ case lbj::Info::CardDealer:
449+ std::cout << " CardDealer" << std::endl;
450+ if (p1 > 0 ) {
451+ remaining[p1]--;
452+ remaining_cards--;
453+ }
454+ break ;
455+
456+ case lbj::Info::CardDealerRevealsHole:
457+ std::cout << " CardDealerRevealsHole" << std::endl;
458+ remaining[p1]--;
459+ remaining_cards--;
460+ break ;
461+
462+ case lbj::Info::DealerBlackjack:
463+ std::cout << " DealerBlackjack" << std::endl;
464+ break ;
465+
466+ case lbj::Info::PlayerWinsInsurance:
467+ std::cout << " PlayerWinsInsurance" << std::endl;
468+ break ;
469+
470+ case lbj::Info::PlayerBlackjackAlso:
471+ std::cout << " PlayerBlackjackAlso" << std::endl;
472+ break ;
473+
474+ case lbj::Info::PlayerSplitInvalid:
475+ std::cout << " PlayerSplitInvalid" << std::endl;
476+ break ;
477+
478+ case lbj::Info::PlayerSplitOk:
479+ std::cout << " PlayerSplitOk" << std::endl;
480+ break ;
481+
482+ case lbj::Info::PlayerSplitIds:
483+ std::cout << " PlayerSplitIds" << std::endl;
484+ break ;
485+
486+ case lbj::Info::PlayerDoubleInvalid:
487+ std::cout << " PlayerDoubleInvalid" << std::endl;
488+ break ;
489+
490+ case lbj::Info::PlayerNextHand:
491+ std::cout << " PlayerNextHand" << std::endl;
492+ break ;
493+
494+ case lbj::Info::PlayerPushes:
495+ std::cout << " PlayerPushes" << std::endl;
496+ break ;
497+
498+ case lbj::Info::PlayerLosses:
499+ std::cout << " PlayerLosses" << std::endl;
500+ break ;
501+ case lbj::Info::PlayerBlackjack:
502+ std::cout << " PlayerBlackjack" << std::endl;
503+ break ;
504+ case lbj::Info::PlayerWins:
505+ std::cout << " PlayerWins" << std::endl;
506+ break ;
507+
508+ case lbj::Info::NoBlackjacks:
509+ std::cout << " NoBlackjacks" << std::endl;
510+ break ;
511+
512+ case lbj::Info::DealerBusts:
513+ std::cout << " DealerBusts" << std::endl;
514+ break ;
515+
516+ case lbj::Info::Help:
517+ std::cout << " Help" << std::endl;
518+ break ;
519+
520+ case lbj::Info::Bankroll:
521+ std::cout << " Bankroll" << std::endl;
522+ break ;
523+
524+ case lbj::Info::CommandInvalid:
525+ std::cout << " CommandInvalid" << std::endl;
526+ break ;
527+
528+ case lbj::Info::Bye:
529+ std::cout << " Bye" << std::endl;
530+ break ;
531+
532+ case lbj::Info::None:
533+ break ;
534+
535+ }
536+
537+ return ;
538+ }
539+
387540}
541+
542+
543+
0 commit comments