-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvalScheme.cpp
171 lines (133 loc) · 4.15 KB
/
EvalScheme.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
/* This file is part of Qenolaba.
Copyright (C) 2000-2015 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
Qenolaba 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, version 2.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/* Evaluation Schemes are used for evalution of a board position */
#include "EvalScheme.h"
#include <QStringList>
// 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(QString 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::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(QString scheme)
{
int pos = scheme.indexOf('=');
if (pos<0) return 0;
EvalScheme* evalScheme = new EvalScheme( scheme.left(pos) );
evalScheme->setDefaults();
QStringList list = scheme.right(pos+1).split( QChar(',') );
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;
}
QString EvalScheme::ascii()
{
QString res;
int i;
res.sprintf("%s=%d", _name.toUtf8().constData(), _stoneValue[1]);
for(i=1;i<6;i++)
res += QString(",%1").arg( _stoneValue[i] );
for(i=0;i<Move::typeCount;i++)
res += QString(",%1").arg( _moveValue[i] );
for(i=0;i<InARowCounter::inARowCount;i++)
res += QString(",%1").arg( _inARowValue[i] );
for(i=0;i<5;i++)
res += QString(",%1").arg( _ringValue[i] );
for(i=0;i<5;i++)
res += QString(",%1").arg( _ringDiff[i] );
return res;
}