-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDirection.cs
149 lines (103 loc) · 5.47 KB
/
Direction.cs
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
namespace Hexagony
{
abstract class Direction : IEquatable<Direction>
{
public static readonly Direction East = new East();
public static readonly Direction SouthEast = new SouthEast();
public static readonly Direction SouthWest = new SouthWest();
public static readonly Direction West = new West();
public static readonly Direction NorthWest = new NorthWest();
public static readonly Direction NorthEast = new NorthEast();
public abstract Direction ReflectAtSlash { get; }
public abstract Direction ReflectAtBackslash { get; }
public abstract Direction ReflectAtUnderscore { get; }
public abstract Direction ReflectAtPipe { get; }
public abstract Direction ReflectAtLessThan(bool positive);
public abstract Direction ReflectAtGreaterThan(bool positive);
public abstract PointAxial Vector { get; }
public abstract bool Equals(Direction other);
public override bool Equals(object obj) => obj is Direction other && Equals(other);
public static bool operator ==(Direction a, Direction b) => a is not null && a.Equals(b);
public static bool operator !=(Direction a, Direction b) => a is not null && !a.Equals(b);
public abstract override int GetHashCode();
}
sealed class NorthEast : Direction
{
public override Direction ReflectAtSlash => NorthEast;
public override Direction ReflectAtBackslash => West;
public override Direction ReflectAtUnderscore => SouthEast;
public override Direction ReflectAtPipe => NorthWest;
public override Direction ReflectAtLessThan(bool positive) => SouthWest;
public override Direction ReflectAtGreaterThan(bool positive) => East;
public override PointAxial Vector => new(1, -1);
public override int GetHashCode() => 245;
public override bool Equals(Direction other) => other is NorthEast;
public override string ToString() => "NE";
}
sealed class NorthWest : Direction
{
public override Direction ReflectAtSlash => East;
public override Direction ReflectAtBackslash => NorthWest;
public override Direction ReflectAtUnderscore => SouthWest;
public override Direction ReflectAtPipe => NorthEast;
public override Direction ReflectAtLessThan(bool positive) => West;
public override Direction ReflectAtGreaterThan(bool positive) => SouthEast;
public override PointAxial Vector => new(0, -1);
public override int GetHashCode() => 2456;
public override bool Equals(Direction other) => other is NorthWest;
public override string ToString() => "NW";
}
sealed class West : Direction
{
public override Direction ReflectAtSlash => SouthEast;
public override Direction ReflectAtBackslash => NorthEast;
public override Direction ReflectAtUnderscore => West;
public override Direction ReflectAtPipe => East;
public override Direction ReflectAtLessThan(bool positive) => East;
public override Direction ReflectAtGreaterThan(bool positive) => positive ? NorthWest : SouthWest;
public override PointAxial Vector => new(-1, 0);
public override int GetHashCode() => 24567;
public override bool Equals(Direction other) => other is West;
public override string ToString() => "W";
}
sealed class SouthWest : Direction
{
public override Direction ReflectAtSlash => SouthWest;
public override Direction ReflectAtBackslash => East;
public override Direction ReflectAtUnderscore => NorthWest;
public override Direction ReflectAtPipe => SouthEast;
public override Direction ReflectAtLessThan(bool positive) => West;
public override Direction ReflectAtGreaterThan(bool positive) => NorthEast;
public override PointAxial Vector => new(-1, 1);
public override int GetHashCode() => 245678;
public override bool Equals(Direction other) => other is SouthWest;
public override string ToString() => "SW";
}
sealed class SouthEast : Direction
{
public override Direction ReflectAtSlash => West;
public override Direction ReflectAtBackslash => SouthEast;
public override Direction ReflectAtUnderscore => NorthEast;
public override Direction ReflectAtPipe => SouthWest;
public override Direction ReflectAtLessThan(bool positive) => NorthWest;
public override Direction ReflectAtGreaterThan(bool positive) => East;
public override PointAxial Vector => new(0, 1);
public override int GetHashCode() => 2456783;
public override bool Equals(Direction other) => other is SouthEast;
public override string ToString() => "SE";
}
sealed class East : Direction
{
public override Direction ReflectAtSlash => NorthWest;
public override Direction ReflectAtBackslash => SouthWest;
public override Direction ReflectAtUnderscore => East;
public override Direction ReflectAtPipe => West;
public override Direction ReflectAtLessThan(bool positive) => positive ? SouthEast : NorthEast;
public override Direction ReflectAtGreaterThan(bool positive) => West;
public override PointAxial Vector => new(1, 0);
public override int GetHashCode() => 24567837;
public override bool Equals(Direction other) => other is East;
public override string ToString() => "E";
}
}