oracleAdjust.h
Go to the documentation of this file.
1 /* oracleAdjust.h
2  */
3 #ifndef _ORACLEADUST_H
4 #define _ORACLEADUST_H
5 
6 #include "osl/numEffectState.h"
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:
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
Definition: basic_type.h:157
GeneralMask< mask_int_t > mask_t
Definition: mask.h:351
const Piece findAttackAt(Player attack, Square target) const
return a piece s.t.
Ptype ptype() const
Definition: basic_type.h:821
bool isPiece() const
Definition: basic_type.h:953
差が uniqになるような座標の差分.
Definition: offset32.h:16
const Piece pieceOnBoard(Square sq) const
Definition: simpleState.h:170
const Offset getShortOffsetNotKnight(Offset32 offset32) const
Longの利きの可能性のあるoffsetの場合は, 反復に使う offsetを Knight以外のShortの利きのoffsetの場合はそ...
Definition: boardTable.h:119
Offset32Base< 8, 9 > Offset32
Definition: offset32.h:63
bool isPtype() const
Definition: basic_type.h:930
const Piece pieceOf(int num) const
Definition: simpleState.h:76
Ptype ptype() const
Definition: basic_type.h:1155
const PtypeTable Ptype_Table
Definition: tables.cc:97
const Square from() const
Definition: basic_type.h:1125
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition: basic_type.h:1174
圧縮していない moveの表現 .
Definition: basic_type.h:1051
bool hasLongMove(Ptype ptype) const
遅くて良い?
Definition: ptypeTable.h:54
Player player() const
Definition: basic_type.h:1195
bool isAlmostValidMove(Move move) const
合法手かどうかを簡単に検査する.局面に依存するチェックのみ. ルール上指せない手である可能性がある場合...
利きを持つ局面
const Move newCapture(Piece capture) const
Definition: basic_type.h:1231
static const Move attack(const NumEffectState &state, Move check_move)
Definition: oracleAdjust.h:14
const Square square() const
Definition: basic_type.h:832
Ptype capturePtype() const
Definition: basic_type.h:1180
bool isDrop() const
Definition: basic_type.h:1150
const Square to() const
Definition: basic_type.h:1132
const mask_t allEffectAt(Player P, Square target) const
Move newFrom(Square new_from) const
Definition: basic_type.h:1207
static bool isValidMoveByRule(Move move, bool show_error)
盤面以外の部分の反則のチェック
Definition: simpleState.cc:372
bool isValid() const
Definition: basic_type.cc:246
const BoardTable Board_Table
Definition: tables.cc:95