-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pawn.cpp
72 lines (63 loc) · 2.11 KB
/
Pawn.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
//
// Pawn.cpp for ChessIA in /home/wilmot_p/PROG/C++/ChessIA
//
// Made by WILMOT Pierre
// Login <[email protected]>
//
// Started on Tue Nov 27 00:30:50 2012 WILMOT Pierre
//
#include <iostream>
#include "Pawn.hpp"
Pawn::Pawn(int x, int y, GameData::team t)
: PieceInfo(x, y, t, GameData::Pawn)
{
m_name = "Pawn";
}
Pawn::~Pawn()
{
}
bool Pawn::startPosition(GameData const &g) const
{
if ((g.getDirection(m_team) == 1 && m_y == 1)
|| (g.getDirection(m_team) == -1 && m_y == 6))
return (true);
return (false);
}
std::list<Move *> *Pawn::getSuccessors(GameData const &g) const
{
std::list<Move *> *successorStateList = NULL;
Move *successorState;
successorStateList = new std::list<Move *>();
if (caseIsValid(m_x, m_y + g.getDirection(m_team))
&& g[m_x][m_y + g.getDirection(m_team)].first == GameData::Empty)
{
successorState = new Move(g, m_x, m_y, m_x, m_y + g.getDirection(m_team));
successorStateList->push_back(successorState);
successorState = NULL;
if (caseIsValid(m_x, m_y + (2 * g.getDirection(m_team)))
&& g[m_x][m_y + (2 * g.getDirection(m_team))].first == GameData::Empty
&& startPosition(g))
{
successorState = new Move(g, m_x, m_y, m_x, m_y + (2 * g.getDirection(m_team)));
successorStateList->push_back(successorState);
successorState = NULL;
}
}
if (caseIsValid(m_x - 1, m_y + g.getDirection(m_team))
&& g[m_x - 1][m_y + g.getDirection(m_team)].second != GameData::None
&& g[m_x - 1][m_y + g.getDirection(m_team)].second != m_team)
{
successorState = new Move(g, m_x, m_y, m_x - 1, m_y + g.getDirection(m_team));
successorStateList->push_back(successorState);
successorState = NULL;
}
if (caseIsValid(m_x + 1, m_y + g.getDirection(m_team))
&& g[m_x + 1][m_y + g.getDirection(m_team)].second != GameData::None
&& g[m_x + 1][m_y + g.getDirection(m_team)].second != m_team)
{
successorState = new Move(g, m_x, m_y, m_x + 1, m_y + g.getDirection(m_team));
successorStateList->push_back(successorState);
successorState = NULL;
}
return (successorStateList);
}