00001
00002
00003 #include "osl/ntesuki/ntesukiMove.h"
00004 #include "osl/ntesuki/ntesukiMove.tcc"
00005 #include <iostream>
00006
00007
00008
00009
00010 osl::ntesuki::NtesukiMove::
00011 NtesukiMove()
00012 : move(Move::INVALID()), flags(0), order(-1) {};
00013
00014 osl::ntesuki::NtesukiMove::
00015 NtesukiMove(osl::Move m)
00016 : move(m), flags(0), order(-1),
00017 h_a_proof(1), h_a_disproof(1),
00018 h_d_proof(1), h_d_disproof(1)
00019 {};
00020
00021 osl::ntesuki::NtesukiMove::
00022 NtesukiMove(osl::Move m, Flags f)
00023 : move(m), flags(f), order(-1),
00024 h_a_proof(1), h_a_disproof(1),
00025 h_d_proof(1), h_d_disproof(1)
00026 {};
00027
00028 osl::ntesuki::NtesukiMove::
00029 NtesukiMove(const NtesukiMove& m)
00030 : move(m.move), flags(m.flags), order(m.order),
00031 h_a_proof(1), h_a_disproof(1),
00032 h_d_proof(1), h_d_disproof(1)
00033 {};
00034
00035 osl::ntesuki::NtesukiMove
00036 osl::ntesuki::NtesukiMove::
00037 operator=(const NtesukiMove& m)
00038 {
00039 if (this == &m) return *this;
00040
00041 move = m.move;
00042 flags = m.flags;
00043 order = m.order;
00044 h_a_proof = m.h_a_proof;
00045 h_a_disproof = m.h_a_disproof;
00046 h_d_proof = m.h_d_proof;
00047 h_d_disproof = m.h_d_disproof;
00048
00049 return *this;
00050 };
00051
00052 osl::ntesuki::NtesukiMove::
00053 ~NtesukiMove()
00054 {
00055 }
00056
00057
00058 osl::ntesuki::NtesukiMove osl::ntesuki::NtesukiMove::
00059 INVALID() { return NtesukiMove(Move::INVALID()); }
00060
00061
00062 void osl::ntesuki::NtesukiMove::
00063 setCheck()
00064 {
00065 ntesuki_assert(!(flags & CHECK_FLAG));
00066 flags |= CHECK_FLAG;
00067 };
00068
00069 bool osl::ntesuki::NtesukiMove::
00070 isCheck() const
00071 {
00072 return flags & CHECK_FLAG;
00073 }
00074
00075 void osl::ntesuki::NtesukiMove::
00076 setOrder(int o)
00077 {
00078 ntesuki_assert(order == -1);
00079 order = o;
00080 };
00081
00082 int osl::ntesuki::NtesukiMove::
00083 getOrder() const
00084 {
00085
00086 return order;
00087 }
00088
00089 void osl::ntesuki::NtesukiMove::
00090 setNoPromote()
00091 {
00092 ntesuki_assert(!(flags & NOPROMOTE));
00093 flags |= NOPROMOTE;
00094 };
00095
00096 bool osl::ntesuki::NtesukiMove::
00097 isNoPromote() const
00098 {
00099 return flags & NOPROMOTE;
00100 }
00101
00102 void osl::ntesuki::NtesukiMove::
00103 setInterpose()
00104 {
00105 ntesuki_assert(!(flags & INTERPOSE));
00106 flags |= INTERPOSE;
00107 };
00108
00109 bool osl::ntesuki::NtesukiMove::
00110 isInterpose() const
00111 {
00112 return flags & INTERPOSE;
00113 }
00114
00115 void osl::ntesuki::NtesukiMove::
00116 setLameLong()
00117 {
00118 ntesuki_assert(!(flags & LAME_LONG));
00119 flags |= LAME_LONG;
00120 }
00121
00122 bool osl::ntesuki::NtesukiMove::
00123 isLameLong() const
00124 {
00125 return flags & LAME_LONG;
00126 }
00127
00128 void osl::ntesuki::NtesukiMove::
00129 setToOld()
00130 {
00131 flags |= TO_OLDER_CHILD;
00132 };
00133
00134 bool osl::ntesuki::NtesukiMove::
00135 isToOld() const
00136 {
00137 return flags & TO_OLDER_CHILD;
00138 }
00139
00140
00141
00142
00143 bool osl::ntesuki::NtesukiMove::
00144 isImmediateCheckmate()const
00145 {
00146 return flags & IMMEDIATE_CHECKMATE;
00147 };
00148
00149 void osl::ntesuki::NtesukiMove::
00150 setBySimulation()
00151 {
00152 flags |= BY_SIMULATION;
00153 };
00154
00155 bool osl::ntesuki::NtesukiMove::
00156 isBySimulation() const
00157 {
00158 return flags & BY_SIMULATION;
00159 }
00160
00161
00162
00163 void osl::ntesuki::NtesukiMove::
00164 setPawnDropCheckmate()
00165 {
00166 flags |= PAWN_DROP_CHECKMATE_FLAG;
00167 };
00168
00169 bool osl::ntesuki::NtesukiMove::
00170 isPawnDropCheckmate() const
00171 {
00172 return (flags & PAWN_DROP_CHECKMATE_FLAG) == PAWN_DROP_CHECKMATE_FLAG;
00173 }
00174
00175 void osl::ntesuki::NtesukiMove::
00176 setHEstimates(unsigned short p_a, unsigned short d_a,
00177 unsigned short p_d, unsigned short d_d)
00178 {
00179 h_a_proof = p_a;
00180 h_a_disproof = d_a;
00181 h_d_proof = p_d;
00182 h_d_disproof = d_d;
00183 }
00184
00185 bool osl::ntesuki::NtesukiMove::
00186 isCheckmateSuccessSlow(Player P, int pass_left) const
00187 {
00188 if (P == BLACK)
00189 return isCheckmateSuccess<BLACK>(pass_left);
00190 else
00191 return isCheckmateSuccess<WHITE>(pass_left);
00192 }
00193
00194 bool osl::ntesuki::NtesukiMove::
00195 isCheckmateFailSlow(Player P, int pass_left) const
00196 {
00197 if (P == BLACK)
00198 return isCheckmateFail<BLACK>(pass_left);
00199 else
00200 return isCheckmateFail<WHITE>(pass_left);
00201 }
00202
00203
00204 bool osl::ntesuki::NtesukiMove::
00205 isValid() const { return move.isValid(); }
00206 bool osl::ntesuki::NtesukiMove::
00207 isInvalid() const { return move.isInvalid(); }
00208 bool osl::ntesuki::NtesukiMove::
00209 isNormal() const { return move.isNormal(); }
00210 bool osl::ntesuki::NtesukiMove::
00211 isPass() const { return move.isPass(); }
00212 bool osl::ntesuki::NtesukiMove::
00213 isDrop() const { return move.isDrop(); }
00214 osl::Position osl::ntesuki::NtesukiMove::
00215 to() const { return move.to(); }
00216 osl::Ptype osl::ntesuki::NtesukiMove::
00217 ptype() const { return move.ptype(); }
00218 osl::Move osl::ntesuki::NtesukiMove::
00219 getMove() const { return move; }
00220
00221
00222 bool osl::ntesuki::NtesukiMove::
00223 operator==(const NtesukiMove& rhs) const
00224 {
00225 return move == rhs.move;
00226 };
00227 bool osl::ntesuki::NtesukiMove::
00228 operator!=(const NtesukiMove& rhs) const
00229 {
00230 return move != rhs.move;
00231 };
00232
00233
00234 void osl::ntesuki::NtesukiMove::
00235 flagsToStream(std::ostream& os) const
00236 {
00237 int tmp = flags;
00238 for (int i = 0; i < 32; ++i)
00239 {
00240 if (1 == (tmp % 2))
00241 os << " " << NtesukiMove::FlagsStr[i];
00242 tmp = tmp >> 1;
00243 }
00244 }
00245
00246 std::ostream& osl::ntesuki::
00247 operator<<(std::ostream& os, const osl::ntesuki::NtesukiMove& move)
00248 {
00249 os << "(" << move.getMove();
00250 os << "o=" << move.getOrder() << " ";
00251 move.flagsToStream(os);
00252 return os << ")";
00253 }
00254
00255 namespace osl
00256 {
00257 namespace ntesuki
00258 {
00259 template void NtesukiMove::setCheckmateSuccess<BLACK>(int pass_left);
00260 template void NtesukiMove::setCheckmateSuccess<WHITE>(int pass_left);
00261 template void NtesukiMove::setCheckmateFail<BLACK>(int pass_left);
00262 template void NtesukiMove::setCheckmateFail<WHITE>(int pass_left);
00263 template void NtesukiMove::setImmediateCheckmate<BLACK>();
00264 template void NtesukiMove::setImmediateCheckmate<WHITE>();
00265 }
00266 }
00267
00268 std::string
00269 osl::ntesuki::NtesukiMove::FlagsStr[] =
00270 {
00271
00272 "CHECK",
00273
00274 "PAWN_CHECKMATE",
00275
00276 "(BUG)",
00277
00278 "IMMEDIATE",
00279
00280 "OLD_CHILD",
00281
00282 "NOPROMOTE",
00283
00284 "INTERPOSE",
00285
00286 "ATTACK",
00287
00288 "BY_SIMULATION",
00289
00290 "LAME_LONG",
00291
00292 "(BUG)",
00293
00294 "(BUG)",
00295
00296 "(BUG)",
00297
00298 "(BUG)",
00299
00300 "(BUG)",
00301
00302 "(BUG)",
00303
00304 "BLACK_SUCC_1",
00305 "BLACK_SUCC_2",
00306 "BLACK_SUCC_3",
00307 "BLACK_SUCC_4",
00308
00309 "WHITE_SUCC_1",
00310 "WHITE_SUCC_2",
00311 "WHITE_SUCC_3",
00312 "WHITE_SUCC_4",
00313
00314 "BLACK_FAIL_1",
00315 "BLACK_FAIL_2",
00316 "BLACK_FAIL_3",
00317 "BLACK_FAIL_4",
00318
00319 "WHITE_FAIL_1",
00320 "WHITE_FAIL_2",
00321 "WHITE_FAIL_3",
00322 "WHITE_FAIL_4",
00323 };