00001
00002
00003 #include "osl/threatmate/richPredictor.h"
00004
00005 double osl::threatmate::RichPredictor::predict(const NumEffectState& state,
00006 const Move move){
00007 const Player turn = alt(state.getTurn());
00008 const Position opKingPosition = state.getKingPosition(alt(turn));
00009 const int x = opKingPosition.x();
00010 const int y = opKingPosition.y();
00011 const Position to = move.to();
00012 const int distance_m = abs(x - to.x()) + abs(y - to.y());
00013 const int sign = -1 + 2 * (turn == BLACK);
00014 const int min = -1;
00015 const int max = 1;
00016
00017
00018 int add_effect = 0;
00019 int effect_b = 0;
00020 int effect_w = 0;
00021 int effect_e = 0;
00022
00023 for (int i=min; i<=max; i++)
00024 for (int j=min; j<=max; j++){
00025 Position pos(x+j, y+i);
00026 if (pos.isOnBoard()){
00027 int eff_w = state.countEffect(alt(turn),pos);
00028 effect_w += eff_w;
00029 add_effect += AdditionalEffect::count(state,turn, pos);
00030 int eff_b = state.countEffect(turn,pos);
00031 effect_b += eff_b;
00032 effect_e += (eff_b > eff_w);
00033 }
00034 }
00035
00036
00037 int escapeKing = 0;
00038 for (int i=min; i<=max; i++)
00039 for (int j=min; j<=max; j++){
00040 Position pos(x+j, y+i);
00041 if (pos.isOnBoard()){
00042 Piece pieceOnBoard = state.getPieceOnBoard(pos);
00043 if ((pieceOnBoard == Piece::EMPTY()) || (pieceOnBoard.owner() != alt(turn)))
00044 escapeKing += (!state.hasEffectBy(turn, pos));
00045 }
00046 }
00047
00048
00049 const double coefCapture[16]
00050 ={0.0, 0.0, 0.0, 0.0, 0.0, 5.06, 4.73, 7.70,
00051 0.0, 9.78, 0.0, 0.0, 0.0, 5.06, 4.73, 7.70};
00052
00053 const double neigh[9]
00054 ={14.52, 9.13, 8.26,
00055 0.39, 0.0, 11.87,
00056 0.53, 11.30, 15.06};
00057
00058 double neigh8 = 0.0;
00059 for (int i=min; i<=max; i++)
00060 for (int j=min; j<=max; j++){
00061 Position pos(x+sign*j, y+sign*i);
00062 if (pos.isOnBoard())
00063 neigh8 += neigh[3*(i+1)+j+1]*state.hasEffectByPiece(state.getPieceOnBoard(to), pos);
00064 }
00065
00066 const double value_p =
00067 9.62*(double)state.countPiecesOnStand(turn, ROOK)
00068 + 6.07*(double)state.countPiecesOnStand(turn, BISHOP)
00069 + 8.27*(double)state.countPiecesOnStand(turn, GOLD)
00070 + 5.64*(double)state.countPiecesOnStand(turn, SILVER)
00071 + 4.06*(double)state.countPiecesOnStand(turn, KNIGHT)
00072 + 2.77*(double)state.countPiecesOnStand(turn, LANCE)
00073 + 1.05*(double)state.countPiecesOnStand(turn, PAWN);
00074
00075 double est =
00076 45.07
00077 + neigh8
00078 + 10.20*(double)add_effect
00079 + 6.41*(double)effect_b
00080 - 1.24*(double)effect_w
00081 + 13.79*(double)effect_e
00082 - 1.98*(double)escapeKing
00083 - 3.11*(double)distance_m
00084 + value_p
00085 + coefCapture[move.capturePtype()];
00086
00087 return est;
00088 }
00089
00090
00091
00092
00093