/
NimStateHelper.cs
57 lines (41 loc) · 1.51 KB
/
NimStateHelper.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
using System.Collections.Generic;
namespace Nim {
public static class NimStateHelper {
public static readonly NimState StartingNimState = new NimState(3, 5, 7);
public static bool IsCompatibleWith(this NimState from, NimState to) {
return GetDiff(from, to) == 1;
}
public static int GetDiff(this NimState from, NimState to) {
int diff = 0;
if (from.X == to.X)
diff++;
if (from.Y == to.Y)
diff++;
if (from.Z == to.Z)
diff++;
return diff;
}
public static List<NimState> GetPossibleStates(this NimState state) {
List<NimState> states = new List<NimState>();
for (int i = 1; i <= state.XReal; i++) {
NimState tempState = state.Clone();
tempState.XReal -= i;
if (tempState.HasValidMoves())
states.Add(tempState);
}
for (int i = 1; i <= state.YReal; i++) {
NimState tempState = state.Clone();
tempState.YReal -= i;
if (tempState.HasValidMoves())
states.Add(tempState);
}
for (int i = 1; i <= state.ZReal; i++) {
NimState tempState = state.Clone();
tempState.ZReal -= i;
if (tempState.HasValidMoves())
states.Add(tempState);
}
return states;
}
}
}