-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pos.h
54 lines (48 loc) · 1.78 KB
/
Pos.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
// Copyright 2024 Benjamin Yankowitz.
// This file is part of NetHack Sokoban Solver.
// NetHack Sokoban Solver is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
// NetHack Sokoban Solver is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with Foobar. If not, see <https://www.gnu.org/licenses/>.
#ifndef _POS__H__
#define _POS__H__
#include "typedef.h"
#include "HashMap.h"
#include <ostream>
struct Pos{
constexpr Pos(): y(0), x(0){};
constexpr Pos(myChar y_, myChar x_): y(y_), x(x_) {}
inline constexpr bool operator==(Pos other) const{
return y==other.y&&x==other.x;
}
inline constexpr bool operator!=(Pos other) const{
return y!=other.y||x!=other.x;
}
inline constexpr Pos& operator+=(Pos other){
y+=other.y;
x+=other.x;
return *this;
}
inline constexpr Pos& operator-=(Pos other){
y-=other.y;
x-=other.x;
return *this;
}
inline constexpr Pos operator-(Pos other) const{
return Pos(y-other.y,x-other.x);
}
inline constexpr Pos operator+(Pos other) const{
return Pos(y+other.y,x+other.x);
}
myChar y;
myChar x;
};
template <>
struct MyHash<Pos> {
constexpr static std::size_t hash(Pos input) {
return (static_cast<std::size_t>(input.x) << 8) + input.y;
}
};
inline std::ostream& operator<<(std::ostream& out, Pos ob){
return out << (int)ob.x << ',' << (int)ob.y;
}
#endif