All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
compactBoard.h
Go to the documentation of this file.
1 #ifndef _COMPACT_BOARD_H
2 #define _COMPACT_BOARD_H
4 #include "osl/stl/vector.h"
5 #include <string>
6 
7 namespace osl
8 {
9  namespace record
10  {
11  class OPiece
12  {
13  public:
15  {
16  const Square pos = p.square();
17  const int bitPos = position2Bits(pos);
18  value = (static_cast<int>(p.owner()) << 20 |
19  static_cast<int>(p.ptype()) << 16 | bitPos);
20  }
21  OPiece(int i)
22  {
23  value = i;
24  }
25  Square getSquare() const
26  {
27  return bits2Square(value);
28  }
29  Ptype getPtype() const
30  {
31  return static_cast<Ptype>((value >> 16) & 0xf);
32  }
33  Player getOwner() const
34  {
35  return static_cast<Player>(value >> 20);
36  }
37  operator int() const { return value; }
38 
40  static int position2Bits(const Square& pos);
42  static Square bits2Square(const int bit_position);
43  private:
44  int value;
45  };
46 
47  class CompactBoard;
53  bool operator==(const CompactBoard&, const CompactBoard&);
54  std::ostream& operator<<(std::ostream& os, const CompactBoard& c);
55  std::istream& operator>>(std::istream& os, CompactBoard& c);
60  {
61  public:
63  explicit CompactBoard(const SimpleState& state);
64  SimpleState getState() const;
65  const osl::vector<OPiece>& getPieces() const {return pieces;};
66  Player turn() const {return player_to_move;}
67 
68  std::string toBase64() const;
69  static const CompactBoard fromBase64(const std::string& str);
70 
71  friend std::ostream& operator<<(std::ostream& os, const CompactBoard& c);
72  friend std::istream& operator>>(std::istream& os, CompactBoard& c);
73  friend bool operator==(const CompactBoard&, const CompactBoard&);
74  private:
75  osl::vector<OPiece> pieces;
77  };
78  }
79 }
80 
81 #endif // _COMPACT_BOARD_H
82 /* ------------------------------------------------------------------------- */
83 // ;;; Local Variables:
84 // ;;; mode:c++
85 // ;;; c-basic-offset:2
86 // ;;; End: