/
brick.cpp
43 lines (37 loc) · 893 Bytes
/
brick.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
// See LICENSE file for copyright and license details.
#include "brick.h"
#include <cstdio>
void Brick::print_no_rot(int a, int b) {
// const char *s = "(%i|%i)";
// const char *s = "[%i:%i]";
const char *s = "%i-%i";
printf(s, a, b);
}
Brick::Brick(int left, int right, bool is_rotated)
: is_rotated(is_rotated),
left(left),
right(right)
{
}
void Brick::print() {
if (is_rotated) {
print_no_rot(left, right);
} else {
print_no_rot(right, left);
}
}
bool Brick::can_connect(const Brick *brick) {
return left == brick->left
|| left == brick->right
|| right == brick->left
|| right == brick->right;
}
void print_bricks_list(const BricksList *list) {
for (BricksList::const_iterator it = list->begin();
it != list->end(); ++it)
{
(*it)->print();
putchar(' ');
}
putchar('\n');
}