All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
enterKingUtil.cc
Go to the documentation of this file.
2 
3 // 範囲内(x0,y0) - (x1,y1) の利きの数を調べる
5  osl::Player Turn,
6  int x0, int x1, int y0, int y1) {
7  assert(x0 >= 1 && x0 <= 9);
8  assert(x1 >= 1 && x1 <= 9);
9  assert(y0 >= 1 && y0 <= 9);
10  assert(y1 >= 1 && y1 <= 9);
11  assert(x0 <= x1);
12  assert(y0 <= y1);
13  int effect_count = 0;
14  for (int sy = y0; sy <= y1; sy++)
15  for (int sx = x0; sx <= x1; sx++)
16  effect_count += state.countEffect(Turn, osl::Square(sx,sy));
17  return effect_count;
18 }
19 
20 // target の前方(target を中心とした幅3マス) の利きの数を調べる
23  osl::Player defense) {
24  const int ky = target.y();
25  // 一番前面にいるので前方が存在しない
26  if ((defense == osl::BLACK && ky == 1) ||
27  (defense == osl::WHITE && ky == 9)) return 0;
28 
29  const int kx = (target.x() == 1) ? 2 : ((target.x() == 9)? 8 : target.x());
30  if (defense == osl::BLACK)
31  return osl::enter_king::countEffectInRange(state, attack, kx - 1, kx + 1, 1, ky - 1);
32  else
33  return osl::enter_king::countEffectInRange(state, attack, kx - 1, kx + 1, ky + 1, 9);
34 }
35 
36 // 駒台の駒の点数を数える
38  return (5 * state.countPiecesOnStand<osl::ROOK>(Turn)
39  + 5 * state.countPiecesOnStand<osl::BISHOP>(Turn)
40  + state.countPiecesOnStand<osl::GOLD>(Turn)
41  + state.countPiecesOnStand<osl::SILVER>(Turn)
42  + state.countPiecesOnStand<osl::KNIGHT>(Turn)
43  + state.countPiecesOnStand<osl::LANCE>(Turn)
44  + state.countPiecesOnStand<osl::PAWN>(Turn));
45 }
46 
47 // 範囲内(x0,y0) - (x1,y1) の駒の点数を返す
48 // num_pieces には点数ではなく、枚数を足し込む
49 template <osl::Player Turn>
51  int& num_pieces,
52  int x0, int x1, int y0, int y1) {
53  assert(x0 >= 1 && x0 <= 9);
54  assert(x1 >= 1 && x1 <= 9);
55  assert(y0 >= 1 && y0 <= 9);
56  assert(y1 >= 1 && y1 <= 9);
57  assert(x0 <= x1);
58  assert(y0 <= y1);
59  int count = 0;
60  for (int sy = y0; sy <= y1; sy++) {
61  for (int sx = x0; sx <= x1; sx++) {
62  osl::Piece pieceOnSquare = state.pieceOnBoard(osl::Square(sx,sy));
63  if (! pieceOnSquare.isOnBoardByOwner<Turn>() ||
64  pieceOnSquare.ptype() == osl::KING)
65  continue;
66  count += (1 + 4 * isMajor(pieceOnSquare.ptype()));
67  num_pieces++;
68  }
69  }
70  return count;
71 }
73  int& num_pieces,
74  int x0, int x1, int y0, int y1) {
75  if (Turn == osl::BLACK)
76  return osl::enter_king::countPiecePointsInRange<BLACK>(state, num_pieces, x0, x1, y0, y1);
77  else
78  return osl::enter_king::countPiecePointsInRange<WHITE>(state, num_pieces, x0, x1, y0, y1);
79 }
80 // row 行目の駒の点数と枚数を調べる
81 template <osl::Player Turn>
83  int& num_pieces, int row) {
84  return osl::enter_king::countPiecePointsInRange<Turn>(state, num_pieces, 1, 9, row, row);
85 }
87  int& num_pieces, int row) {
88  if (Turn == osl::BLACK)
89  return osl::enter_king::countPiecePointsOnRow<BLACK>(state, num_pieces, row);
90  else
91  return osl::enter_king::countPiecePointsOnRow<WHITE>(state, num_pieces, row);
92 }
93 
94 namespace osl {
95  namespace enter_king {
96  template
98  (const osl::state::NumEffectState& state, int& num_pieces,
99  int x0, int x1, int y0, int y1);
100  template
102  (const osl::state::NumEffectState& state, int& num_pieces,
103  int x0, int x1, int y0, int y1);
104  template
106  (const osl::state::NumEffectState& state, int& num_pieces, int row);
107  template
109  (const osl::state::NumEffectState& state, int& num_pieces, int row);
110  }
111 }