-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathkiller.cpp
102 lines (85 loc) · 2.22 KB
/
killer.cpp
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
96
97
98
99
100
101
102
/*
Copyright (C) 2015 Matthew Lai
Giraffe is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Giraffe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "killer.h"
#include <limits>
#include <algorithm>
Killer::Killer()
{
}
void Killer::Notify(int32_t ply, Move move)
{
if (m_killerMoves.size() < (static_cast<size_t>(ply) + 1))
{
m_killerMoves.resize(ply + 1);
for (size_t i = 0; i < NUM_KILLER_MOVES_PER_PLY; ++i)
{
m_killerMoves[ply].moves[i] = 0;
m_killerMoves[ply].moves[i] = 0;
}
}
// if the move is already in the table, we don't need to do anything
if (m_killerMoves[ply].moves[0] == move)
{
return;
}
// otherwise, push everything down one slot
for (int64_t i = (NUM_KILLER_MOVES_PER_PLY - 1); i >= 0; --i)
{
if (i == 0)
{
m_killerMoves[ply].moves[i] = move;
}
else
{
m_killerMoves[ply].moves[i] = m_killerMoves[ply].moves[i - 1];
}
}
}
void Killer::GetKillers(KillerMoveList &moveList, int32_t ply)
{
moveList.Clear();
if (m_killerMoves.size() < (static_cast<size_t>(ply) + 1))
{
return;
}
// moves from the current ply
for (size_t i = 0; i < NUM_KILLER_MOVES_PER_PLY; ++i)
{
moveList.PushBack(m_killerMoves[ply].moves[i]);
}
// moves from the ply-2
if (ply >= 2)
{
for (size_t i = 0; i < NUM_KILLER_MOVES_PER_PLY; ++i)
{
moveList.PushBack(m_killerMoves[ply - 2].moves[i]);
}
}
// moves from the ply+2
if ((static_cast<size_t>(ply) + 2) < m_killerMoves.size())
{
for (size_t i = 0; i < NUM_KILLER_MOVES_PER_PLY; ++i)
{
moveList.PushBack(m_killerMoves[ply + 2].moves[i]);
}
}
}
void Killer::MoveMade()
{
// if a move is made, we decrement all plies
for (size_t ply = 1; ply < m_killerMoves.size(); ++ply)
{
m_killerMoves[ply - 1] = m_killerMoves[ply];
}
}