-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy paththe-last-crusade-episode-1.cpp
132 lines (115 loc) · 3.54 KB
/
the-last-crusade-episode-1.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#define DEBUG 0 // Display debug infos
#define TYPES 14 // Number of pieces types
using namespace std;
struct Piece
{
int x; // X pos
int y; // Y pos
int type;// type
Piece(const int p_x,
const int p_y,
const int p_type): x(p_x), y(p_y), type(p_type)
{};
// Output when enters from RIGHT
void r(void) const
{
switch(type)
{
case 1: cout << x << " " << y+1 << endl; break;
case 2: cout << x-1 << " " << y << endl; break;
case 4: cout << x << " " << y+1 << endl; break;
case 6: cout << x-1 << " " << y << endl; break;
case 7: cout << x << " " << y+1 << endl; break;
case 8: cout << x << " " << y+1 << endl; break;
case 12: cout << x << " " << y+1 << endl; break;
default: break;
}
}
// Output when enters from LEFT
void l(void) const
{
switch(type)
{
case 1: cout << x << " " << y+1 << endl; break;
case 2: cout << x+1 << " " << y << endl; break;
case 5: cout << x << " " << y+1 << endl; break;
case 6: cout << x+1 << " " << y << endl; break;
case 8: cout << x << " " << y+1 << endl; break;
case 9: cout << x << " " << y+1 << endl; break;
case 13:cout << x << " " << y+1 << endl; break;
default: break;
}
}
// Output when enters from TOP
void t(void) const
{
switch(type)
{
case 1: cout << x << " " << y+1 << endl; break;
case 3: cout << x << " " << y+1 << endl; break;
case 4: cout << x-1 << " " << y << endl; break;
case 5: cout << x+1 << " " << y << endl; break;
case 7: cout << x << " " << y+1 << endl; break;
case 9: cout << x << " " << y+1 << endl; break;
case 10:cout << x-1 << " " << y << endl; break;
case 11:cout << x+1 << " " << y << endl; break;
default: break;
}
}
// Output wherever you come from
void out(const int p_from) const
{
switch(p_from)
{
case 0: r(); break;
case 1: l(); break;
case 2: t(); break;
default:r(); break;
}
}
};
ostream& operator<<(ostream& os, const Piece& p_current)
{
return ( os << "T" << p_current.type << ":X"
<< p_current.x << ":Y" << p_current.y << endl );
}
int main()
{
int W, H;
cin >> W >> H; cin.ignore();
vector< Piece > array;
map<string, int> moves;
moves["RIGHT"] = 0; moves["LEFT"] = 1; moves["TOP"] = 2;
for (int i = 0; i < H; i++)
{
string LINE;
getline(cin, LINE);
istringstream iss(LINE);
string s;
int cmpt = 0;
while ( getline( iss, s, ' ' ) )
{
int tmp_type = atoi(s.c_str());
array.push_back(Piece(cmpt++, i, tmp_type));
if(DEBUG) cerr << " " << s;
}
if(DEBUG) cerr << endl;
}
if(DEBUG)
std::for_each(std::begin(array),
std::end (array), [](Piece& it){ cerr << it; } );
int EX; cin >> EX; cin.ignore();
// game loop
while (1) {
int XI, YI;
string POS;
cin >> XI >> YI >> POS; cin.ignore();
array[YI*W + XI].out(moves[POS]);
}
}