All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
richPredictor.cc
Go to the documentation of this file.
1 /* richPredictor.cc
2  */
4 
5 double osl::threatmate::RichPredictor::predict(const NumEffectState& state,
6  const Move move){
7  const Player turn = alt(state.turn());
8  const Square opKingSquare = state.kingSquare(alt(turn));
9  const int x = opKingSquare.x();
10  const int y = opKingSquare.y();
11  const Square to = move.to();
12  const int distance_m = abs(x - to.x()) + abs(y - to.y());
13  const int sign = -1 + 2 * (turn == BLACK);
14  const int min = -1;
15  const int max = 1;
16 
17  // Kiki around opKing
18  int add_effect = 0;
19  int effect_b = 0;
20  int effect_w = 0;
21  int effect_e = 0;
22 
23  for (int i=min; i<=max; i++)
24  for (int j=min; j<=max; j++){
25  Square pos(x+j, y+i);
26  if (pos.isOnBoard()){
27  int eff_w = state.countEffect(alt(turn),pos);
28  effect_w += eff_w;
29  add_effect += AdditionalEffect::count(state,turn, pos);
30  int eff_b = state.countEffect(turn,pos);
31  effect_b += eff_b;
32  effect_e += (eff_b > eff_w);
33  }
34  }
35 
36  // King's Escape path
37  int escapeKing = 0;
38  for (int i=min; i<=max; i++)
39  for (int j=min; j<=max; j++){
40  Square pos(x+j, y+i);
41  if (pos.isOnBoard()){
42  Piece pieceOnBoard = state.pieceOnBoard(pos);
43  if ((pieceOnBoard == Piece::EMPTY()) || (pieceOnBoard.owner() != alt(turn)))
44  escapeKing += (!state.hasEffectAt(turn, pos));
45  }
46  }
47 
48  // Capture Ptype
49  const double coefCapture[16]
50  ={0.0, 0.0, 0.0, 0.0, 0.0, 5.06, 4.73, 7.70,
51  0.0, 9.78, 0.0, 0.0, 0.0, 5.06, 4.73, 7.70};
52 
53  const double neigh[9]
54  ={14.52, 9.13, 8.26,
55  0.39, 0.0, 11.87,
56  0.53, 11.30, 15.06};
57 
58  double neigh8 = 0.0;
59  for (int i=min; i<=max; i++)
60  for (int j=min; j<=max; j++){
61  Square pos(x+sign*j, y+sign*i);
62  if (pos.isOnBoard())
63  neigh8 += neigh[3*(i+1)+j+1]*state.hasEffectByPiece(state.pieceOnBoard(to), pos);
64  }
65 
66  const double value_p =
67  9.62*(double)state.countPiecesOnStand(turn, ROOK)
68  + 6.07*(double)state.countPiecesOnStand(turn, BISHOP)
69  + 8.27*(double)state.countPiecesOnStand(turn, GOLD)
70  + 5.64*(double)state.countPiecesOnStand(turn, SILVER)
71  + 4.06*(double)state.countPiecesOnStand(turn, KNIGHT)
72  + 2.77*(double)state.countPiecesOnStand(turn, LANCE)
73  + 1.05*(double)state.countPiecesOnStand(turn, PAWN);
74 
75  double est =
76  45.07
77  + neigh8
78  + 10.20*(double)add_effect
79  + 6.41*(double)effect_b
80  - 1.24*(double)effect_w
81  + 13.79*(double)effect_e
82  - 1.98*(double)escapeKing
83  - 3.11*(double)distance_m
84  + value_p
85  + coefCapture[move.capturePtype()];
86 
87  return est;
88 }
89 
90 // ;;; Local Variables:
91 // ;;; mode:c++
92 // ;;; c-basic-offset:2
93 // ;;; End: