-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulate.cpp
More file actions
99 lines (89 loc) · 2.39 KB
/
Simulate.cpp
File metadata and controls
99 lines (89 loc) · 2.39 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
//
// Created by botanic on 8/7/15.
//
#include "Simulate.h"
using namespace icfp2015;
bool icfp2015::Simulate::nextUnit() {
Unit nextUnit(units[gen()]);
uY = 0;
uX = (field.width() - nextUnit.width()) / 2 - nextUnit.disp();
if (!nextUnit.Check(field, uX, uY)) {
return false;
}
nextUnit.Apply(field, uX, uY);
curUnit = nextUnit;
unitPath.Reset(nextUnit);
unitPath.Save(uX, uY, curUnit.Orient());
return true;
}
VerifyState icfp2015::Simulate::step(Actions a, bool verify) {
int uXnew = uX, uYnew = uY;
Unit newUnit = curUnit;
switch (a) {
case Actions::MoveW:
--uXnew;
break;
case Actions::MoveE:
++uXnew;
break;
case Actions::MoveSE:
++uYnew;
if ((uYnew & 1) == 0) ++uXnew;
break;
case Actions::MoveSW:
++uYnew;
if ((uYnew & 1) == 1) --uXnew;
break;
case Actions::TurnCW:
newUnit.rotate(true);
break;
case Actions::TurnCCW:
newUnit.rotate(false);
break;
}
if (!unitPath.Verify(uXnew, uYnew, newUnit.Orient())) {
return VerifyState::Fail;
}
if (newUnit.Check(field, uXnew, uYnew)) { // can be placed
if (!verify) {
last.code.push_back(a);
curUnit.Apply(field, uX, uY, true); // erase
curUnit = newUnit;
uX = uXnew;
uY = uYnew;
curUnit.Apply(field, uX, uY); // draw
unitPath.Save(uX, uY, curUnit.Orient());
}
return VerifyState::Pass;
} else {
if (!verify) {
last.code.push_back(a);
curUnit.Lock(field, uX, uY); // lock
int sz = curUnit.size();
int lines = field.simplify();
int pts = sz + 50 * lines * (lines + 1);
curScore += pts + (lastLines - 1) * pts / 10;
lastLines = lines;
}
return VerifyState::Lock;
}
}
long icfp2015::Simulate::run(Solution &sol) {
/*bool needFigure = true;
field.reset();
gen.reset();
last.reset();
curScore = 0;
lastLines = 0;
for (Actions a : sol.code) {
if (needFigure && !nextUnit()) {
break;
}
needFigure = !step(a);
}
return score();*/
return 0;
}
Solution icfp2015::Simulate::Moves() {
return last;
}