-
Notifications
You must be signed in to change notification settings - Fork 0
/
Panel.cpp
81 lines (72 loc) · 2.51 KB
/
Panel.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
#include "Panel.h"
#include "Configure.h"
Panel::Panel():myMap(),count(0){} //default constructor
Panel::Panel(const int _row, const int _column):myMap(_row,_column),count(0){} //constructor
void Panel::AddPoint(const Point& p, const int _row, const int _column)
{
if (_row <= 0 || _column <=0 || _row > myMap.row || _column > myMap.column)
/* out of range */
throw ErrorSign();
if (myMap.map[_row][_column] != 0)
/* already have point */
throw ErrorSign();
myMap.map[_row][_column] = p.getIndex();
++count;
}
void Panel::DeletePoint(const int _row, const int _column)
{
if (_row <= 0 || _column <=0 || _row > myMap.row || _column > myMap.column)
/* out of range */
throw ErrorSign();
if (myMap.map[_row][_column] == 0)
/* there is no point */
throw ErrorSign();
myMap.map[_row][_column] = 0;
--count;
}
bool Panel::judgePath(const Point& start, const Point& finish)
{
if (start.getX() <= 0 || start.getY() <= 0 || start.getX() > myMap.row || start.getY() > myMap.column
|| finish.getX() <= 0 || finish.getY() <= 0 || finish.getX() > myMap.row || finish.getY() > myMap.column)
throw ErrorSign();
for (int i=0;i<MapRow;i++)
for (int j=0;j<MapColumn;j++)
for (int k=0;k<DIRECTION;k++)
f[i][j][k] = 3;
while (que.size()>0) que.pop();
for (int k=0;k<DIRECTION;k++)
{
f[start.getX()][start.getY()][k] = 0;
que.push(superPoint(start.getX(),start.getY(),k));
}
int tempValue;
while (que.size()>0){
superPoint now(que.front().getX(),que.front().getY(),que.front().index);
for (int k=0;k<DIRECTION;k++)
{
int nextX = now.getX() + direct[0][k];
int nextY = now.getY() + direct[1][k];
if (myMap.map[nextX][nextY] == 0){
if (now.index == k)
tempValue = f[now.getX()][now.getY()][now.index];
else
tempValue = f[now.getX()][now.getY()][now.index]+1;
if (tempValue < f[nextX][nextY][k])
{
f[nextX][nextY][k] = tempValue;
que.push(superPoint(nextX,nextY,k));
if (nextX == finish.getX() && nextY == finish.getY())
return true;
}
}
}
que.pop();
}
return false;
}
bool Panel::judgeVictory()
{
return (count == 0);
}
int Panel::getInfo(const int _row, const int _column){
}