00001
00002
00003 #include "osl/threatmate/mlPredictor.h"
00004
00005 const double predictor_coef[5][9] =
00006 {
00007
00008 {-3.7460724, 1.5899403, 1.5218839,
00009 1.8912265, 2.2698081, 2.9564733,
00010 1.8364091, 0.4818582, 0.2046128},
00011
00012 { -4.502173, 1.866922, 1.075071,
00013 1.785152, 2.904015, 3.546099,
00014 2.217401, 1.037181, 0.198456},
00015
00016 {-4.2651299, 1.8346520, 1.4515673,
00017 1.8766168, 2.8202449, 3.2856799,
00018 2.0692834, 0.7330482, 0.2069689},
00019
00020 {-3.8450811, 1.5901365, 1.6039122,
00021 1.9947154, 2.2830698, 2.9788201,
00022 1.8998258, 0.4654985, 0.2174952},
00023
00024 {-3.3149250, 1.3827221, 1.4877458,
00025 1.8048604, 1.6804844, 2.7207930,
00026 1.6221641, 0.3460561, 0.1866114,}
00027 };
00028
00029 double osl::threatmate::MlPredictor::predict(const NumEffectState& state,
00030 const Move move, size_t index){
00031 const Player turn = alt(state.turn());
00032 const Square oking = state.kingSquare(alt(turn));
00033 King8Info K(state.Iking8Info(alt(turn)));
00034 osl::progress::ml::NewProgress tprogress(state);
00035
00036 const double* coef = predictor_coef[index];
00037 double sum = coef[0];
00038
00039 const int npiece = (int)(move.capturePtype());
00040 if (npiece) {
00041 for (int i=0; i<3; i++)
00042 if (npiece%8 == i+5)
00043 sum += coef[i+1];
00044 if (npiece == 9)
00045 sum += coef[4];
00046 }
00047
00048 int moveCandidate;
00049 if(turn==BLACK) moveCandidate=K.countMoveCandidate<BLACK>(state);
00050 else moveCandidate=K.countMoveCandidate<WHITE>(state);
00051 sum += coef[5] * ( Neighboring8Direct::hasEffect(state, newPtypeO(turn, move.ptype()),
00052 move.to(), oking) ) +
00053 coef[6] * moveCandidate +
00054 coef[7] * ( misc::BitOp::countBit(K.dropCandidate()) )+
00055 coef[8] * ( tprogress.progressAttack(alt(turn)).value() );
00056
00057 return sum;
00058 }
00059 double osl::threatmate::MlPredictor::probability(const NumEffectState& state,
00060 const Move move, size_t index){
00061 return 1.0 / (1.0 + exp (- predict(state,move,index) ));
00062 }
00063
00064
00065
00066