-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pos2.h
95 lines (80 loc) · 2.43 KB
/
Pos2.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright Chris Welty
// All Rights Reserved
// This file is distributed subject to GNU GPL version 3. See the files
// GPLv3.txt and License.txt in the instructions subdirectory for details.
#pragma once
#include <stdio.h>
#include <vector>
#include "n64/utils.h"
#include "core/Moves.h"
#include "core/BitBoard.h"
#include "pattern/patternJ.h"
#include "Stable.hpp"
// global variables
class Pos2 {
public:
void InitializeToStartPosition();
void Initialize(const char* sBoard, bool fBlackMove);
void Initialize(const CBitBoard& bb, bool fBlackMove);
// print the position
void Print() const;
void FPrint(FILE* logfile) const;
void PrintStable() const;
void FPrintStable(FILE* logfile) const;
void PrintStableNext() const;
void FPrintStableNext(FILE* logfile) const;
// get the board text
char* GetText(char* sBoard) const;
// Moving
void MakeMoveBB(int square);
void PassBB();
int CalcMovesAndPassBB(CMoves& moves);
/**
* Calculate moves and store them in moves
*
* @param [out] moves location to store moves
* @return true if there are legal moves
*/
bool CalcMoves(CMoves& moves) const {
return m_bb.CalcMoves(moves);
}
void PassBase();
// Info
int NEmpty() const { return m_bb.NEmpty();}
bool BlackMove() const { return m_fBlackMove; }
const CBitBoard& GetBB() const { return m_bb; }
bool IsValid() const { return m_bb.IsValid(); };
int TerminalValue() const;
int CalcMobility(u4& nMovesPlayer, u4& nMovesOpponent) const {
return m_bb.CalcMobility(nMovesPlayer,nMovesOpponent);
}
uint64_t m_stable = 0;
uint64_t m_stable_trigger = Corners;
CBitBoard m_bb;
uint8_t m_stable_mover = 0;
uint8_t m_stable_opponent = 0;
bool m_fBlackMove;
private:
int CalcMovesAndPassBB(CMoves& moves, const CMoves& submoves);
};
inline int Pos2::TerminalValue() const {
return m_bb.TerminalValue();
}
inline void Pos2::PassBase() {
m_fBlackMove=!m_fBlackMove;
m_bb.mover = ~(m_bb.mover | m_bb.empty);
if (m_stable) {
auto stable_swap = m_stable_mover;
m_stable_mover = m_stable_opponent;
m_stable_opponent = stable_swap;
}
}
inline void Pos2::PassBB() {
m_fBlackMove = !m_fBlackMove;
m_bb.InvertColors();
if (m_stable) {
auto stable_swap = m_stable_mover;
m_stable_mover = m_stable_opponent;
m_stable_opponent = stable_swap;
}
}