-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosition.cpp
More file actions
131 lines (89 loc) · 2.98 KB
/
Position.cpp
File metadata and controls
131 lines (89 loc) · 2.98 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
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
//
// Position.cpp
// BCAI
//
// Created by Max Botviniev on 13.11.15.
// Copyright © 2015 Max Botviniev. All rights reserved.
//
#include "Position.hpp"
namespace BCAI {
Position & Position::operator = (const Position & other) {
x = other.x;
y = other.y;
return * this;
}
bool Position::operator == ( Position & other )const {
return this->x == other.x && this->y == other.y;
}
std::ostream & operator<<(std::ostream & os, Position & pos)
{
os << "( X: " << pos.x << ", " << "Y: " << pos.y << ")";
return os;
}
//-------------------------
//-------------------------
IndexPair::IndexPair() {
x_v = -666;
y_v = -999; // Index begins from 0, that's why: -1
}
IndexPair::IndexPair(int _x_v, int _y_v) {
x_v = _x_v;
y_v = _y_v;
//std::cout << "Created from INT: " << * this << std::endl;
}
IndexPair::IndexPair( char _x_v, char _y_v ) {
x_v = _x_v - 'A';
y_v = _y_v - '0' -1; // Index begins from 0, that's why: -1
//std::cout << "Created from CHARs: " << *this << std::endl;
}
IndexPair::IndexPair( const IndexPair & other ) {
//std::cout << "COPY: " << other << " TO: " << * this << std::endl;
x_v = other.x_v;
y_v = other.y_v;
}
IndexPair::IndexPair( const Position & pos ) {
x_v = pos.x - 'A';
y_v = pos.y - 1; // Index begins from 0, that's why: -1
}
bool IndexPair::OnBoard() {
return x_v > -1 && x_v < 8 && y_v > -1 && y_v < 8;
}
IndexPair IndexPair::Abs(const IndexPair & other) {
return IndexPair( std::abs(other.x_v), std::abs(other.y_v) );
}
template <typename T> int Sign(T val) {
return (T(0) < val) - (val < T(0));
}
IndexPair IndexPair::Normilized() {
return IndexPair(Sign(x_v), Sign(y_v));
}
IndexPair IndexPair::Direction(IndexPair to) {
return to - * this;
}
void IndexPair::operator += (const IndexPair & other) {
this->x_v += other.x_v;
this->y_v += other.y_v;
}
IndexPair IndexPair::operator + (const IndexPair & other) {
return IndexPair( x_v + other.x_v, y_v + other.y_v );
}
IndexPair IndexPair::operator - (const IndexPair & other) {
return IndexPair(x_v - other.x_v, y_v - other.y_v);
}
void IndexPair::operator = (IndexPair & other) {
//std::cout << "ASSIGMENT: " << other << " TO: " << * this << std::endl;
x_v = other.x_v;
y_v = other.y_v;
}
bool IndexPair::operator == ( IndexPair & other ) const {
return x_v == other.x_v && y_v == other.y_v;
}
bool IndexPair::operator > ( IndexPair & other ) const {
return this->x_v > other.x_v && this->y_v > other.y_v;
}
std::ostream & operator << (std::ostream & os, const IndexPair & indexes)
{
os << "( x_i: " << indexes.x_v << ", " << "y_i: " << indexes.y_v << ")";
return os;
}
}