/
main.go
67 lines (63 loc) · 1.62 KB
/
main.go
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
package main
import (
"bufio"
"flag"
"fmt"
"github.com/davidafox/rubikscubesolver/bytecube"
"github.com/davidafox/rubikscubesolver/combined"
"github.com/davidafox/rubikscubesolver/rubikscuberunner"
"log"
"os"
"runtime/pprof"
"time"
)
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var depth = flag.Int("depth", 6, "specify the depth to use breadth-first seach")
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
fmt.Println("Enter cube state with numbers 0-5 representing the colors starting with the Side facing you and going clockwise around the cube followed by the top and then the bottom. Type quit to quit.")
fmt.Println("Example: 000000000111111111222222222333333333444444444555555555")
scanner := bufio.NewScanner(os.Stdin)
valid := false
var err error
var c *bytecube.Cube
for !valid {
scanner.Scan()
state := scanner.Text()
if state == "quit" {
return
}
c, err = bytecube.NewCube(state)
if err != nil {
fmt.Println(err)
} else {
valid, err = c.Validate()
if err != nil {
fmt.Println(err)
}
}
}
if c.Solved() {
fmt.Println("The cube is already solved.")
return
}
cf := combined.NewFactory()
r := rubikscuberunner.NewOfficialRunner(c)
// r.Run("R U' B' L F R' U2 F2 L' D R U L'")
s := combined.NewSolver(c.String(), cf, *depth)
startTime := time.Now()
solution := s.Solve()
runtime := time.Since(startTime)
r.Run(solution)
fmt.Println(solution)
fmt.Println("Time: ", runtime)
fmt.Println("Solved: ", c.Solved())
}