miniBoard.h
Go to the documentation of this file.
#ifndef _MINI_BOARD_H
#define _MINI_BOARD_H
#include "osl/book/compactBoard.h"
#include "osl/simpleState.h"
#include "boost/dynamic_bitset.hpp"
#include <string>
#include <vector>
namespace osl
{
namespace book
{
class OSquare
{
public:
static const size_t total_bits;
OSquare() : value(0) {}
OSquare(const Piece& p)
{
const Square pos = p.square();
const int bitPos = OPiece::position2Bits(pos); // 8 bits
int owner = 0;
if (p.owner() == BLACK)
owner = 0;
else
owner = 1;
value = owner << 8 | bitPos; // 9 bits
}
OSquare(const int i)
{
value = i;
}
Square getSquare() const
{
return OPiece::bits2Square(value);
}
Player getOwner() const
{
const int owner = value >> 8 & 1;
if (owner == 0)
return BLACK;
else
return WHITE;
}
operator int() const { return value; }
protected:
int value;
};
class OPSquare : public OSquare
{
public:
static const size_t total_bits;
OPSquare() : OSquare() {}
OPSquare(const Piece& p)
: OSquare(p)
{
int is_promoted = 0;
if (p.isPromoted())
is_promoted = 1;
value = is_promoted << 9 | value; // 10 bits
}
OPSquare(const int i)
: OSquare(i) {}
bool isPromoted() const
{
const int is_promoted = value >> 9 & 1;
if (is_promoted == 0)
return false;
else
return true;
}
};
class MiniBoard
{
public:
static const size_t total_bits;
MiniBoard() {}
explicit MiniBoard(const SimpleState& state);
SimpleState getState() const;
boost::dynamic_bitset<> toBits() const;
std::string toBase64() const;
private:
typedef std::vector<OPSquare> PawnArray; // 10 bits x 18 = 180
typedef std::vector<OPSquare> LanceArray; // 10 x 4 = 40
typedef std::vector<OPSquare> KnightArray; // 10 x 4 = 40
typedef std::vector<OPSquare> SilverArray; // 10 x 4 = 40
typedef std::vector<OPSquare> BishopArray; // 10 x 2 = 20
typedef std::vector<OPSquare> RookArray; // 10 x 2 = 20
typedef std::vector<OSquare> GoldArray; // 9 x 4 = 36
typedef osl::CArray<char, 2> KingArray; // 8 x 2 = 16
// ------------------
// 392
PawnArray pawn_pieces;
LanceArray lance_pieces;
KnightArray knight_pieces;
SilverArray silver_pieces;
BishopArray bishop_pieces;
RookArray rook_pieces;
GoldArray gold_pieces;
KingArray king_pieces;
Player turn;
friend int fromBase64(const std::string& base64, MiniBoard& mb);
};
}
}
#endif // _MINI_BOARD_H
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::CArray
Definition container.h:20
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::isPromoted
bool isPromoted() const
promoteした駒かどうかをチェックする
Definition basic_type.h:898
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::owner
Player owner() const
Definition basic_type.h:963
osl::SimpleState
Definition simpleState.h:35
osl::Square
Definition basic_type.h:532
osl::book::MiniBoard::GoldArray
std::vector< OSquare > GoldArray
Definition miniBoard.h:119
osl::book::MiniBoard::RookArray
std::vector< OPSquare > RookArray
Definition miniBoard.h:118
osl::book::MiniBoard::fromBase64
friend int fromBase64(const std::string &base64, MiniBoard &mb)
Converts a base64 string to MiniBoard.
Definition miniBoard.cc:257
osl::book::MiniBoard::total_bits
static const size_t total_bits
Definition miniBoard.h:106
osl::book::MiniBoard::lance_pieces
LanceArray lance_pieces
Definition miniBoard.h:124
osl::book::MiniBoard::toBits
boost::dynamic_bitset toBits() const
Definition miniBoard.cc:178
osl::book::MiniBoard::BishopArray
std::vector< OPSquare > BishopArray
Definition miniBoard.h:117
osl::book::MiniBoard::toBase64
std::string toBase64() const
Definition miniBoard.cc:251
osl::book::MiniBoard::turn
Player turn
Definition miniBoard.h:131
osl::book::MiniBoard::PawnArray
std::vector< OPSquare > PawnArray
Definition miniBoard.h:113
osl::book::MiniBoard::silver_pieces
SilverArray silver_pieces
Definition miniBoard.h:126
osl::book::MiniBoard::SilverArray
std::vector< OPSquare > SilverArray
Definition miniBoard.h:116
osl::book::MiniBoard::king_pieces
KingArray king_pieces
Definition miniBoard.h:130
osl::book::MiniBoard::bishop_pieces
BishopArray bishop_pieces
Definition miniBoard.h:127
osl::book::MiniBoard::getState
SimpleState getState() const
Definition miniBoard.cc:112
osl::book::MiniBoard::rook_pieces
RookArray rook_pieces
Definition miniBoard.h:128
osl::book::MiniBoard::knight_pieces
KnightArray knight_pieces
Definition miniBoard.h:125
osl::book::MiniBoard::KingArray
osl::CArray< char, 2 > KingArray
Definition miniBoard.h:120
osl::book::MiniBoard::LanceArray
std::vector< OPSquare > LanceArray
Definition miniBoard.h:114
osl::book::MiniBoard::KnightArray
std::vector< OPSquare > KnightArray
Definition miniBoard.h:115
osl::book::MiniBoard::gold_pieces
GoldArray gold_pieces
Definition miniBoard.h:129
osl::book::MiniBoard::pawn_pieces
PawnArray pawn_pieces
Definition miniBoard.h:123
osl::book::MiniBoard::MiniBoard
MiniBoard()
Definition miniBoard.h:107
osl::book::OPSquare::total_bits
static const size_t total_bits
Definition miniBoard.h:67
osl::book::OPSquare::OPSquare
OPSquare(const Piece &p)
Definition miniBoard.h:69
osl::book::OPSquare::OPSquare
OPSquare()
Definition miniBoard.h:68
osl::book::OPSquare::OPSquare
OPSquare(const int i)
Definition miniBoard.h:77
osl::book::OPSquare::isPromoted
bool isPromoted() const
Definition miniBoard.h:79
osl::book::OPiece::bits2Square
static Square bits2Square(const int bit_position)
Converts an integer (bits) to Square.
Definition compactBoard.cc:13
osl::book::OPiece::position2Bits
static int position2Bits(const Square &pos)
Converts a position to an integer (bits).
Definition compactBoard.cc:7
osl::book::OSquare::OSquare
OSquare(const Piece &p)
Definition miniBoard.h:24
osl::book::OSquare::getSquare
Square getSquare() const
Definition miniBoard.h:39
osl::book::OSquare::value
int value
Definition miniBoard.h:53
osl::book::OSquare::OSquare
OSquare()
Definition miniBoard.h:23
osl::book::OSquare::getOwner
Player getOwner() const
Definition miniBoard.h:43
osl::book::OSquare::OSquare
OSquare(const int i)
Definition miniBoard.h:35
osl::book::OSquare::total_bits
static const size_t total_bits
Definition miniBoard.h:22
compactBoard.h
osl::book
Definition bookInMemory.h:12
osl
Definition additionalEffect.h:6
osl::Player
Player
Definition basic_type.h:8
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
simpleState.h