00001 #ifndef _COMPACT_BOARD_H 00002 #define _COMPACT_BOARD_H 00003 #include "osl/state/simpleState.h" 00004 #include "osl/stl/vector.h" 00005 #include <string> 00006 00007 namespace osl 00008 { 00009 namespace record 00010 { 00011 class OPiece 00012 { 00013 public: 00014 OPiece(Piece p) 00015 { 00016 const Position pos = p.position(); 00017 const int bitPos = position2Bits(pos); 00018 value = (static_cast<int>(p.owner()) << 20 | 00019 static_cast<int>(p.ptype()) << 16 | bitPos); 00020 } 00021 OPiece(int i) 00022 { 00023 value = i; 00024 } 00025 Position getPosition() const 00026 { 00027 return bits2Position(value); 00028 } 00029 Ptype getPtype() const 00030 { 00031 return static_cast<Ptype>((value >> 16) & 0xf); 00032 } 00033 Player getOwner() const 00034 { 00035 return static_cast<Player>(value >> 20); 00036 } 00037 operator int() const { return value; } 00038 00040 static int position2Bits(const Position& pos); 00042 static Position bits2Position(const int bit_position); 00043 private: 00044 int value; 00045 }; 00046 00047 class CompactBoard; 00053 bool operator==(const CompactBoard&, const CompactBoard&); 00054 std::ostream& operator<<(std::ostream& os, const CompactBoard& c); 00055 std::istream& operator>>(std::istream& os, CompactBoard& c); 00059 class CompactBoard 00060 { 00061 public: 00062 CompactBoard() {} 00063 explicit CompactBoard(const SimpleState& state); 00064 SimpleState getState() const; 00065 const osl::vector<OPiece>& getPieces() const {return pieces;}; 00066 Player getTurn() const {return turn;} 00067 00068 std::string toBase64() const; 00069 static const CompactBoard fromBase64(const std::string& str); 00070 00071 friend std::ostream& operator<<(std::ostream& os, const CompactBoard& c); 00072 friend std::istream& operator>>(std::istream& os, CompactBoard& c); 00073 friend bool operator==(const CompactBoard&, const CompactBoard&); 00074 private: 00075 osl::vector<OPiece> pieces; 00076 Player turn; 00077 }; 00078 } 00079 } 00080 00081 #endif // _COMPACT_BOARD_H 00082 /* ------------------------------------------------------------------------- */ 00083 // ;;; Local Variables: 00084 // ;;; mode:c++ 00085 // ;;; c-basic-offset:2 00086 // ;;; End: