aboutsummaryrefslogtreecommitdiff
path: root/rubiks.go
diff options
context:
space:
mode:
authorNat Lasseter <nat.lasseter@exa.net.uk>2019-07-16 11:14:38 +0100
committerNat Lasseter <nat.lasseter@exa.net.uk>2019-07-16 11:14:38 +0100
commitac3bf7d594a515dcd238c8e369960b89720f26c1 (patch)
tree3cb575c81b8bb91ab148e1f3e0ec66acff7f5c63 /rubiks.go
Initial commit
Diffstat (limited to 'rubiks.go')
-rw-r--r--rubiks.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/rubiks.go b/rubiks.go
new file mode 100644
index 0000000..3ecf605
--- /dev/null
+++ b/rubiks.go
@@ -0,0 +1,61 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+ "rubiks/cube"
+ "strconv"
+ "strings"
+)
+
+func handle(c *cube.Cube, cmd string) {
+ cmd = strings.ToLower(strings.TrimSpace(cmd))
+ switch cmd {
+ case "q":
+ os.Exit(0)
+ case "u":
+ c.U()
+ case "u'":
+ c.U_()
+ case "d":
+ c.D()
+ case "d'":
+ c.D_()
+ case "r":
+ c.R()
+ case "r'":
+ c.R_()
+ case "l":
+ c.L()
+ case "l'":
+ c.L_()
+ case "f":
+ c.F()
+ case "f'":
+ c.F_()
+ case "b":
+ c.B()
+ case "b'":
+ c.B_()
+ }
+}
+
+func main() {
+ s := 3
+ if len(os.Args) > 1 {
+ s, _ = strconv.Atoi(os.Args[1])
+ }
+
+ c, _ := cube.New(s)
+ scanner := bufio.NewScanner(os.Stdin)
+
+ fmt.Print(c)
+ fmt.Print(">: ")
+ for scanner.Scan() {
+ handle(c, scanner.Text())
+ fmt.Println()
+ fmt.Print(c)
+ fmt.Print(">: ")
+ }
+}