This repository was archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCubeRandomizer.cs
More file actions
82 lines (78 loc) · 1.55 KB
/
CubeRandomizer.cs
File metadata and controls
82 lines (78 loc) · 1.55 KB
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RubiksCubeSolver
{
public class CubeRandomizer
{
public Cube CreateRandomCube()
{
var cube = new Cube();
DoRandomTurns(cube);
return cube;
}
public void DoRandomTurns(Cube cube)
{
var random = new Random();
//randomize how many turns
int turnCount = random.Next(100);
//generate random turns
var turns = new int[turnCount];
for (int i = 0; i < turnCount; i++)
{
turns[i] = random.Next(12);
}
//apply turns
foreach (var turnId in turns)
{
applyAction(cube, turnId);
}
}
private void applyAction(Cube cube, int turnId)
{
Debug.Assert(turnId < 12 && turnId >= 0);
switch (turnId)
{
case 0:
cube.RotateBackCCWAsync().Wait();
break;
case 1:
cube.RotateBackCWAsync().Wait();
break;
case 2:
cube.RotateBottomCCWAsync().Wait();
break;
case 3:
cube.RotateBottomCWAsync().Wait();
break;
case 4:
cube.RotateFrontCCWAsync().Wait();
break;
case 5:
cube.RotateFrontCWAsync().Wait();
break;
case 6:
cube.RotateLeftCCWAsync().Wait();
break;
case 7:
cube.RotateLeftCWAsync().Wait();
break;
case 8:
cube.RotateRightCCWAsync().Wait();
break;
case 9:
cube.RotateRightCWAsync().Wait();
break;
case 10:
cube.RotateTopCCWAsync().Wait();
break;
case 11:
cube.RotateTopCWAsync().Wait();
break;
}
}
}
}