-
Notifications
You must be signed in to change notification settings - Fork 0
/
Position.h
71 lines (51 loc) · 1.54 KB
/
Position.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include "Common.h"
struct RNG;
struct Position {
Position();
void doMove(int wall);
void doMove(const Move& move);
void doMove(const string& move);
void tryClose(int wall, int square, Zone& zone, bool& border) const;
Zone findZone(int wall) const;
bool isPossibleWall(int wall) const;
bool isPossibleSize(int size) const;
bool getRandomMove(RNG& gen, Move& move) const;
Move getMove(int Wall) const;
struct MoveIterator {
Move move;
const Position* pos;
int index;
MoveIterator(const Position* p, int i = 0) : pos(p), index(i) { advance(); }
void advance() {
while (index < pos->wallsLength) {
int wall = pos->walls[index];
auto zone = pos->findZone(wall);
if (pos->isPossibleSize(zone.size)) {
move = {wall, zone};
break;
}
++index;
}
}
void operator++() {
++index;
advance();
}
const Move& operator*() { return move; }
bool operator==(const MoveIterator& it) { return index == it.index; }
bool operator!=(const MoveIterator& it) { return index != it.index; }
};
MoveIterator begin() const { return MoveIterator(this); }
MoveIterator end() const { return MoveIterator(this, wallsLength); }
bool isEndGame() const { return begin() == end(); }
int getImpact(const Move& move) const;
State getStateAfterPlaying(const Move& move) const;
mutable int walls[60];
Bitmask placed;
Bitmask state;
Bitmask possibleWalls;
Bitmask possibleSizes;
int turns;
int wallsLength;
};