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 }
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 const osl::Move osl::Move::rotate180() const
00028 {
00029 if (isPass())
00030 return Move::PASS(alt(player()));
00031 if (! isNormal())
00032 return *this;
00033 return Move(from().rotate180Safe(), to().rotate180(), ptype(),
00034 capturePtype(), isPromote(), alt(player()));
00035 }
00036
00037 std::ostream& osl::operator<<(std::ostream& os,const Move move)
00038 {
00039 if (move == Move::DeclareWin())
00040 return os << "MOVE_DECLARE_WIN";
00041 if (move.isInvalid())
00042 return os << "MOVE_INVALID";
00043 if (move.isPass())
00044 return os << "MOVE_PASS";
00045 const Player turn = move.player();
00046 if (move.isValid())
00047 {
00048 if (move.from().isPieceStand())
00049 {
00050 os << "Drop(" << turn << "," << move.ptype() << "," << move.to() << ")";
00051 }
00052 else
00053 {
00054 const Ptype capture_ptype=move.capturePtype();
00055 os << "Move(" << turn << "," << move.ptype() << ","
00056 << move.from() << "->" << move.to() ;
00057 if (move.promoteMask())
00058 os << ",promote";
00059 if (capture_ptype != PTYPE_EMPTY)
00060 os << ",capture=" << capture_ptype;
00061 os << ")";
00062 }
00063 }
00064 else
00065 {
00066 os << "InvalidMove " << move.from() << " " << move.to()
00067 << " " << move.ptypeO() << " " << move.oldPtypeO()
00068 << " " << move.promoteMask()
00069 << " " << move.capturePtype() << "\n";
00070 }
00071 return os;
00072 }
00073
00074
00075
00076
00077