-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.cpp
223 lines (175 loc) · 7.02 KB
/
Tests.cpp
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
#include "YahtzeeDistributions.cpp"
void test_make_choice()
{
int weights[252][32] = {0};
find_num_ways_get_superset_from_subset(weights);
bool available_options[14];
for (int i=1; i<14; i++) available_options[i] = (i == sixes || i==chance || i==yahtzee);
int roll[5] = {1,2,5,6,6};
//part 3 adjustment example
part_three_predicted_scores weights_part_3[13];
weights_part_3[sixes - 1].score_independent_from_freq = 12;
for (int i=2; i<4; i++)
weights_part_3[sixes - 1].freq_dependent_scores[i] = 35;
weights_part_3[yahtzee - 1].score_independent_from_freq = 23 + 10;
weights_part_3[chance - 1].score_independent_from_freq = 2 + 10;
CategoryInfo instance = CategoryInfo();
value_of_roll result = instance.make_choice(roll, weights_part_3, available_options, false, 0);
assert(result.option == 42); //zero in yahtzee
assert(fabs(result.value - 33) <= .001);
//now, we change 5 into six, and expect to take sixes
roll[2] = 6;
result = instance.make_choice(roll, weights_part_3, available_options, false, 0);
assert(result.option == sixes);
}
void test_get_distribution()
{
bool available_options[14];
for (int i=1; i<14; i++) available_options[i] = (i == sixes || i==chance || i==yahtzee);
part_three_predicted_scores weights_part_3[13];
weights_part_3[sixes - 1].score_independent_from_freq = 12;
for (int i=2; i<4; i++)
weights_part_3[sixes - 1].freq_dependent_scores[i] = 35;
weights_part_3[yahtzee - 1].score_independent_from_freq = 23 + 10;
weights_part_3[chance - 1].score_independent_from_freq = 2 + 10;
storing_considered_rolls_with_overall_value *decision_input = \
new storing_considered_rolls_with_overall_value[9331];
storing_considered_rolls_with_overall_value *decision_output = \
new storing_considered_rolls_with_overall_value[252];
storing_considered_rolls result = get_distribution_or_choice(available_options, 45, weights_part_3, decision_input, \
decision_output);
for (int i=0; i<NUM_OPTIONS; i++)
{
if (i == 24 || i == 31)
cout << "| ";
cout << result.Probabilities[i] << " ";
}
cout << endl;
for (int i=0; i<3; i++)
cout << result.sums[i] << " ";
cout << endl;
delete [] decision_input;
delete [] decision_output;
}
void test_get_distribution2()
{
//these are the actual adjustments from part 3 for distribution -4-k,-FH
double adjustments[13][5] =
{
{181.739, 1.69964, 3.40115, 5.14604, 6.82755},
{180.215, 3.13052, 6.56007, 10.1377, 13.3759},
{173.51, 4.00768, 9.08712, 14.541, 19.4759},
{167.936, 3.61435, 9.8799, 17.5729, 24.1774},
{164.181, 2.05778, 8.58621, 18.5807, 27.1642},
{161.888, 0.594032, 5.87712, 18.2263, 29.0429},
{172.017, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{161.351, 0, 0, 0, 0},
{166.521, 0, 0, 0, 0},
{180.489, 0, 0, 0, 0},
{165.929, 0, 0, 0, 0}
};
part_three_predicted_scores weights_part_3[13];
for (int i=0; i<13; i++)
{
weights_part_3[i].score_independent_from_freq = adjustments[i][0];
for (int j=0; j<4; j++)
weights_part_3[i].freq_dependent_scores[j] = adjustments[i][j+1];
}
bool available_options[14];
for (int i=1; i<14; i++) available_options[i] = (i != four_of_a_kind && i != full_house);
storing_considered_rolls_with_overall_value *decision_input = \
new storing_considered_rolls_with_overall_value[9331];
storing_considered_rolls_with_overall_value *decision_output = \
new storing_considered_rolls_with_overall_value[252];
storing_considered_rolls result = get_distribution_or_choice(available_options, 0, weights_part_3, decision_input, \
decision_output);
for (int i=0; i<NUM_OPTIONS; i++)
{
if (i == 24 || i == 31)
cout << "| ";
cout << result.Probabilities[i] << " ";
}
cout << endl;
for (int i=0; i<3; i++)
cout << result.sums[i] << " ";
cout << endl;
delete [] decision_input;
delete [] decision_output;
}
void test_adjustments()
{
bool available_options[14];
for (int i=1; i<14; i++) available_options[i] = (i != four_of_a_kind && i != full_house);
int num_rounds_left = 0;
for (int i=1; i<14; i++)
if (available_options[i])
num_rounds_left ++;
int initial_upper_score = 0;
for (int i=1; i<=6; i++)
if (!available_options[i])
initial_upper_score += 3 * i;
if (num_rounds_left > 1)
{
Beynesian_Computation computer = Beynesian_Computation(&get_distribution_or_choice, \
available_options, initial_upper_score);
computer.compute_beynesian_expected_values();
for (int i=0; i<13; i++)
print_ele_part_three_arr(computer.get_curr_base_index(), i);
for (int i=0; i<8192; i++)
{
free(find_redundency[i]);
find_redundency[i] = NULL;
}
}
}
void test_intermed_choice()
{
//uses actual adjustments
bool available_options[14];
for (int i=1; i<14; i++) available_options[i] = (i == fives || i==chance || i==yahtzee);
part_three_predicted_scores weights_part_3[13];
weights_part_3[fives - 1].score_independent_from_freq = 27.2598;
for (int i=2; i<4; i++)
weights_part_3[fives - 1].freq_dependent_scores[i] = 35;
weights_part_3[yahtzee - 1].score_independent_from_freq = 53.9569;
weights_part_3[chance - 1].score_independent_from_freq = 34.3179;
storing_considered_rolls_with_overall_value *decision_input = \
new storing_considered_rolls_with_overall_value[9331];
storing_considered_rolls_with_overall_value *decision_output = \
new storing_considered_rolls_with_overall_value[252];
vector<vector<int>> supersets = get_supersets();
get_distribution_or_choice(available_options, 48, weights_part_3, decision_input, \
decision_output, 1);
vector<int> sample_rolls = {2,5,5,6,6};
vector<int> expected_choice = {5,5};
int superset_index = find(supersets.begin(), supersets.end(), sample_rolls) - supersets.begin();
int subset_index = get_index(expected_choice);
//if the choice is 5,5, as expecting,
// then expect that decision_output[superset index].value equals decision_input[subset_index].value
assert(abs(decision_input[subset_index].value - decision_output[superset_index].value) <= .001);
vector<int> sample_rolls_2 = {1,1,1,2,2};
int superset_index_2 = find(supersets.begin(), supersets.end(), sample_rolls_2) - supersets.begin();
vector<int> expected_choice_2 = vector<int> (0);
subset_index = get_index(expected_choice_2);
assert(abs(decision_input[subset_index].value - decision_output[superset_index_2].value) <= .001);
get_distribution_or_choice(available_options, 48, weights_part_3, decision_input, \
decision_output, 2);
vector<int> expected_choice_3 (3,1);
subset_index = get_index(expected_choice_3);
assert(abs(decision_input[subset_index].value - decision_output[superset_index_2].value) <= .001);
for (unsigned int i=0; i<Memoized_Subsets.subset_array[superset_index_2].size(); i++)
{
int subset_index = Memoized_Subsets.indices[superset_index_2][i];
if(abs(decision_input[subset_index].value - decision_output[superset_index_2].value) <= .001)
{
vector<int> claimed_ele = Memoized_Subsets.subset_array[superset_index_2][i];
assert(claimed_ele == expected_choice_3);
break;
}
assert(i < Memoized_Subsets.subset_array[superset_index_2].size() - 1);
}
delete [] decision_input;
delete [] decision_output;
}