ntesukiMoveGeneratorDefense.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ntesukiMoveGeneratorDefense.cc
Go to the documentation of this file.
1 /* ntesukiMoveGenerator.cc
2 */
3 #include "osl/ntesuki/ntesukiMoveGenerator.h"
4 #include "osl/state/numEffectState.h"
5 #include "osl/effect_util/neighboring8Direct.h"
6 #include "osl/move_generator/escape.h"
7 #include "osl/move_classifier/canAttackInNMoves.h"
8 #include "osl/move_classifier/moveAdaptor.h"
9 #include "osl/move_classifier/safeMove.h"
10 #include "osl/move_classifier/check.h"
11 #include "osl/move_generator/legalMoves.h"
12 #include "osl/move_generator/addEffect.h"
13 #include "osl/move_generator/drop.h"
14 #include "osl/move_generator/addEffect8.h"
15 #include "osl/move_generator/kingWalk.h"
16 #include "osl/move_generator/openKingRoad.h"
17 #include "osl/move_generator/dropAroundKing8.h"
18 #include "osl/move_generator/captureEffectToAroundKing8.h"
19 #include "osl/move_generator/addEffect8Defense.h"
20 #include "osl/move_action/store.h"
21 #include <iostream>
22
23 /*
24 * n 手すき探索で用いる move generator.
25 */
26
27 namespace osl
28 {
29 namespace ntesuki
30 {
31 /* ----------------------------------------------------------------------
32 * DEFENSE
33 * ----------------------------------------------------------------------
34 */
35 /* GetAllDefenseMoves
36 */
37 GetAllDefenseMoves::GetAllDefenseMoves(bool verbose)
38 : NtesukiDefenseMoveGenerator(verbose) {}
39 GetAllDefenseMoves::~GetAllDefenseMoves() {}
40 template <Player P>
41 void GetAllDefenseMoves::
42 generate(const NumEffectState& state,
43 NtesukiMoveList& moves,
44 const Square& last_to)
45 {
46 assert (state.turn() == P);
47 MoveVector move_candidates;
48 LegalMoves::generate(state, move_candidates);
49 moves = NtesukiMoveList(state, move_candidates);
50 }
51 template void GetAllDefenseMoves::generate<BLACK>(const NumEffectState& state,
52 NtesukiMoveList& moves,
53 const Square& last_to);
54 template void GetAllDefenseMoves::generate<WHITE>(const NumEffectState& state,
55 NtesukiMoveList& moves,
56 const Square& last_to);
57
58 /* GetDefenseMoves
59 * - 実装済み
60 * -- 玉を動かす
61 * -- 玉のまわり 8近傍に駒を打つ
62 * -- 玉の逃げ道を空ける
63 * -- 玉のまわり8近傍に利きをつけている駒(を取る
64 * -- 玉のまわり 8近傍に(守りの)利きをつけるによる defense
65 * -- 直前に動いた駒を取る手
66 * - 未実装
67 * -- 玉のまわり 8近傍の駒を取る
68 * -- 最後に動かした大駒から八近傍へ利きがある場合、
69 * その利きの途中のマスで、自分が利きがあるところに駒を打つ
70 * - 相手からの反撃のうち
71 * -- 駒を取りつつ王手(特に銀がないときの銀取りのような手)
72 */
73 GetDefenseMoves::GetDefenseMoves(bool verbose)
74 : NtesukiDefenseMoveGenerator(verbose) {}
75 GetDefenseMoves::~GetDefenseMoves(){}
76 template <Player P>
77 void GetDefenseMoves::
78 generate(const NumEffectState& state,
79 NtesukiMoveList& moves,
80 const Square& last_to)
81 {
82 MoveVector move_candidates;
83
84 const Square pos = state.template kingSquare<P>();
85 const bool check = state.hasEffectAt(PlayerTraits<P>::opponent, pos);
86
87 if (check)
88 {
89 GenerateEscapeKing::generate(state, move_candidates);
90 moves = NtesukiMoveList(state, move_candidates);
91 return;
92 }
93
94 typedef move_action::Store action_t;
95 assert (state.turn() == P);
96
97 move_action::Store store_candidates(move_candidates);
98
99 move_generator::KingWalk<P>::
100 generate(static_cast<const SimpleState &>(state),
101 store_candidates);
102 move_generator::OpenKingRoad<P>::
103 generate(static_cast<const SimpleState &>(state),
104 store_candidates);
105 move_generator::CaptureEffectToAroundKing8<P>::
106 generate(state, store_candidates);
107 move_generator::GenerateCapture::
108 generate(state.turn(), state, last_to, store_candidates);
109 //these are non drop moves that could be 'non safe moves'
110 MoveVector move_safe;
111 using namespace osl::move_classifier;
112 for (unsigned int i = 0; i < move_candidates.size(); ++i)
113 {
114 const Move m = move_candidates[i];
115
116 if (PlayerMoveAdaptor<SafeMove>::isMember(state, m))
117 {
118 move_safe.push_back(m);
119 }
120 }
121
122 move_action::Store store_safe(move_safe);
123 move_generator::AddEffect8Defense<P>::
124 generate(state, store_safe);
125 //drop moves that are always safe
126 move_generator::DropAroundKing8<P>::
127 generate(static_cast<const SimpleState &>(state),
128 store_safe);
129 move_safe.unique();
130 moves = NtesukiMoveList(state, move_safe);
131 }
132 template void GetDefenseMoves::generate<BLACK>(const NumEffectState& state,
133 NtesukiMoveList& moves,
134 const Square& last_to);
135 template void GetDefenseMoves::generate<WHITE>(const NumEffectState& state,
136 NtesukiMoveList& moves,
137 const Square& last_to);
138 }//ntesuki
139 }//osl
140
141
142 // ;;; Local Variables:
143 // ;;; mode:c++
144 // ;;; c-basic-offset:2
145 // ;;; End: