-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition.h
38 lines (32 loc) · 1.24 KB
/
position.h
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
#pragma once
#include <iostream>
// Stores a position on the chessboard. Accepts positions outside of chessboard, but will throw exceptions when trying to write them out
struct Position {
private:
int x_;
int y_;
public:
Position();
Position(int posX, int posY);
// Sets the horizontal position
void x(int newX);
// Sets the vertical position
void y(int newY);
// Gets the horizontal position in int form
int x() const;
// Gets the vertical position in int form
int y() const;
bool on_chessboard() const;
// Compares two positions by x and y
bool operator==(const Position& other) const;
// Compares two positions by x and y
bool operator!=(const Position& other) const;
Position operator+(const Position& other) const;
Position& operator+=(const Position& other);
Position operator-(const Position& other) const;
Position& operator-=(const Position& other);
// Representation in form of "yx" where x will be converted to char from range a-h, y stays as a number. If outside of range (1-8), throws exception
friend std::ostream& operator<<(std::ostream& out, const Position& pos);
// Accepts two forms of representation, "xy" and "yx". Char part will always be the x
friend std::istream& operator>>(std::istream& in, Position& pos);
};