-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshapepuzzle.go
82 lines (67 loc) · 1.66 KB
/
shapepuzzle.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// -*- tab-width: 4; -*-
// Package main for the shapepuzzle program.
package main
import (
"fmt"
"log"
"runtime"
"github.com/garyjg/shapepuzzle/board"
"github.com/garyjg/shapepuzzle/shape"
)
// There are 8 permutations for every shape: flipped over or not, then
// four rotations for each side up.
// getShapes generates the shapes for a specific shape puzzle to be solved.
//
func getShapes() []shape.Shape {
grids := [][][]int{{
{1, 1, 0}, {1, 1, 1}}, {
{1, 0, 1}, {1, 1, 1}}, {
{1, 0, 0, 0, 0}, {1, 1, 1, 1, 1}}, {
{1, 1, 1, 1}, {1, 0, 0, 1}}, {
{1, 1, 1}, {1, 1, 1}, {0, 1, 1}}, {
{0, 1, 0}, {1, 1, 1}, {0, 1, 0}}, {
{0, 1, 0}, {0, 1, 0}, {1, 1, 1}}, {
{0, 0, 1, 1}, {1, 1, 1, 1}}, {
{0, 1, 1}, {1, 1, 0}, {1, 0, 0}}, {
{1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {1, 1, 1, 1}}, {
{1, 0, 0, 0}, {1, 1, 1, 1}, {1, 0, 0, 0}}}
return shape.MakeShapes(grids)
}
type _NullWriter struct {
}
func (nw _NullWriter) Write(b []byte) (n int, err error) {
return len(b), nil
}
func main() {
logenable := false
runtime.GOMAXPROCS(8)
log.SetFlags(0)
if !logenable {
log.SetOutput(_NullWriter{})
}
b := board.NewBoard(8, 8)
shapes := getShapes()
nshapes := len(shapes)
for i := 0; i < nshapes; i++ {
s := &shapes[i]
perms := s.Permutations()
for _, p := range perms {
log.Printf(p.String())
}
}
fmt.Printf("Initial board:\n%v", b)
bc := b.Solve(shapes)
nfound := 0
for b := range bc {
fmt.Printf("Solution found.\n")
fmt.Printf("%s\n", b)
nfound++
}
if nfound == 0 {
fmt.Printf("No solution found.\n")
} else if nfound == 1 {
fmt.Printf("One solution found.\n")
} else {
fmt.Printf("%d solutions found.\n", nfound)
}
}