All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
oracleAdjust.h
Go to the documentation of this file.
1 /* oracleAdjust.h
2  */
3 #ifndef _ORACLEADUST_H
4 #define _ORACLEADUST_H
5 
7 
8 namespace osl
9 {
10  namespace checkmate
11  {
12  struct OracleAdjust
13  {
14  static const Move attack(const NumEffectState& state, Move check_move)
15  {
16  assert(check_move.isValid());
17  if (! check_move.isDrop())
18  {
19  // capture
20  {
21  const Piece p=state.pieceOnBoard(check_move.to());
22  if (p.isPtype<KING>())
23  return Move();
24  check_move=check_move.newCapture(p);
25  }
26 
27  // from
28  if (state.pieceOnBoard(check_move.from()).ptype() != check_move.oldPtype()
29  && Ptype_Table.hasLongMove(check_move.ptype())) {
30  Piece p;
31  switch (unpromote(check_move.ptype())) {
32  case ROOK:
33  {
34  mask_t m = state.allEffectAt<ROOK>(check_move.player(), check_move.to());
35  while (m.any()) {
36  const int num = m.takeOneBit()+PtypeFuns<ROOK>::indexNum*32;
37  p = state.pieceOf(num);
38  if (Board_Table.getShortOffsetNotKnight(Offset32(check_move.to(), check_move.from()))
39  == Board_Table.getShortOffsetNotKnight(Offset32(check_move.to(), p.square())))
40  break;
41  }
42  break;
43  }
44  case BISHOP:
45  {
46  mask_t m = state.allEffectAt<BISHOP>(check_move.player(), check_move.to());
47  while (m.any()) {
48  const int num = m.takeOneBit()+PtypeFuns<BISHOP>::indexNum*32;
49  p = state.pieceOf(num);
50  if (Board_Table.getShortOffsetNotKnight(Offset32(check_move.to(), check_move.from()))
51  == Board_Table.getShortOffsetNotKnight(Offset32(check_move.to(), p.square())))
52  break;
53  }
54  break;
55  }
56  case LANCE: p = state.findAttackAt<LANCE>(check_move.player(), check_move.to());
57  break;
58  default:
59  assert(0);
60  }
61  if (p.isPiece()) {
62  if (check_move.oldPtype() == p.ptype())
63  check_move=check_move.newFrom(p.square());
64  else if (check_move.ptype() == p.ptype())
65  check_move = Move(p.square(), check_move.to(), check_move.ptype(),
66  check_move.capturePtype(), false, check_move.player());
67  if (! state.isValidMoveByRule(check_move, false))
68  return Move();
69  }
70  }
71  }
72  if (! state.isAlmostValidMove<false>(check_move))
73  return Move();
74  return check_move;
75  }
76  };
77  }
78 }
79 
80 
81 #endif /* _ORACLEADUST_H */
82 // ;;; Local Variables:
83 // ;;; mode:c++
84 // ;;; c-basic-offset:2
85 // ;;; End: