00001 #ifndef _COMPACT_BOARD_H 00002 #define _COMPACT_BOARD_H 00003 #include "osl/state/simpleState.h" 00004 #include "osl/stl/vector.h" 00005 00006 namespace osl 00007 { 00008 namespace record 00009 { 00010 class OPiece 00011 { 00012 public: 00013 OPiece(Piece p) 00014 { 00015 const Position pos = p.position(); 00016 const int bitPos = pos.isPieceStand() ? 0 : pos.x() << 4 | pos.y(); 00017 value = (static_cast<int>(p.owner()) << 20 | 00018 static_cast<int>(p.ptype()) << 16 | bitPos); 00019 } 00020 OPiece(int i) 00021 { 00022 value = i; 00023 } 00024 Position getPosition() const 00025 { 00026 if ((value & 0xff) == 0) 00027 return Position::STAND(); 00028 else 00029 return Position((value >> 4) & 0xf, value & 0xf); 00030 } 00031 Ptype getPtype() const 00032 { 00033 return static_cast<Ptype>((value >> 16) & 0xf); 00034 } 00035 Player getOwner() const 00036 { 00037 return static_cast<Player>(value >> 20); 00038 } 00039 operator int() const { return value; } 00040 private: 00041 int value; 00042 }; 00043 00044 class CompactBoard 00045 { 00046 public: 00047 CompactBoard() {} 00048 explicit CompactBoard(const SimpleState& state); 00049 SimpleState getState(); 00050 friend std::ostream& operator<<(std::ostream& os, const CompactBoard& c); 00051 friend std::istream& operator>>(std::istream& os, CompactBoard& c); 00052 private: 00053 osl::vector<OPiece> pieces; 00054 Player turn; 00055 }; 00056 } 00057 } 00058 00059 #endif // _COMPACT_BOARD_H