-
Notifications
You must be signed in to change notification settings - Fork 2
/
algorithmStates.cpp
149 lines (122 loc) · 2.99 KB
/
algorithmStates.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
#include <math.h>
#include "algorithmStates.h"
//#include "LimitedEvalPlayer.h"
namespace hearts {
//#define min(x, y) (((x)>(y))?(y):(x))
//#define max(x, y) (((x)<(y))?(y):(x))
maxnState::maxnState(double lim, short after, short d)
:limit(lim), next(after), depth(d) {}
//bool maxnState::equals(State *val)
void maxnState::Print(int val) const
{
printf("depth %d\n", depth);
}
minimaxState::minimaxState(double aa, double bb, short nex, short d, short dr)
:a(aa), b(bb), next(nex), depth(d), depthRemaining(dr)
{ result = log(-1); }
void minimaxState::Print(int val) const
{
printf("depth %d/%d, a=%1.2f, b=%1.2f ans=%1.2f, next=%d\n", depth, depthRemaining, a, b, result, next);
}
bool minimaxState::equals(State *val)
{
minimaxState *mms = (minimaxState *)val;
//#pragma WARNING "isnan problem here"
//#warning "unresolved isnan problem here"
if (isnan(result))
return mms->equals(this);
if (next != mms->next)
return false;
if ((depth != mms->depth) || (depthRemaining != mms->depthRemaining))
return false;
if (result == a)
if (a != mms->a)
return false;
if (result == b)
return (b == mms->b);
return true;
}
maxnval::maxnval() :returnValue()
{
eval[0] = eval[1] = eval[2] = eval[3] = eval[4] = eval[5] = 0;
}
maxnval::~maxnval() { }
returnValue *maxnval::clone(GameState *g) const {
maxnval *r = new maxnval();
r->m = (m==0)?0:m->clone(g);
r->eval[0] = eval[0]; r->eval[1] = eval[1]; r->eval[2] = eval[2];
r->eval[3] = eval[3]; r->eval[4] = eval[4]; r->eval[5] = eval[5];
r->numPlayers = numPlayers;
return r;
}
void maxnval::Print(int v) const
{
printf("(%1.4f, %1.4f, %1.4f, %1.4f...)\n",
eval[0], eval[1], eval[2], eval[3]);
if (v) {
if (next) next->Print(v);
if (m) m->Print(v);
}
}
double maxnval::getValue(int who) const
{
return eval[who];
}
minimaxval::minimaxval()
:returnValue()
{ m = 0; }
minimaxval::minimaxval(double v, Move *mv)
{
val = v; m = mv;
}
minimaxval::~minimaxval()
{ }
returnValue *minimaxval::clone(GameState *g) const {
Move *mm=0;
if (m != 0) mm = m->clone(g);
return new minimaxval(val, mm);
}
double minimaxval::getValue(int who) const
{
return val;
}
void minimaxval::Print(int v) const
{
if (next)
{
next->Print(1);
}
if (m)
{
printf(" %1.2f ", val);
m->Print(v);
}
}
partition::partition(GameState *g, double score, double d)
{}
returnValue *outcomePDF::clone(GameState *g) const
{
outcomePDF *p = new outcomePDF(m?m->clone(g):0, /*next?next->clone(g):*/0);
p->utility.resize(utility.size());
for (unsigned int x = 0; x < utility.size(); x++)
for (unsigned int y = 0; y < utility[x].size(); y++)
p->utility[x].push_back(utility[x][y]);
p->realUtility = realUtility;
return p;
}
void outcomePDF::Print(int verbose) const
{
for (unsigned int x = 0; x < utility.size(); x++)
{
printf("(%d)\t", x);
for (unsigned int y = 0; y < utility[x].size(); y++)
{
printf("%1.4f\t", utility[x][y]);
}
printf("\n");
}
printf("Real util: %1.4f\t", realUtility);
if (m) m->Print(1);
printf("\n");
}
} // namespace hearts