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
|
/**
* EvalScheme
*
* Configuration options for a Evaluation Scheme.
* Evaluation Schemes are used for evalution of a Abalone board position
*
* (C) JW, 2000
*/
#include <tdeapplication.h>
#include <tdeconfig.h>
#include "EvalScheme.h"
// Default Values
static int defaultRingValue[] = { 45, 35, 25, 10, 0 };
static int defaultRingDiff[] = { 0, 10, 10, 8, 5 };
static int defaultStoneValue[]= { 0,-800,-1800,-3000,-4400,-6000 };
static int defaultMoveValue[Move::typeCount] = { 40,30,30, 15,14,13,
5,5,5, 2,2,2, 1 };
static int defaultInARowValue[InARowCounter::inARowCount]= { 2, 5, 4, 3 };
/**
* Constructor: Set Default values
*/
EvalScheme::EvalScheme(TQString n)
{
_name = n;
setDefaults();
}
/**
* Copy Constructor
*/
EvalScheme::EvalScheme(EvalScheme& s)
{
_name = s._name;
for(int i=0;i<6;i++)
_stoneValue[i] = s._stoneValue[i];
for(int i=0;i<Move::typeCount;i++)
_moveValue[i] = s._moveValue[i];
for(int i=0;i<InARowCounter::inARowCount;i++)
_inARowValue[i] = s._inARowValue[i];
for(int i=0;i<5;i++)
_ringValue[i] = s._ringValue[i];
for(int i=0;i<5;i++)
_ringDiff[i] = s._ringDiff[i];
}
void EvalScheme::setDefaults()
{
for(int i=0;i<6;i++)
_stoneValue[i] = defaultStoneValue[i];
for(int i=0;i<Move::typeCount;i++)
_moveValue[i] = defaultMoveValue[i];
for(int i=0;i<InARowCounter::inARowCount;i++)
_inARowValue[i] = defaultInARowValue[i];
for(int i=0;i<5;i++)
_ringValue[i] = defaultRingValue[i];
for(int i=0;i<5;i++)
_ringDiff[i] = defaultRingDiff[i];
}
void EvalScheme::read(TDEConfig *config)
{
TQString confSection = TQString("%1 Evaluation Scheme").arg(_name);
config->setGroup(confSection);
TQStringList list;
TQString tmp;
list = config->readListEntry("StoneValues");
if (list.count()>0) {
_stoneValue[0] = 0;
for(int i=1;i<6;i++)
_stoneValue[i] = list[i-1].toInt();
}
list = config->readListEntry("MoveValues");
if (list.count()>0) {
for(int i=0;i<Move::typeCount;i++)
_moveValue[i] = list[i].toInt();
}
list = config->readListEntry("InARowValues");
if (list.count()>0) {
for(int i=0;i<InARowCounter::inARowCount;i++)
_inARowValue[i] = list[i].toInt();
}
list = config->readListEntry("RingValues");
if (list.count()>0) {
for(int i=0;i<5;i++)
_ringValue[i] = list[i].toInt();
}
list = config->readListEntry("RingDiffs");
if (list.count()>0) {
for(int i=0;i<5;i++)
_ringDiff[i] = list[i].toInt();
}
}
void EvalScheme::save(TDEConfig* config)
{
TQString confSection = TQString("%1 Evaluation Scheme").arg(_name);
config->setGroup(confSection);
TQString entry;
entry.sprintf("%d,%d,%d,%d,%d", _stoneValue[1], _stoneValue[2],
_stoneValue[3], _stoneValue[4], _stoneValue[5]);
config->writeEntry("StoneValues", entry);
entry.sprintf("%d", _moveValue[0]);
for(int i=1;i<Move::typeCount;i++)
entry += TQString(", %1").arg( _moveValue[i] );
config->writeEntry("MoveValues", entry);
entry.sprintf("%d", _inARowValue[0]);
for(int i=1;i<InARowCounter::inARowCount;i++)
entry += TQString(", %1").arg( _inARowValue[i] );
config->writeEntry("InARowValues", entry);
entry.sprintf("%d,%d,%d,%d,%d", _ringValue[0], _ringValue[1],
_ringValue[2], _ringValue[3], _ringValue[4]);
config->writeEntry("RingValues", entry);
entry.sprintf("%d,%d,%d,%d,%d", _ringDiff[0], _ringDiff[1],
_ringDiff[2], _ringDiff[3], _ringDiff[4]);
config->writeEntry("RingDiffs", entry);
}
void EvalScheme::setRingValue(int ring, int value)
{
if (ring >=0 && ring <5)
_ringValue[ring] = value;
}
void EvalScheme::setRingDiff(int ring, int value)
{
if (ring >=1 && ring <5)
_ringDiff[ring] = value;
}
void EvalScheme::setStoneValue(int stoneDiff, int value)
{
if (stoneDiff>0 && stoneDiff<6)
_stoneValue[stoneDiff] = value;
}
void EvalScheme::setMoveValue(int type, int value)
{
if (type>=0 && type<Move::typeCount)
_moveValue[type] = value;
}
void EvalScheme::setInARowValue(int stones, int value)
{
if (stones>=0 && stones<InARowCounter::inARowCount)
_inARowValue[stones] = value;
}
/**
* Create a EvalScheme out of a String of format
*
* <SchemeName>=<v1>,<v2>,<v3>,<v4>,... (34 values)
*
*/
EvalScheme* EvalScheme::create(TQString scheme)
{
int pos = scheme.find('=');
if (pos<0) return 0;
EvalScheme* evalScheme = new EvalScheme( scheme.left(pos) );
evalScheme->setDefaults();
TQStringList list = TQStringList::split( TQString(","), scheme.right(pos+1) );
int i=0;
while(i<list.count()) {
if (i<5)
evalScheme->_stoneValue[i+1] = list[i].toInt();
else if (i<10)
evalScheme->_ringValue[i-5] = list[i].toInt();
else if (i<15)
evalScheme->_ringDiff[i-10] = list[i].toInt();
else if (i<15+Move::typeCount)
evalScheme->_moveValue[i-15] = list[i].toInt();
else if (i<15+Move::typeCount+InARowCounter::inARowCount)
evalScheme->_inARowValue[i-15-Move::typeCount] = list[i].toInt();
i++;
}
return evalScheme;
}
TQString EvalScheme::ascii()
{
TQString res;
int i;
res.sprintf("%s=%d", _name.ascii(), _stoneValue[1]);
for(i=1;i<6;i++)
res += TQString(",%1").arg( _stoneValue[i] );
for(i=0;i<Move::typeCount;i++)
res += TQString(",%1").arg( _moveValue[i] );
for(i=0;i<InARowCounter::inARowCount;i++)
res += TQString(",%1").arg( _inARowValue[i] );
for(i=0;i<5;i++)
res += TQString(",%1").arg( _ringValue[i] );
for(i=0;i<5;i++)
res += TQString(",%1").arg( _ringDiff[i] );
return res;
}
|