My Project
miniBoard.h
Go to the documentation of this file.
1 #ifndef _MINI_BOARD_H
2 #define _MINI_BOARD_H
4 #include "osl/simpleState.h"
5 #include "boost/dynamic_bitset.hpp"
6 #include <string>
7 #include <vector>
8 
9 namespace osl
10 {
11  namespace book
12  {
19  class OSquare
20  {
21  public:
22  static const size_t total_bits;
23  OSquare() : value(0) {}
24  OSquare(const Piece& p)
25  {
26  const Square pos = p.square();
27  const int bitPos = OPiece::position2Bits(pos); // 8 bits
28  int owner = 0;
29  if (p.owner() == BLACK)
30  owner = 0;
31  else
32  owner = 1;
33  value = owner << 8 | bitPos; // 9 bits
34  }
35  OSquare(const int i)
36  {
37  value = i;
38  }
39  Square getSquare() const
40  {
41  return OPiece::bits2Square(value);
42  }
43  Player getOwner() const
44  {
45  const int owner = value >> 8 & 1;
46  if (owner == 0)
47  return BLACK;
48  else
49  return WHITE;
50  }
51  operator int() const { return value; }
52  protected:
53  int value;
54  };
55 
64  class OPSquare : public OSquare
65  {
66  public:
67  static const size_t total_bits;
68  OPSquare() : OSquare() {}
69  OPSquare(const Piece& p)
70  : OSquare(p)
71  {
72  int is_promoted = 0;
73  if (p.isPromoted())
74  is_promoted = 1;
75  value = is_promoted << 9 | value; // 10 bits
76  }
77  OPSquare(const int i)
78  : OSquare(i) {}
79  bool isPromoted() const
80  {
81  const int is_promoted = value >> 9 & 1;
82  if (is_promoted == 0)
83  return false;
84  else
85  return true;
86  }
87  };
88 
103  class MiniBoard
104  {
105  public:
106  static const size_t total_bits;
108  explicit MiniBoard(const SimpleState& state);
109  SimpleState getState() const;
110  boost::dynamic_bitset<> toBits() const;
111  std::string toBase64() const;
112  private:
113  typedef std::vector<OPSquare> PawnArray; // 10 bits x 18 = 180
114  typedef std::vector<OPSquare> LanceArray; // 10 x 4 = 40
115  typedef std::vector<OPSquare> KnightArray; // 10 x 4 = 40
116  typedef std::vector<OPSquare> SilverArray; // 10 x 4 = 40
117  typedef std::vector<OPSquare> BishopArray; // 10 x 2 = 20
118  typedef std::vector<OPSquare> RookArray; // 10 x 2 = 20
119  typedef std::vector<OSquare> GoldArray; // 9 x 4 = 36
120  typedef osl::CArray<char, 2> KingArray; // 8 x 2 = 16
121  // ------------------
122  // 392
132 
135  friend int fromBase64(const std::string& base64, MiniBoard& mb);
136  };
137  }
138 }
139 
140 #endif // _MINI_BOARD_H
141 /* ------------------------------------------------------------------------- */
142 // ;;; Local Variables:
143 // ;;; mode:c++
144 // ;;; c-basic-offset:2
145 // ;;; End:
bool isPromoted() const
promoteした駒かどうかをチェックする
Definition: basic_type.h:898
const Square square() const
Definition: basic_type.h:832
Player owner() const
Definition: basic_type.h:963
More compact board than CompactBoard.
Definition: miniBoard.h:104
std::vector< OSquare > GoldArray
Definition: miniBoard.h:119
std::vector< OPSquare > RookArray
Definition: miniBoard.h:118
friend int fromBase64(const std::string &base64, MiniBoard &mb)
Converts a base64 string to MiniBoard.
Definition: miniBoard.cc:257
static const size_t total_bits
Definition: miniBoard.h:106
LanceArray lance_pieces
Definition: miniBoard.h:124
boost::dynamic_bitset toBits() const
Definition: miniBoard.cc:178
std::vector< OPSquare > BishopArray
Definition: miniBoard.h:117
std::string toBase64() const
Definition: miniBoard.cc:251
std::vector< OPSquare > PawnArray
Definition: miniBoard.h:113
SilverArray silver_pieces
Definition: miniBoard.h:126
std::vector< OPSquare > SilverArray
Definition: miniBoard.h:116
KingArray king_pieces
Definition: miniBoard.h:130
BishopArray bishop_pieces
Definition: miniBoard.h:127
SimpleState getState() const
Definition: miniBoard.cc:112
RookArray rook_pieces
Definition: miniBoard.h:128
KnightArray knight_pieces
Definition: miniBoard.h:125
osl::CArray< char, 2 > KingArray
Definition: miniBoard.h:120
std::vector< OPSquare > LanceArray
Definition: miniBoard.h:114
std::vector< OPSquare > KnightArray
Definition: miniBoard.h:115
GoldArray gold_pieces
Definition: miniBoard.h:129
PawnArray pawn_pieces
Definition: miniBoard.h:123
Square, Owner, Promoted : 10 bits.
Definition: miniBoard.h:65
static const size_t total_bits
Definition: miniBoard.h:67
OPSquare(const Piece &p)
Definition: miniBoard.h:69
OPSquare(const int i)
Definition: miniBoard.h:77
bool isPromoted() const
Definition: miniBoard.h:79
static Square bits2Square(const int bit_position)
Converts an integer (bits) to Square.
Definition: compactBoard.cc:13
static int position2Bits(const Square &pos)
Converts a position to an integer (bits)
Definition: compactBoard.cc:7
Square, Owner: 9 bits.
Definition: miniBoard.h:20
OSquare(const Piece &p)
Definition: miniBoard.h:24
Square getSquare() const
Definition: miniBoard.h:39
Player getOwner() const
Definition: miniBoard.h:43
OSquare(const int i)
Definition: miniBoard.h:35
static const size_t total_bits
Definition: miniBoard.h:22
Player
Definition: basic_type.h:8
@ WHITE
Definition: basic_type.h:10
@ BLACK
Definition: basic_type.h:9