-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.cs
111 lines (96 loc) · 2.66 KB
/
Util.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TicTacToe
{
public class Util
{
public static int ApplyTransform(int position, Transform transform)
{
if (transform.Flip)
{
position = Flip(position);
}
for (int i = 0; i < transform.Rotate; i++)
{
position = RotateRight(position);
}
return position;
}
public static int RotateLeft(int position)
{
switch (position)
{
case 0: return 6;
case 1: return 3;
case 2: return 0;
case 3: return 7;
case 4: return 4;
case 5: return 1;
case 6: return 8;
case 7: return 5;
case 8: return 2;
}
return -1;
}
public static int RotateRight(int position)
{
switch (position)
{
case 0: return 2;
case 1: return 5;
case 2: return 8;
case 3: return 1;
case 4: return 4;
case 5: return 7;
case 6: return 0;
case 7: return 3;
case 8: return 6;
}
return -1;
}
public static int Flip(int position)
{
switch (position)
{
case 0: return 2;
case 1: return 1;
case 2: return 0;
case 3: return 5;
case 4: return 4;
case 5: return 3;
case 6: return 8;
case 7: return 7;
case 8: return 6;
}
return -1;
}
public static string Int32ToString(int value, int toBase)
{
string result = string.Empty;
while (value > 0)
{
result = "012"[value % toBase] + result;
value /= toBase;
}
while (result.Length < 9)
{
result = '0' + result;
}
return result;
}
public static State GenerateState(int seed)
{
string preamble = Util.Int32ToString(seed, 3);
int ones = preamble.Count(t => t == '1');
int twos = preamble.Count(t => t == '2');
if (Math.Abs(ones - twos) <= 1)
{
var state = new State(preamble);
}
return new State();
}
}
}