-
Notifications
You must be signed in to change notification settings - Fork 0
/
Position.h
62 lines (49 loc) · 1.73 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// Created by Piotr Kamiński on 22/05/2022.
//
#ifndef BOMBERMANSERVER_POSITION_H
#define BOMBERMANSERVER_POSITION_H
#include <iostream>
#include "types.h"
#include "common.h"
namespace bomberman {
struct Position {
board_size_t positionX{};
board_size_t positionY{};
constexpr Position() = default;
explicit Position(socket_t &socket) {
read_number_inplace(socket, positionX);
read_number_inplace(socket, positionY);
}
constexpr Position(board_size_t x, board_size_t y) : positionX(x), positionY(y) {
}
bool operator==(const Position &other) const {
return (positionX == other.positionX) && (positionY == other.positionY);
}
Position operator+(Position const &other) const {
Position added;
added.positionX = positionX + other.positionX;
added.positionY = positionY + other.positionY;
return added;
}
Position operator*(explosion_radius_t multiplier) const {
Position added;
added.positionX = positionX * multiplier;
added.positionY = positionY * multiplier;
return added;
}
friend std::ostream &operator<<(std::ostream &os, const Position &position) {
return os << '(' << position.positionX << ", " << position.positionY << ')';
}
};
}
namespace std {
template<>
struct hash<bomberman::Position> {
size_t operator()(const bomberman::Position &position) const {
return hash<bomberman::board_size_t>()(position.positionX) ^
hash<bomberman::board_size_t>()(position.positionY);
}
};
}
#endif //BOMBERMANSERVER_POSITION_H