All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bigramKillerMove.cc
Go to the documentation of this file.
1 /* bigramKillerMove.cc
2  */
4 #include <iostream>
5 
8 {
9  clear();
10 }
11 
14 {
15 }
16 
17 void osl::search::
19 {
20  for (size_t i=0; i<killer_moves.capacity1(); ++i)
21  for (size_t j=0; j<killer_moves.capacity2(); ++j)
22  killer_moves[i][j].clear();
23 }
24 
25 void osl::search::
26 BigramKillerMove::getMove(const NumEffectState& state, Move last_move,
27  MoveVector& out) const
28 {
29  if (last_move.isInvalid())
30  return;
31  const LRUMoves& moves = operator[](last_move);
32 
33  for (size_t i=0; i<moves.size(); ++i)
34  {
35  Move bigram_move = moves[i];
36  if (bigram_move.isInvalid())
37  return;
38  const Ptype ptype = bigram_move.oldPtype();
39  const Square from = bigram_move.from();
40  if ((! from.isPieceStand())
41  && (state.pieceOnBoard(from).ptype() != ptype))
42  {
43  if (! Ptype_Table.hasLongMove(ptype))
44  return;
45  assert(isPiece(ptype));
46  const Square to = bigram_move.to();
47  const Player player = state.turn();
48  const PieceMask pieces
49  = state.piecesOnBoard(player) & state.effectSetAt(to);
50  // to に同じptype の利きがあれば拾う
51  for (int i=Ptype_Table.getIndexMin(unpromote(ptype));
52  i<Ptype_Table.getIndexLimit(unpromote(ptype)); ++i)
53  {
54  if (pieces.test(i))
55  {
56  const Piece moving = state.pieceOf(i);
57  assert(moving.owner() == player);
58  if (moving.ptype() != ptype)
59  continue;
60  const Square new_from = moving.square();
61  const bool promote = (! isPromoted(ptype))
62  && (to.canPromote(player) || new_from.canPromote(player));
63  bigram_move = Move(new_from, to,
64  (promote
65  ? osl::promote(moving.ptype()) : moving.ptype()),
66  bigram_move.capturePtype(),
67  promote, player);
68  assert(state.isValidMoveByRule(bigram_move,false));
69  break;
70  }
71  }
72  }
73  if (state.isAlmostValidMove<false>(bigram_move))
74  out.push_back(bigram_move);
75  }
76 }
77 
78 void osl::search::
80 {
81  for (int y=1; y<=9; ++y)
82  {
83  for (int x=1; x<=9; ++x)
84  {
85  const Square position(x,y);
86  for (int p=PTYPEO_MIN; p<=PTYPEO_MAX; ++p)
87  {
88  const PtypeO ptypeo = static_cast<PtypeO>(p);
89  const LRUMoves& moves
90  = killer_moves[position.index()][ptypeOIndex(ptypeo)];
91  if (moves[0].isNormal())
92  {
93  std::cerr << position << " " << moves[0];
94  if (moves[1].isNormal())
95  std::cerr << " " << moves[1];
96  std::cerr << "\n";
97  }
98  }
99  }
100  }
101 }
102 
103 /* ------------------------------------------------------------------------- */
104 // ;;; Local Variables:
105 // ;;; mode:c++
106 // ;;; c-basic-offset:2
107 // ;;; End: