compactBoard.h
Go to the documentation of this file.
#ifndef _COMPACT_BOARD_H
#define _COMPACT_BOARD_H
#include "osl/simpleState.h"
#include <vector>
#include <string>
namespace osl
{
namespace book
{
class OPiece
{
public:
OPiece(Piece p)
{
const Square pos = p.square();
const int bitPos = position2Bits(pos);
value = (static_cast<int>(p.owner()) << 20 |
static_cast<int>(p.ptype()) << 16 | bitPos);
}
OPiece(int i)
{
value = i;
}
Square square() const
{
return bits2Square(value);
}
Ptype ptype() const
{
return static_cast<Ptype>((value >> 16) & 0xf);
}
Player owner() const
{
return static_cast<Player>(value >> 20);
}
operator int() const { return value; }
static int position2Bits(const Square& pos);
static Square bits2Square(const int bit_position);
private:
int value;
};
class CompactBoard;
bool operator==(const CompactBoard&, const CompactBoard&);
std::ostream& operator<<(std::ostream& os, const CompactBoard& c);
std::istream& operator>>(std::istream& os, CompactBoard& c);
class CompactBoard
{
public:
CompactBoard() {}
explicit CompactBoard(const SimpleState& state);
SimpleState state() const;
const std::vector<OPiece>& pieces() const {return piece_vector;};
Player turn() const {return player_to_move;}
friend std::ostream& operator<<(std::ostream& os, const CompactBoard& c);
friend std::istream& operator>>(std::istream& os, CompactBoard& c);
friend bool operator==(const CompactBoard&, const CompactBoard&);
private:
std::vector<OPiece> piece_vector;
Player player_to_move;
};
int readInt(std::istream& is);
void writeInt(std::ostream& os, int n);
}
}
#endif // _COMPACT_BOARD_H
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
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::CompactBoard
SimpleStateよりcompactな局面の表現
Definition compactBoard.h:60
osl::book::CompactBoard::CompactBoard
CompactBoard()
Definition compactBoard.h:62
osl::book::CompactBoard::operator<<
friend std::ostream & operator<<(std::ostream &os, const CompactBoard &c)
osl::book::CompactBoard::player_to_move
Player player_to_move
Definition compactBoard.h:73
osl::book::CompactBoard::turn
Player turn() const
Definition compactBoard.h:66
osl::book::CompactBoard::operator==
friend bool operator==(const CompactBoard &, const CompactBoard &)
局面を比較する.
osl::book::CompactBoard::pieces
const std::vector< OPiece > & pieces() const
Definition compactBoard.h:65
osl::book::CompactBoard::operator>>
friend std::istream & operator>>(std::istream &os, CompactBoard &c)
osl::book::CompactBoard::piece_vector
std::vector< OPiece > piece_vector
Definition compactBoard.h:72
osl::book::CompactBoard::state
SimpleState state() const
Definition compactBoard.cc:58
osl::book::OPiece::square
Square square() const
Definition compactBoard.h:25
osl::book::OPiece::owner
Player owner() const
Definition compactBoard.h:33
osl::book::OPiece::OPiece
OPiece(int i)
Definition compactBoard.h:21
osl::book::OPiece::bits2Square
static Square bits2Square(const int bit_position)
Converts an integer (bits) to Square.
Definition compactBoard.cc:13
osl::book::OPiece::OPiece
OPiece(Piece p)
Definition compactBoard.h:14
osl::book::OPiece::value
int value
Definition compactBoard.h:44
osl::book::OPiece::position2Bits
static int position2Bits(const Square &pos)
Converts a position to an integer (bits).
Definition compactBoard.cc:7
osl::book::OPiece::ptype
Ptype ptype() const
Definition compactBoard.h:29
osl::book
Definition bookInMemory.h:12
osl::book::operator==
bool operator==(const CompactBoard &, const CompactBoard &)
局面を比較する.
Definition compactBoard.cc:73
osl::book::operator<<
std::ostream & operator<<(std::ostream &os, const CompactBoard &c)
Definition compactBoard.cc:79
osl::book::operator>>
std::istream & operator>>(std::istream &os, CompactBoard &c)
Definition compactBoard.cc:91
osl::book::writeInt
void writeInt(std::ostream &os, int n)
Definition openingBook.cc:18
osl::book::readInt
int readInt(std::istream &is)
Definition openingBook.cc:7
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::Player
Player
Definition basic_type.h:8
simpleState.h