-
Notifications
You must be signed in to change notification settings - Fork 2
/
cell.cpp
162 lines (143 loc) · 3.72 KB
/
cell.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*************************
* cell.cpp
* editor: amo
*************************/
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <bitset>
#include <cmath>
#include <vector>
#include <cell.h>
#include <algorithm> // std::for_each, copy
#include <iterator> // std::back_inserter
#include <stack>
#include <map>
using namespace amo;
/* -------------------------------------------------------------------- */
/* my define macro */
/* -------------------------------------------------------------------- */
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
/* -------------------------------------------------------------------- */
/* global variables */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* implements */
/* -------------------------------------------------------------------- */
std::istream& amo::operator>>(std::istream& is, Cell& cell) {
is >> cell.status;
return is;
}
std::ostream& amo::operator<<(std::ostream& os, Cell& cell) {
switch (cell.status) {
case AVAL:
os << "AVAL /";
break;
case ROUTE:
os << "ROUTE/";
break;
case BACK:
os << "BACK /";
break;
case WALL:
os << "WALL /";
break;
default:
os << "ERROR /";
break;
}
switch (cell.in) {
case INIT:
os << "INIT /";
break;
case EAST:
os << "EAST /";
break;
case SOUTH:
os << "SOUTH/";
break;
case WEST:
os << "WEST /";
break;
case NORTH:
os << "NORTH/";
break;
case DEAD:
os << "DEAD /";
break;
default:
os << "ERROR/";
break;
}
switch (cell.out) {
case INIT :
os << "INIT ";
break;
case EAST:
os << "EAST ";
break;
case SOUTH:
os << "SOUTH";
break;
case WEST:
os << "WEST ";
break;
case NORTH:
os << "NORTH";
break;
case DEAD:
os << "DEAD ";
break;
default:
os << "ERROR";
break;
}
return os;
}
amo::Cell::Cell(): x(0), y(0), status(AVAL), in(INIT), out(INIT) {
std::cout << "[Cell::Cell()]:" << this << std::endl;
}
amo::Cell::Cell(int i, int j): x(i), y(j), status(AVAL), in(INIT), out(INIT) {
std::cout << "[Cell::Cell(int,int)]:" << this << ", x:" << x << ", y:" << y << std::endl;
}
amo::Cell::Cell(const Cell& c) {
x = c.x;
y = c.y;
status = c.status;
in = c.in;
out = c.out;
std::cout << "[Cell::Cell(Cell&)]:" << this << ", x:" << x << ", y:" << y << std::endl;
}
amo::Cell::~Cell() {
std::cout << "[Cell::~Cell()]:" << this << ", x:" << x << ", y:" << y << std::endl;
}
amo::Cell& amo::Cell::operator=(const amo::Cell& c) {
x = c.x;
y = c.y;
status = c.status;
in = c.in;
out = c.out;
std::cout << "[Cell::operator=(Cell&)]:" << this << ", x:" << c.x << ", y:" << c.y << std::endl;
return *this;
}
bool amo::Cell::operator==(const amo::Cell& c) {
bool ret = false;
ret &= (x == c.x);
ret &= (y == c.y);
ret &= (status == c.status);
ret &= (in == c.in);
ret &= (out = c.out);
//std::cout << "[Cell::operator==(Cell&)]:" << this << ", returns:" << ret << std::endl;
return ret;
}