My Project
compactBoard.h
Go to the documentation of this file.
1#ifndef _COMPACT_BOARD_H
2#define _COMPACT_BOARD_H
3#include "osl/simpleState.h"
4#include <vector>
5#include <string>
6
7namespace osl
8{
9 namespace book
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 square() const
26 {
27 return bits2Square(value);
28 }
29 Ptype ptype() const
30 {
31 return static_cast<Ptype>((value >> 16) & 0xf);
32 }
33 Player owner() 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 state() const;
65 const std::vector<OPiece>& pieces() const {return piece_vector;};
66 Player turn() const {return player_to_move;}
67
68 friend std::ostream& operator<<(std::ostream& os, const CompactBoard& c);
69 friend std::istream& operator>>(std::istream& os, CompactBoard& c);
70 friend bool operator==(const CompactBoard&, const CompactBoard&);
71 private:
72 std::vector<OPiece> piece_vector;
74 };
75 int readInt(std::istream& is);
76 void writeInt(std::ostream& os, int n);
77 }
78}
79
80#endif // _COMPACT_BOARD_H
81/* ------------------------------------------------------------------------- */
82// ;;; Local Variables:
83// ;;; mode:c++
84// ;;; c-basic-offset:2
85// ;;; End:
Ptype ptype() const
Definition basic_type.h:821
const Square square() const
Definition basic_type.h:832
Player owner() const
Definition basic_type.h:963
SimpleStateよりcompactな局面の表現
friend std::ostream & operator<<(std::ostream &os, const CompactBoard &c)
friend bool operator==(const CompactBoard &, const CompactBoard &)
局面を比較する.
const std::vector< OPiece > & pieces() const
friend std::istream & operator>>(std::istream &os, CompactBoard &c)
std::vector< OPiece > piece_vector
SimpleState state() const
Square square() const
Player owner() const
static Square bits2Square(const int bit_position)
Converts an integer (bits) to Square.
static int position2Bits(const Square &pos)
Converts a position to an integer (bits)
Ptype ptype() const
bool operator==(const CompactBoard &, const CompactBoard &)
局面を比較する.
std::ostream & operator<<(std::ostream &os, const CompactBoard &c)
std::istream & operator>>(std::istream &os, CompactBoard &c)
void writeInt(std::ostream &os, int n)
int readInt(std::istream &is)
Definition openingBook.cc:7
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
Player
Definition basic_type.h:8