00001 #ifndef _COMPACT_BOARD_H 00002 #define _COMPACT_BOARD_H 00003 #include "osl/simpleState.h" 00004 #include <vector> 00005 #include <string> 00006 00007 namespace osl 00008 { 00009 namespace book 00010 { 00011 class OPiece 00012 { 00013 public: 00014 OPiece(Piece p) 00015 { 00016 const Square pos = p.square(); 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 Square square() const 00026 { 00027 return bits2Square(value); 00028 } 00029 Ptype ptype() const 00030 { 00031 return static_cast<Ptype>((value >> 16) & 0xf); 00032 } 00033 Player owner() const 00034 { 00035 return static_cast<Player>(value >> 20); 00036 } 00037 operator int() const { return value; } 00038 00040 static int position2Bits(const Square& pos); 00042 static Square bits2Square(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 state() const; 00065 const std::vector<OPiece>& pieces() const {return piece_vector;}; 00066 Player turn() const {return player_to_move;} 00067 00068 friend std::ostream& operator<<(std::ostream& os, const CompactBoard& c); 00069 friend std::istream& operator>>(std::istream& os, CompactBoard& c); 00070 friend bool operator==(const CompactBoard&, const CompactBoard&); 00071 private: 00072 std::vector<OPiece> piece_vector; 00073 Player player_to_move; 00074 }; 00075 int readInt(std::istream& is); 00076 void writeInt(std::ostream& os, int n); 00077 } 00078 } 00079 00080 #endif // _COMPACT_BOARD_H 00081 /* ------------------------------------------------------------------------- */ 00082 // ;;; Local Variables: 00083 // ;;; mode:c++ 00084 // ;;; c-basic-offset:2 00085 // ;;; End: