-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnight.cpp
65 lines (57 loc) · 1.4 KB
/
Knight.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
//
// Knight.cpp for ChessIA in /home/wilmot_p/PROG/C++/ChessIA
//
// Made by WILMOT Pierre
// Login <[email protected]>
//
// Started on Tue Nov 27 00:33:13 2012 WILMOT Pierre
//
#include <iostream>
#include "Knight.hpp"
Knight::Knight(int x, int y, GameData::team t)
: PieceInfo(x, y, t, GameData::Knight)
{
m_name = "Knight";
m_directions[0][0] = 1;
m_directions[0][1] = -2;
m_directions[1][0] = -1;
m_directions[1][1] = -2;
m_directions[2][0] = 2;
m_directions[2][1] = -1;
m_directions[3][0] = 2;
m_directions[3][1] = 1;
m_directions[4][0] = 1;
m_directions[4][1] = 2;
m_directions[5][0] = -1;
m_directions[5][1] = 2;
m_directions[6][0] = -2;
m_directions[6][1] = 1;
m_directions[7][0] = -2;
m_directions[7][1] = -1;
}
Knight::~Knight()
{
}
std::list<Move *> *Knight::getSuccessors(GameData const &g) const
{
std::list<Move *> *successorStateList = NULL;
Move *successorState;
successorStateList = new std::list<Move *>();
int dest_x;
int dest_y;
for (int a(0) ; a < 8 ; ++a)
{
dest_x = m_x + m_directions[a][0];
dest_y = m_y + m_directions[a][1];
if (caseIsValid(dest_x, dest_y))
{
if (g[dest_x][dest_y].first == GameData::Empty)
{
successorState = new Move(g, m_x, m_y, dest_x, dest_y);
successorStateList->push_back(successorState);
successorState = NULL;
}
}
}
return (successorStateList);
}