-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMoveList.cpp
More file actions
141 lines (118 loc) · 2.04 KB
/
Copy pathMoveList.cpp
File metadata and controls
141 lines (118 loc) · 2.04 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// MoveList.cpp: implementation of the MoveList class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RenLib.h"
#include "MoveList.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
MoveList::MoveList()
{
ClearAll();
}
MoveList::~MoveList()
{
}
void MoveList::ClearAll()
{
for (int i=0; i <= MAXINDEX; i++)
{
m_List[i] = 0;
}
m_nIndex = -1;
}
void MoveList::ClearEnd()
{
for (int i = m_nIndex + 1; i <= MAXINDEX; i++)
{
m_List[i] = 0;
}
}
bool MoveList::IsEmpty() const
{
return m_nIndex == -1;
}
bool MoveList::IsFull() const
{
return m_nIndex == MAXINDEX;
}
void MoveList::SetRoot(MoveNode* pMove)
{
VERIFY(IsEmpty());
Add(pMove);
}
void MoveList::Add(MoveNode* pMove)
{
VERIFY(m_nIndex < MAXINDEX);
m_List[++m_nIndex] = pMove;
}
void MoveList::Swap(int nIndex1, int nIndex2)
{
VERIFY(nIndex1 >= 1 && nIndex1 <= m_nIndex);
VERIFY(nIndex2 >= 1 && nIndex2 <= m_nIndex);
MoveNode* temp = m_List[nIndex1];
m_List[nIndex1] = m_List[nIndex2];
m_List[nIndex2] = temp;
}
MoveNode* MoveList::GetRoot() const
{
VERIFY(!IsEmpty());
return m_List[0];
}
MoveNode* MoveList::Get(int nIndex) const
{
VERIFY(!IsEmpty());
VERIFY(nIndex >= 0 && nIndex <= MAXINDEX);
return m_List[nIndex];
}
MoveNode* MoveList::Current() const
{
VERIFY(!IsEmpty());
return m_List[m_nIndex];
}
MoveNode* MoveList::Next()
{
if (m_nIndex < MAXINDEX)
{
return m_List[m_nIndex + 1];
}
else
{
return 0;
}
}
MoveNode* MoveList::Previous()
{
if (m_nIndex > 0)
{
return m_List[m_nIndex - 1];
}
else
{
return 0;
}
}
void MoveList::SetIndex(int nIndex)
{
VERIFY(nIndex >= 0 && nIndex <= m_nIndex);
m_nIndex = nIndex;
}
void MoveList::SetRootIndex()
{
SetIndex(0);
}
void MoveList::Decrement()
{
VERIFY(m_nIndex > 0);
m_nIndex--;
}
int MoveList::Index() const
{
return m_nIndex;
}