説明を見る。00001
00002
00003 #ifndef OSL_SIMPLE_STATE_TCC
00004 #define OSL_SIMPLE_STATE_TCC
00005
00006 #include "osl/simpleState.h"
00007 #include <iostream>
00008
00009 template <bool show_error>
00010 bool osl::SimpleState::isAlmostValidDrop(Move move) const
00011 {
00012 assert(move.from().isPieceStand());
00013 const Square to=move.to();
00014 const Piece to_piece=pieceAt(to);
00015 const Ptype ptype=move.ptype();
00016 const Player turn = move.player();
00017
00018 if (! to_piece.isEmpty()) {
00019 if (show_error) std::cerr << "drop on to piece : " << move << std::endl;
00020 return false;
00021 }
00022
00023 if (! hasPieceOnStand(turn,ptype)) {
00024 if (show_error) std::cerr << turn << " don't have : " << ptype << std::endl;
00025 return false;
00026 }
00027
00028 if (ptype==PAWN && isPawnMaskSet(turn, to.x())) {
00029 if (show_error) std::cerr << " Double Pawn : " << move << std::endl;
00030 return false;
00031 }
00032 return true;
00033 }
00034
00035 template <bool show_error>
00036 bool
00037 osl::SimpleState::testValidityOtherThanEffect(Move move) const
00038 {
00039 const Square from=move.from();
00040 const Piece from_piece = pieceAt(from);
00041 const Square to=move.to();
00042 const Piece to_piece=pieceAt(to);
00043
00044 if (from_piece.isEmpty()
00045 || (from_piece.owner() != turn()))
00046 {
00047 if (show_error)
00048 std::cerr << " No such piece0 : " << move << std::endl;
00049 return false;
00050 }
00051
00052 if (move.isPromotion())
00053 {
00054
00055 if (from_piece.ptype() != unpromote(move.ptype()))
00056 {
00057 if (show_error)
00058 std::cerr << " No such piece1 : " << move << std::endl;
00059 return false;
00060 }
00061 if (from_piece.isPromotedNotKingGold())
00062 {
00063 if (show_error)
00064 std::cerr << " can't promote promoted piece : " << move << std::endl;
00065 return false;
00066 }
00067 }
00068 else
00069 {
00070
00071 if (from_piece.ptype() != move.ptype())
00072 {
00073 if (show_error)
00074 std::cerr << " No such piece2 : " << move << std::endl;
00075 return false;
00076 }
00077 }
00078
00079 if (!to_piece.isEmpty() && to_piece.owner()==turn()) {
00080 if (show_error) std::cerr << " No move on : " << move << std::endl;
00081 return false;
00082 }
00083
00084 if (to_piece.ptype()!=move.capturePtype()) {
00085 if (show_error) std::cerr << " Not such capture : " << move
00086 << std::endl << *this;
00087 return false;
00088 }
00089 return true;
00090 }
00091
00092
00093 #endif
00094
00095
00096
00097