-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtkcube.c
1862 lines (1567 loc) · 61.6 KB
/
gtkcube.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2002-2003 Joern Thyssen <jthyssen@dk.ibm.com>
* Copyright (C) 2021 Aaron Tikuisis and Isaac Keslassy (MoneyEval)
* Copyright (C) 2002-2023 the AUTHORS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* $Id: gtkcube.c,v 1.107 2023/03/07 22:29:54 plm Exp $
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "backgammon.h"
#include "eval.h"
#include "export.h"
#include "rollout.h"
#include "gtkgame.h"
#include "gtkcube.h"
#include "gtkwindows.h"
#include "progress.h"
#include "format.h"
#include "gtklocdefs.h"
// -------------------------------------------------------------------------
// new functionality with a button performing an Eval in Money Play |
// (i.e. hypothetical eval independent of score) |
// -------------------------------------------------------------------------
/* Notes:
- One minor problem is left: When running a rollout in MoneyEval, the "JSDs" column displays "NaN"
*/
typedef struct {
GtkWidget *pwFrame; /* the table */
GtkWidget *pw; /* the box */
GtkWidget *pwTools; /* the tools */
moverecord *pmr;
matchstate ms;
int did_double;
int did_take;
int hist;
GtkWidget *pwMWC; // Remember the pwMWC and pwCmark buttons because they should be deactivated during money eval
GtkWidget *pwCmark;
int evalAtMoney; // Whether evalAtMoney is toggled
} cubehintdata;
// These two variables are extern, and used for the temperature map when the MoneyEval button is toggled on.
// The temperature map can then provide an eval at money play rather than at the current score
// The second variable determines whether to use a Jacoby rule or not
int cubeTempMapAtMoney = 0;
int cubeTempMapJacoby = 0;
// Text to display when using MoneyEval
static const char *MONEY_EVAL_TEXT=N_("(Hypothetical money game)");
// here we can set an initial default preference for Jacoby -- else we use the system preference fJacoby
#define UNDEF (-1000) // Different from TRUE
static int moneyEvalJacoby=UNDEF;
static void
EvalCube(cubehintdata * pchd, const evalcontext * pec);
static void
JacobyToggled(GtkWidget *pwJ, cubehintdata *pchd)
{
/* This is called by gtk when the user clicks on the Jacoby check button during money eval.
If the Jacoby setting is changed, it reruns the EvalCube()
*/
g_assert(pchd->evalAtMoney);
if (moneyEvalJacoby!=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pwJ)) ) {
moneyEvalJacoby = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pwJ));
EvalCube(pchd, &GetEvalCube()->ec);
}
}
static GtkWidget *
OutputPercentsTable(const float ar[])
{
/* Creates the table showing win% etc. */
#if GTK_CHECK_VERSION(3,0,0)
GtkWidget *pwGrid;
#else
GtkWidget *pwTable;
#endif
GtkWidget *pw;
int i;
static gchar *headings[] = { N_("Win"), N_("W(g)"), N_("W(bg)"),
"-", N_("Lose"), N_("L(g)"), N_("L(bg)")
};
#if GTK_CHECK_VERSION(3,0,0)
pwGrid = gtk_grid_new();
#else
pwTable = gtk_table_new(2, 7, FALSE);
#endif
for (i = 0; i < 7; i++) {
pw = gtk_label_new(gettext(headings[i]));
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, i, 0, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 2);
gtk_widget_set_margin_end(pw, 2);
#else
gtk_widget_set_margin_left(pw, 2);
gtk_widget_set_margin_right(pw, 2);
#endif
#else
gtk_table_attach(GTK_TABLE(pwTable), pw, i, i + 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0);
#endif
}
pw = gtk_label_new(OutputPercent(ar[OUTPUT_WIN]));
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, 1, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 2);
gtk_widget_set_margin_end(pw, 2);
#else
gtk_widget_set_margin_left(pw, 2);
gtk_widget_set_margin_right(pw, 2);
#endif
#else
gtk_table_attach(GTK_TABLE(pwTable), pw, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0);
#endif
pw = gtk_label_new(OutputPercent(ar[OUTPUT_WINGAMMON]));
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 1, 1, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 2);
gtk_widget_set_margin_end(pw, 2);
#else
gtk_widget_set_margin_left(pw, 2);
gtk_widget_set_margin_right(pw, 2);
#endif
#else
gtk_table_attach(GTK_TABLE(pwTable), pw, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0);
#endif
pw = gtk_label_new(OutputPercent(ar[OUTPUT_WINBACKGAMMON]));
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 2, 1, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 2);
gtk_widget_set_margin_end(pw, 2);
#else
gtk_widget_set_margin_left(pw, 2);
gtk_widget_set_margin_right(pw, 2);
#endif
#else
gtk_table_attach(GTK_TABLE(pwTable), pw, 2, 3, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0);
#endif
pw = gtk_label_new(" - ");
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 3, 1, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 2);
gtk_widget_set_margin_end(pw, 2);
#else
gtk_widget_set_margin_left(pw, 2);
gtk_widget_set_margin_right(pw, 2);
#endif
#else
gtk_table_attach(GTK_TABLE(pwTable), pw, 3, 4, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0);
#endif
pw = gtk_label_new(OutputPercent(1.0f - ar[OUTPUT_WIN]));
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 4, 1, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 2);
gtk_widget_set_margin_end(pw, 2);
#else
gtk_widget_set_margin_left(pw, 2);
gtk_widget_set_margin_right(pw, 2);
#endif
#else
gtk_table_attach(GTK_TABLE(pwTable), pw, 4, 5, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0);
#endif
pw = gtk_label_new(OutputPercent(ar[OUTPUT_LOSEGAMMON]));
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 5, 1, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 2);
gtk_widget_set_margin_end(pw, 2);
#else
gtk_widget_set_margin_left(pw, 2);
gtk_widget_set_margin_right(pw, 2);
#endif
#else
gtk_table_attach(GTK_TABLE(pwTable), pw, 5, 6, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0);
#endif
pw = gtk_label_new(OutputPercent(ar[OUTPUT_LOSEBACKGAMMON]));
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 6, 1, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 2);
gtk_widget_set_margin_end(pw, 2);
#else
gtk_widget_set_margin_left(pw, 2);
gtk_widget_set_margin_right(pw, 2);
#endif
#else
gtk_table_attach(GTK_TABLE(pwTable), pw, 6, 7, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0);
#endif
#if GTK_CHECK_VERSION(3,0,0)
return pwGrid;
#else
return pwTable;
#endif
}
static void
GetMoneyCubeInfo(cubeinfo * pci, const matchstate * pms) {
/* Fills pci with cube info for a money game, i.e., same as given match state except with nMatchTo=0. */
matchstate moneyms = *pms; // Copy
moneyms.nMatchTo=0;
moneyms.fJacoby=moneyEvalJacoby;
GetMatchStateCubeInfo(pci, &moneyms);
}
// this function is used for the beavers in money play for example, and
// for the take decision frame; see the next CubeAnalysis function for
// explanations, as the two functions are very similar
static GtkWidget *
TakeAnalysis(cubehintdata * pchd)
{
cubeinfo ci;
GtkWidget *pw;
#if GTK_CHECK_VERSION(3,0,0)
GtkWidget *pwGrid;
#else
GtkWidget *pwTable;
#endif
GtkWidget *pwFrame;
int iRow;
int i;
cubedecision cd;
int ai[2];
const char *aszCube[] = {
NULL, NULL,
N_("Take"),
N_("Pass")
};
float arDouble[4];
gchar *sz;
cubedecisiondata *cdec = (pchd->evalAtMoney ? pchd->pmr->MoneyCubeDecPtr : pchd->pmr->CubeDecPtr);
const evalsetup *pes = &cdec->esDouble;
if (pes->et == EVAL_NONE)
return NULL;
if (!pchd->evalAtMoney)
GetMatchStateCubeInfo(&ci, &pchd->ms);
else
GetMoneyCubeInfo(&ci, &pchd->ms);
cd = FindCubeDecision(arDouble, cdec->aarOutput, &ci);
/* header */
sz = g_strdup_printf("%s %s", _("Take analysis"), pchd->evalAtMoney ? Q_(MONEY_EVAL_TEXT) : "");
pwFrame = gtk_frame_new(sz);
g_free(sz);
gtk_container_set_border_width(GTK_CONTAINER(pwFrame), 8);
#if GTK_CHECK_VERSION(3,0,0)
pwGrid = gtk_grid_new();
gtk_container_add(GTK_CONTAINER(pwFrame), pwGrid);
#else
pwTable = gtk_table_new(6, 4, FALSE);
gtk_container_add(GTK_CONTAINER(pwFrame), pwTable);
#endif
/* if EVAL_EVAL include cubeless equity and winning percentages */
iRow = 0;
InvertEvaluationR(cdec->aarOutput[0], &ci);
InvertEvaluationR(cdec->aarOutput[1], &ci);
switch (pes->et) {
case EVAL_EVAL:
if (ci.nMatchTo)
sz = g_strdup_printf(_("Cubeless %d-ply %s: %s (Money: %s)"),
pes->ec.nPlies,
fOutputMWC ? _("MWC") : _("equity"),
OutputEquity(cdec->aarOutput[0][OUTPUT_EQUITY],
&ci, TRUE),
OutputMoneyEquity(cdec->aarOutput[0], TRUE));
else
sz = g_strdup_printf(_("Cubeless %d-ply equity: %s"),
pes->ec.nPlies, OutputMoneyEquity(cdec->aarOutput[0], TRUE));
break;
case EVAL_ROLLOUT:
if (ci.nMatchTo)
sz = g_strdup_printf(_("Cubeless rollout %s: %s (Money: %s)"),
fOutputMWC ? _("MWC") : _("equity"),
OutputEquity(cdec->aarOutput[0][OUTPUT_EQUITY],
&ci, TRUE),
OutputMoneyEquity(cdec->aarOutput[0], TRUE));
else
sz = g_strdup_printf(_("Cubeless rollout equity: %s"), OutputMoneyEquity(cdec->aarOutput[0], TRUE));
break;
default:
sz = g_strdup("");
}
pw = gtk_label_new(sz);
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 4, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_table_attach(GTK_TABLE(pwTable), pw, 0, 4, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
#endif
g_free(sz);
iRow++;
/* winning percentages */
switch (pes->et) {
case EVAL_EVAL:
pw = OutputPercentsTable(cdec->aarOutput[0]);
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 4, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
gtk_widget_set_margin_top(pw, 4);
gtk_widget_set_margin_bottom(pw, 4);
#else
gtk_table_attach(GTK_TABLE(pwTable), pw,
0, 4, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 4);
#endif
iRow++;
break;
case EVAL_ROLLOUT:
pw = OutputPercentsTable(cdec->aarOutput[1]);
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 4, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
gtk_widget_set_margin_top(pw, 4);
gtk_widget_set_margin_bottom(pw, 4);
#else
gtk_table_attach(GTK_TABLE(pwTable), pw,
0, 4, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 4);
#endif
iRow++;
break;
default:
g_assert_not_reached();
}
InvertEvaluationR(cdec->aarOutput[0], &ci);
InvertEvaluationR(cdec->aarOutput[1], &ci);
/* sub-header */
pw = gtk_label_new(_("Cubeful equities:"));
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 4, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
gtk_widget_set_margin_top(pw, 4);
gtk_widget_set_margin_bottom(pw, 4);
#else
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw, 0, 4, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 4);
#endif
iRow++;
/* ordered take actions with equities */
if (arDouble[OUTPUT_TAKE] < arDouble[OUTPUT_DROP]) {
ai[0] = OUTPUT_TAKE;
ai[1] = OUTPUT_DROP;
} else {
ai[0] = OUTPUT_DROP;
ai[1] = OUTPUT_TAKE;
}
for (i = 0; i < 2; i++) {
/* numbering */
sz = g_strdup_printf("%d.", i + 1);
pw = gtk_label_new(sz);
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw,
0, 1, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
#endif
g_free(sz);
/* label */
pw = gtk_label_new(gettext(aszCube[ai[i]]));
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 1, iRow, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw,
1, 2, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
#endif
/* equity */
if (!ci.nMatchTo || !fOutputMWC)
sz = g_strdup_printf("%+7.3f", -arDouble[ai[i]]);
else
sz = g_strdup_printf("%7.3f%%", 100.0f * (1.0f - eq2mwc(arDouble[ai[i]], &ci)));
pw = gtk_label_new(sz);
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_END);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 2, iRow, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_misc_set_alignment(GTK_MISC(pw), 1, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw,
2, 3, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
#endif
g_free(sz);
/* difference */
if (i) {
if (!ci.nMatchTo || !fOutputMWC)
sz = g_strdup_printf("%+7.3f", arDouble[ai[0]] - arDouble[ai[i]]);
else
sz = g_strdup_printf("%+7.3f%%",
100.0f * eq2mwc(arDouble[ai[0]], &ci) - 100.0f * eq2mwc(arDouble[ai[i]], &ci));
pw = gtk_label_new(sz);
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_END);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 3, iRow, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_misc_set_alignment(GTK_MISC(pw), 1, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw,
3, 4, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
#endif
g_free(sz);
}
iRow++;
}
/* proper cube action */
pw = gtk_label_new(_("Correct response: "));
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 2, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
gtk_widget_set_margin_top(pw, 8);
gtk_widget_set_margin_bottom(pw, 8);
#else
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw, 0, 2, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 8);
#endif
switch (cd) {
case DOUBLE_TAKE:
case NODOUBLE_TAKE:
case TOOGOOD_TAKE:
case REDOUBLE_TAKE:
case NO_REDOUBLE_TAKE:
case TOOGOODRE_TAKE:
case NODOUBLE_DEADCUBE:
case NO_REDOUBLE_DEADCUBE:
case OPTIONAL_DOUBLE_TAKE:
case OPTIONAL_REDOUBLE_TAKE:
pw = gtk_label_new(_("Take"));
break;
case DOUBLE_PASS:
case TOOGOOD_PASS:
case REDOUBLE_PASS:
case TOOGOODRE_PASS:
case OPTIONAL_DOUBLE_PASS:
case OPTIONAL_REDOUBLE_PASS:
pw = gtk_label_new(_("Pass"));
break;
case DOUBLE_BEAVER:
case NODOUBLE_BEAVER:
case NO_REDOUBLE_BEAVER:
case OPTIONAL_DOUBLE_BEAVER:
pw = gtk_label_new(_("Beaver!"));
break;
case NOT_AVAILABLE:
pw = gtk_label_new(_("Eat it!"));
break;
}
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 2, iRow, 2, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
gtk_widget_set_margin_top(pw, 8);
gtk_widget_set_margin_bottom(pw, 8);
#else
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw, 2, 4, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 8);
#endif
iRow++;
/* Jacoby rule */
if (pchd->ms.nMatchTo && pchd->evalAtMoney) {
GtkWidget *pwJ = gtk_check_button_new_with_label(_("Jacoby"));
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pwJ, 0, iRow, 2, 1);
gtk_widget_set_hexpand(pwJ, TRUE);
gtk_widget_set_vexpand(pwJ, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pwJ, 8);
gtk_widget_set_margin_end(pwJ, 8);
#else
gtk_widget_set_margin_left(pwJ, 8);
gtk_widget_set_margin_right(pwJ, 8);
#endif
gtk_widget_set_margin_top(pwJ, 8);
gtk_widget_set_margin_bottom(pwJ, 8);
#else
gtk_table_attach(GTK_TABLE(pwTable), pwJ, 0, 2, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 8);
#endif
g_signal_connect(G_OBJECT (pwJ), "toggled", G_CALLBACK(JacobyToggled), pchd);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pwJ), moneyEvalJacoby);
gtk_widget_set_tooltip_text(pwJ, _("Toggle Jacoby rule for money play"));
// gtk_widget_set_sensitive(pwJ, !pchd->ms.nMatchTo && pchd->pmr->evalAtMoney);
}
return pwFrame;
}
/*
* Make cube analysis widget. Used for doubling decisions.
*
* Input:
* aarOutput, aarStdDev: evaluations
* pes: evaluation setup
*
* Returns:
* nice and pretty widget with cube analysis
*
*/
static GtkWidget *
CubeAnalysis(cubehintdata * pchd)
{
cubeinfo ci;
GtkWidget *pw;
#if GTK_CHECK_VERSION(3,0,0)
GtkWidget *pwGrid;
#else
GtkWidget *pwTable;
#endif
GtkWidget *pwFrame;
int iRow;
int i;
cubedecision cd;
float r;
int ai[3];
const char *aszCube[] = {
NULL,
N_("No double"),
N_("Double, take"),
N_("Double, pass")
};
float arDouble[4];
gchar *sz;
cubedecisiondata *cdec = (pchd->evalAtMoney ? pchd->pmr->MoneyCubeDecPtr : pchd->pmr->CubeDecPtr);
const evalsetup *pes = &cdec->esDouble;
if (pes->et == EVAL_NONE)
return NULL;
if (!pchd->evalAtMoney)
GetMatchStateCubeInfo(&ci, &pchd->ms);
else
GetMoneyCubeInfo(&ci, &pchd->ms);
// FindCubeDecision(arDouble, aarOutput, pci) is defined in eval.c:
// extern cubedecision FindCubeDecision(float arDouble[], float aarOutput[][NUM_ROLLOUT_OUTPUTS], const cubeinfo * pci)
// cubedecision is from eval.h: "DOUBLE_TAKE", "DOUBLE_PASS", etc.
// It calls FindBestCubeDecision, which calculates the optimal cube decision and equity/mwc for this.
// *
// * Input:
// * arDouble - array with equities or mwc's:
// * arDouble[ 1 ]: no double,
// * arDouble[ 2 ]: double take
// * arDouble[ 3 ]: double pass
// * pci - pointer to cube info
// *
// * Output:
// * arDouble - array with equities or mwc's
// * arDouble[ 0 ]: equity for optimal cube decision
// *
// * Returns:
// * cube decision
// Namely, the function takes aarOutput to get the 3 equities of ND,DT and DP,
// (eg from aarOutput[5,6])
// then converts into mwc (when NMatchTo!=0) then stores them in arDouble[1,2,3]
// and stores the best in arDouble[0]
//reminder: typedef struct _cubedecisiondata {float aarOutput[2][NUM_ROLLOUT_OUTPUTS]; float aarStdDev[2][NUM_ROLLOUT_OUTPUTS];
// evalsetup esDouble; CMark cmark; } cubedecisiondata;
cd = FindCubeDecision(arDouble, cdec->aarOutput, &ci);
if (!GetDPEq(NULL, NULL, &ci) && !(pchd->pmr->mt == MOVE_DOUBLE))
/* No cube action possible */
return NULL;
/* header */
sz = g_strdup_printf("%s %s", _("Cube analysis"), pchd->evalAtMoney ? Q_(MONEY_EVAL_TEXT) : "");
pwFrame = gtk_frame_new(sz);
g_free(sz);
gtk_container_set_border_width(GTK_CONTAINER(pwFrame), 8);
#if GTK_CHECK_VERSION(3,0,0)
pw = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
#else
pw = gtk_vbox_new(FALSE, 0);
#endif
gtk_container_add(GTK_CONTAINER(pwFrame), pw);
#if GTK_CHECK_VERSION(3,0,0)
pwGrid = gtk_grid_new();
gtk_box_pack_start(GTK_BOX(pw), pwGrid, FALSE, FALSE, 0);
#else
pwTable = gtk_table_new(8, 4, FALSE);
gtk_box_pack_start(GTK_BOX(pw), pwTable, FALSE, FALSE, 0);
#endif
iRow = 0;
/* cubeless equity */
/* Define first row of text (in sz) */
switch (pes->et) {
case EVAL_EVAL:
if (ci.nMatchTo)
{
// OutputEquity: in format.c:
// extern char * OutputEquity(const float r, const cubeinfo * pci, const int f)
sz = g_strdup_printf(_("Cubeless %d-ply %s: %s (Money: %s)"),
pes->ec.nPlies,
fOutputMWC ? _("MWC") : _("equity"),
OutputEquity(cdec->aarOutput[0][OUTPUT_EQUITY],
&ci, TRUE),
OutputMoneyEquity(cdec->aarOutput[0], TRUE));
} else
sz = g_strdup_printf(_("Cubeless %d-ply equity: %s"),
pes->ec.nPlies, OutputMoneyEquity(cdec->aarOutput[0], TRUE));
break;
case EVAL_ROLLOUT:
if (ci.nMatchTo)
sz = g_strdup_printf(_("Cubeless rollout %s: %s (Money: %s)"),
fOutputMWC ? _("MWC") : _("equity"),
OutputEquity(cdec->aarOutput[0][OUTPUT_EQUITY],
&ci, TRUE),
OutputMoneyEquity(cdec->aarOutput[0], TRUE));
else
sz = g_strdup_printf(_("Cubeless rollout equity: %s"), OutputMoneyEquity(cdec->aarOutput[0], TRUE));
break;
default:
sz = g_strdup("");
}
pw = gtk_label_new(sz);
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 4, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw, 0, 4, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
#endif
g_free(sz);
iRow++;
/* if EVAL_EVAL include cubeless equity and winning percentages */
if (pes->et == EVAL_EVAL) {
pw = OutputPercentsTable(cdec->aarOutput[0]);
#if GTK_CHECK_VERSION(3,0,0)
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 4, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
gtk_widget_set_margin_top(pw, 4);
gtk_widget_set_margin_bottom(pw, 4);
#else
gtk_table_attach(GTK_TABLE(pwTable), pw,
0, 4, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 4);
#endif
iRow++;
}
pw = gtk_label_new(_("Cubeful equities:"));
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 4, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
gtk_widget_set_margin_top(pw, 4);
gtk_widget_set_margin_bottom(pw, 4);
#else
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw, 0, 4, iRow, iRow + 1, GTK_EXPAND |
GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 4);
#endif
iRow++;
getCubeDecisionOrdering(ai, arDouble, cdec->aarOutput, &ci);
for (i = 0; i < 3; i++) {
/* numbering */
sz = g_strdup_printf("%d.", i + 1);
pw = gtk_label_new(sz);
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 0, iRow, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw,
0, 1, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
#endif
g_free(sz);
/* label */
pw = gtk_label_new(gettext(aszCube[ai[i]]));
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_START);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 1, iRow, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_misc_set_alignment(GTK_MISC(pw), 0, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw,
1, 2, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
#endif
/* equity */
sz = OutputEquity(arDouble[ai[i]], &ci, TRUE);
pw = gtk_label_new(sz);
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_END);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 2, iRow, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_misc_set_alignment(GTK_MISC(pw), 1, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw,
2, 3, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
#endif
/* difference */
if (i)
{
pw = gtk_label_new(OutputEquityDiff(arDouble[ai[i]], arDouble[OUTPUT_OPTIMAL], &ci)); //function from format.c
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(pw, GTK_ALIGN_END);
gtk_widget_set_valign(pw, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(pwGrid), pw, 3, iRow, 1, 1);
gtk_widget_set_hexpand(pw, TRUE);
gtk_widget_set_vexpand(pw, TRUE);
#if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start(pw, 8);
gtk_widget_set_margin_end(pw, 8);
#else
gtk_widget_set_margin_left(pw, 8);
gtk_widget_set_margin_right(pw, 8);
#endif
#else
gtk_misc_set_alignment(GTK_MISC(pw), 1, 0.5);
gtk_table_attach(GTK_TABLE(pwTable), pw,
3, 4, iRow, iRow + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 0);
#endif
}