00001
00010 #pragma once
00011
00012 #include "board.h"
00013
00014 #define RING0 0x0000001818000000ULL
00015 #define RING1 0x00003c24243c0000ULL
00016 #define RING2 0x007e424242427e00ULL
00017 #define RING3 0xff818181818181ffULL
00018
00019
00020 #define TRAP_TO_INDEX(trap) (trap < 32 ? (trap == 18 ? 0 : 1) : trap == 42 ? 2 : 3)
00021
00022
00023 #define GS_NUM 3
00024
00025 enum gameStage_e {GS_BEGIN, GS_MIDDLE, GS_LATE};
00026
00027 extern u64 adv[8][2];
00028
00029 enum trapType_e { TT_UNSAFE, TT_HALF_SAFE, TT_SAFE, TT_ACTIVE};
00030
00031 class Eval;
00032 class Values;
00033
00039 class ValueItem {
00040 public:
00041 ValueItem() {};
00042 ValueItem(string name, itemType_e type, void* item, int num);
00043
00044 bool isSingleValue() const;
00045
00046 private:
00047 string name_;
00048 itemType_e type_;
00049 void* item_;
00050 int num_;
00051 friend class Values;
00052 };
00053
00054 typedef list <ValueItem> ValueList;
00055
00059 class Values
00060 {
00061 public:
00062
00063 virtual ~Values(){};
00064
00068 virtual void init() = 0;
00069
00070
00071
00075 string toString() const;
00076
00077 protected:
00078 ValueList values;
00079
00083 bool loadFromString(string);
00084
00085 };
00086
00087
00091 class EvaluationValues:public Values
00092 {
00093 public:
00099 EvaluationValues(string config);
00100
00104 EvaluationValues();
00105
00106 void init();
00107
00108 private:
00109 friend class Eval;
00110
00117 void mirrorPiecePositions();
00118
00122 static void baseMirrorIndexes(int & player, int & coord);
00123
00125 int pieceValue[PIECE_NUM + 1];
00126
00128 int rabbitPenalty[RABBITS_NUM + 1];
00129
00131 float frozenPenaltyRatio;
00132
00133 int trapSoleVal;
00134 int trapMoreThanOneVal;
00135 int trapSafeVal;
00136 int trapActiveVal;
00137 int trapPotVal;
00138
00139 int activeTrapBlockedPenalty;
00140 float framePenaltyRatio;
00141 int camelHostagePenalty;
00142 int elephantBlockadePenalty;
00143
00144 float pinnedPenaltyRatio;
00145
00147 int piecePos[GS_NUM][2][PIECE_NUM + 1][BIT_LEN];
00148 };
00149
00153 class StepKnowledgeValues: public Values{
00154 public:
00155 StepKnowledgeValues(string config);
00156
00157 StepKnowledgeValues();
00158
00159 void init();
00160
00161 private:
00162 float passPenalty;
00163 float inverseStepPenalty;
00164 float elephantStepVal;
00165 float camelStepVal;
00166 float horseStepVal;
00167 float pushPullVal;
00168 float leaveBuddyInTrapPenalty;
00169 float suicidePenalty;
00170 float stepInDangerousTrapPenalty;
00171 float pushPullToTrapVal;
00172 float killVal;
00173 float rabbitStepBeginVal;
00174 float rabbitStepMiddleVal;
00175 float rabbitStepLateVal;
00176 float localityVal;
00177 int localityReach;
00178
00179 friend class Eval;
00180 };
00181
00188 class Eval
00189 {
00190 public:
00191 Eval();
00192
00196 Eval(const Board* board);
00197
00201 void init();
00202
00206 int evaluate(const Board*) const;
00207
00211 int evaluateDailey(const Board*) const;
00212
00216 float evaluateInPercent(const Board*) const;
00217
00221 float getPieceValue(piece_t piece) const;
00222
00228 float evaluateStep(const Board*, const Step& step) const;
00229
00230 private:
00231
00235 gameStage_e determineGameStage(const Bitboard& bitboard) const;
00236
00237 bool blocked(player_t player, piece_t piece, coord_t coord, const Board* b) const;
00238
00239 static string trapTypeToStr(trapType_e trapType);
00240
00241 EvalTT * evalTT_;
00242
00243 EvaluationValues * vals_;
00244 StepKnowledgeValues * skvals_;
00245
00247 double eval_max_;
00248
00249 };