simpleState.tcc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
simpleState.tcc
Go to the documentation of this file.
1 /* simpleState.tcc
2 */
3 #ifndef OSL_SIMPLE_STATE_TCC
4 #define OSL_SIMPLE_STATE_TCC
5
6 #include "osl/state/simpleState.h"
7 #include <iostream>
8
9 template <bool show_error>
10 bool osl::SimpleState::isAlmostValidDrop(Move move) const
11 {
12 assert(move.from().isPieceStand());
13 const Square to=move.to();
14 const Piece to_piece=pieceAt(to);
15 const Ptype ptype=move.ptype();
16 const Player turn = move.player();
17 // ターゲットが空白か
18 if (! to_piece.isEmpty()) {
19 if (show_error) std::cerr << "drop on to piece : " << move << std::endl;
20 return false;
21 }
22 // そもそもその駒を持っているか?
23 if (! hasPieceOnStand(turn,ptype)) {
24 if (show_error) std::cerr << turn << " don't have : " << ptype << std::endl;
25 return false;
26 }
27 // 二歩のチェック
28 if (ptype==PAWN && isPawnMaskSet(turn, to.x())) {
29 if (show_error) std::cerr << " Double Pawn : " << move << std::endl;
30 return false;
31 }
32 return true;
33 }
34
35 template <bool show_error>
36 bool
37 osl::SimpleState::testValidityOtherThanEffect(Move move) const
38 {
39 const Square from=move.from();
40 const Piece from_piece = pieceAt(from);
41 const Square to=move.to();
42 const Piece to_piece=pieceAt(to);
43 // fromにあるのがその駒か
44 if (from_piece.isEmpty()
45 || (from_piece.owner() != turn()))
46 {
47 if (show_error)
48 std::cerr << " No such piece0 : " << move << std::endl;
49 return false;
50 }
51 // promoteしている時にpromote可能か
52 if (move.isPromotion())
53 {
54 // fromにあるのがその駒か
55 if (from_piece.ptype() != unpromote(move.ptype()))
56 {
57 if (show_error)
58 std::cerr << " No such piece1 : " << move << std::endl;
59 return false;
60 }
61 if (from_piece.isPromotedNotKingGold())
62 {
63 if (show_error)
64 std::cerr << " can't promote promoted piece : " << move << std::endl;
65 return false;
66 }
67 }
68 else
69 {
70 // fromにあるのがその駒か
71 if (from_piece.ptype() != move.ptype())
72 {
73 if (show_error)
74 std::cerr << " No such piece2 : " << move << std::endl;
75 return false;
76 }
77 }
78 // toにあるのが，相手の駒か空白か?
79 if (!to_piece.isEmpty() && to_piece.owner()==turn()) {
80 if (show_error) std::cerr << " No move on : " << move << std::endl;
81 return false;
82 }
83 // capturePtypeが一致しているか?
84 if (to_piece.ptype()!=move.capturePtype()) {
85 if (show_error) std::cerr << " Not such capture : " << move
86 << std::endl << *this;
87 return false;
88 }
89 return true;
90 }
91
92
93 #endif /* _SIMPLE_STATE_TCC */
94 // ;;; Local Variables:
95 // ;;; mode:c++
96 // ;;; c-basic-offset:2
97 // ;;; End: