-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ship.cpp
79 lines (74 loc) · 1.6 KB
/
Ship.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
/*
* Ship.cpp
*
* Created on: Feb 27, 2022
* Author: jacobadamsky
*/
#include "Ship.h"
#include <algorithm>
namespace std {
Ship::~Ship() {
}
void Ship::print() {
printf("ID: %d, start: < %d, %d >, verical: %s, length: %d", this->id, this->start.x, this->start.y, vert ? "vertical" : "horizontal",
this->len);
}
bool Ship::intersecting(Ship ship) {
if (this->start == ship.start) {
return true;
}
if (this->end == ship.end) {
return true;
}
if (this->vert == ship.vert) {
if (this->vert) {
if (this->start.x == ship.start.x) {
if (this->end.y < ship.end.y && this->end.y >= ship.start.y) {
return true;
}
}
else if (ship.start.x != this->start.x) {
return false;
}
}
if (!this->vert) {
if (this->start.y == ship.start.y) {
if (this->end.x < ship.end.x && this->end.x >= ship.start.x) {
return true;
}
}
else if (ship.start.y != this->start.y) {
return false;
}
}
}
else {
if (this->vert) {
if (this->start.x >= ship.start.x) {
if (this->start.x <= ship.end.x) {
if (this->end.y >= ship.end.y) {
return true;
}
}
}
}
else {
if (this->start.y >= ship.start.y) {
if (this->start.y <= ship.end.y) {
if (this->end.x >= ship.end.x) {
return true;
}
}
}
}
for (std::Pair pair1 : ship.coords) {
for (std::Pair pair2 : this->coords) {
if (pair1 == pair2) {
return true;
}
}
}
}
return false;
}
} /* namespace std */