説明を見る。00001
00002
00003 #ifndef OSL_PTYPEEVAL_H
00004 #define OSL_PTYPEEVAL_H
00005
00006 #include "osl/eval/ptypeEvalTraits.h"
00007 #include "osl/eval/evalTraits.h"
00008 #include "osl/numEffectState.h"
00009 #include <cassert>
00010
00011 namespace osl
00012 {
00013 namespace eval
00014 {
00015 class PtypeEvalTable
00016 {
00017 protected:
00018 CArray<int, PTYPEO_SIZE> ptypeO2Val;
00019 CArray<int, PTYPEO_SIZE> promoteVal;
00020 CArray<int, PTYPEO_SIZE> captureVal;
00021 public:
00022 PtypeEvalTable();
00023 ~PtypeEvalTable();
00024 void init();
00025 public:
00029 int value(PtypeO ptypeO) const{
00030 assert(isValidPtypeO(ptypeO));
00031 return ptypeO2Val[ptypeO-PTYPEO_MIN];
00032 }
00036 int value(Ptype ptype) const{
00037 assert(isValid(ptype));
00038 return ptypeO2Val[ptype-PTYPEO_MIN];
00039 }
00043 int promoteValue(PtypeO ptypeO) const{
00044 assert(isPromoted(ptypeO));
00045 return promoteVal[ptypeO-PTYPEO_MIN];
00046 }
00050 int captureValue(PtypeO ptypeO) const{
00051 assert(isValidPtypeO(ptypeO));
00052 return captureVal[ptypeO-PTYPEO_MIN];
00053 }
00054 int diffWithMove(const NumEffectState&, Move move) const {
00055 int ret = 0;
00056 if (move.capturePtype() != PTYPE_EMPTY)
00057 ret += captureValue(move.capturePtypeO());
00058 if (move.isPromotion())
00059 ret+=promoteValue(move.ptypeO());
00060 return ret;
00061 }
00062
00063 void reset(const CArray<int, PTYPE_SIZE>& values);
00064 };
00065 extern const PtypeEvalTable Ptype_Eval_Table;
00066 }
00067 }
00068
00069 #endif
00070
00071 #ifndef EVAL_ML_PIECEEVAL_H
00072 #define EVAL_ML_PIECEEVAL_H
00073
00074 #include "osl/eval/weights.h"
00075
00076 namespace osl
00077 {
00078 namespace eval
00079 {
00080 namespace ml
00081 {
00082 class PieceEval
00083 {
00084 static CArray<int, PTYPEO_SIZE> table;
00085 public:
00086 static void setUp(const Weights &weights);
00087 static int eval(const NumEffectState &state);
00088 template<Player P>
00089 static int evalWithUpdate(const NumEffectState &,
00090 Move moved, int last_value)
00091 {
00092 assert(moved.player()==P);
00093 int value = last_value;
00094 if (moved.isPass() || moved.isDrop())
00095 return last_value;
00096 if (moved.isPromotion())
00097 {
00098 value -= table[moved.oldPtypeO() - PTYPEO_MIN];
00099 value += table[moved.ptypeO() - PTYPEO_MIN];
00100 }
00101 Ptype captured = moved.capturePtype();
00102 if (captured != PTYPE_EMPTY)
00103 {
00104 value -= table[newPtypeO(alt(P), captured) - PTYPEO_MIN];
00105 value += table[newPtypeO(P, unpromote(captured)) - PTYPEO_MIN];
00106 }
00107 return value;
00108 }
00109 static int value(PtypeO ptypeO);
00110 };
00111 }
00112 }
00113 }
00114 #endif // EVAL_ML_PIECEEVAL_H
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124