00001 #include "osl/piece.h" 00002 #include "osl/move.h" 00003 #include <boost/static_assert.hpp> 00004 #include <iostream> 00005 00006 namespace osl 00007 { 00008 BOOST_STATIC_ASSERT(sizeof(Move) == 4); 00009 } //namespace osl 00010 00011 bool osl::Move::isValid() const 00012 { 00013 if (! isNormal()) 00014 return false; 00015 const Position from = this->from(); 00016 if (! from.isValid()) 00017 return false; 00018 const Position to = this->to(); 00019 if (! to.isOnBoard()) 00020 return false; 00021 return osl::isValid(ptype()) 00022 && osl::isValid(capturePtype()) 00023 && capturePtype()!=KING 00024 && osl::isValid(player()); 00025 } 00026 00027 00028 std::ostream& osl::operator<<(std::ostream& os,const Move move) 00029 { 00030 if (move == Move::DeclareWin()) 00031 return os << "MOVE_DECLARE_WIN"; 00032 if (move.isInvalid()) 00033 return os << "MOVE_INVALID"; 00034 if (move.isPass()) 00035 return os << "MOVE_PASS"; 00036 const Player turn = move.player(); 00037 if (move.isValid()) 00038 { 00039 if (move.from().isPieceStand()) 00040 { 00041 os << "Drop(" << turn << "," << move.ptype() << "," << move.to() << ")"; 00042 } 00043 else 00044 { 00045 const Ptype capture_ptype=move.capturePtype(); 00046 os << "Move(" << turn << "," << move.ptype() << "," 00047 << move.from() << "->" << move.to() ; 00048 if (move.promoteMask()) 00049 os << ",promote"; 00050 if (capture_ptype != PTYPE_EMPTY) 00051 os << ",capture=" << capture_ptype; 00052 os << ")"; 00053 } 00054 } 00055 else 00056 { 00057 os << "InvalidMove " << move.from() << " " << move.to() 00058 << " " << move.ptypeO() << " " << move.oldPtypeO() 00059 << " " << move.promoteMask() 00060 << " " << move.capturePtype() << "\n"; 00061 } 00062 return os; 00063 } 00064 00065 // ;;; Local Variables: 00066 // ;;; mode:c++ 00067 // ;;; c-basic-offset:2 00068 // ;;; End: