-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helper.h
52 lines (41 loc) · 1.26 KB
/
Helper.h
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
#include "State.h"
#include <set>
bool isGoal(State state){
for (auto& location : state.Meat)
if(state.map_at(location) != BONE)
return false;
return true;
}
bool onGoal(State state, Point location){
for (auto& point : state.Meat)
if (point == location)
return true;
return false;
}
bool notAllowed(State state, Point& Target, Point& Future){
return state.isWall(Target) ||
state.isBox(Target) && state.isWallorBox(Future);
}
bool isDeadlock(State state){
set<Point> seen;
for (auto& box : state.Boxes)
{
if (seen.find(box) != seen.end())
return true;
seen.insert(box);
if (onGoal(state, box))
continue;
bool upright = state.isWall(box + Actions["up"]) && state.isWall(box + Actions["right"]);
bool upleft = state.isWall(box + Actions["up"]) && state.isWall(box + Actions["left"]);
bool downleft = state.isWall(box + Actions["down"]) && state.isWall(box + Actions["left"]);
bool downright = state.isWall(box + Actions["down"]) && state.isWall(box + Actions["right"]);
if (upright || upleft || downleft || downright)
return true;
for (auto& action : Actions) {
auto p = action.second+box;
if (state.isBox(p))
return true;
}
}
return false;
}