110 lines
2.1 KiB
Go
110 lines
2.1 KiB
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type posTable struct {
|
|
bits string
|
|
offset int
|
|
add bool
|
|
}
|
|
|
|
var (
|
|
// 4x4 board with node counts
|
|
// StartingBoard = map[int]int{
|
|
// 10: 2, 11: 3, 12: 3, 13: 3,
|
|
// 20: 1, 21: 4, 22: 5, 23: 16,
|
|
// 30: 0, 31: 2, 32: 2, 33: 4,
|
|
// 40: 0, 41: 1, 42: 3, 43: 0,
|
|
// }
|
|
// spell try to spell 'dice{'
|
|
StartingBoard = map[int]int{
|
|
10: 0, 11: 0, 12: 0, 13: 2,
|
|
20: 0, 21: 0, 22: 3, 23: 0,
|
|
30: 0, 31: 6, 32: 0, 33: 1,
|
|
40: 4, 41: 0, 42: 1, 43: 0,
|
|
50: 0, 51: 0, 52: 0, 53: 0,
|
|
}
|
|
|
|
mTable = []posTable{
|
|
{offset: 11, bits: "00"},
|
|
{offset: 9, bits: "01"},
|
|
{offset: 9, add: true, bits: "10"},
|
|
{offset: 11, add: true, bits: "11"},
|
|
}
|
|
|
|
tTable = []posTable{
|
|
{offset: 1, bits: "00"},
|
|
{offset: 1, add: true, bits: "01"},
|
|
{offset: 9, add: true, bits: "10"},
|
|
{offset: 11, add: true, bits: "11"},
|
|
}
|
|
|
|
rTable = []posTable{
|
|
{offset: 9, bits: "00"},
|
|
{offset: 10, bits: "01"},
|
|
{offset: 9, add: true, bits: "10"},
|
|
{offset: 10, add: true, bits: "11"},
|
|
}
|
|
|
|
bTable = []posTable{
|
|
{offset: 1, bits: "00"},
|
|
{offset: 0, bits: "01"},
|
|
{offset: 9, add: true, bits: "10"},
|
|
{offset: 10, add: true, bits: "11"},
|
|
}
|
|
|
|
tSpots = map[int]bool{10: true, 11: true, 12: true, 13: true}
|
|
rSpots = map[int]bool{23: true, 33: true, 43: true}
|
|
)
|
|
|
|
func FindMove(s int, b map[int]int, p string) (ok bool, paths []string) {
|
|
// finsh point found return path
|
|
if s == 42 {
|
|
return true, append(paths, p)
|
|
}
|
|
// deincrement current spot
|
|
b[s] -= 1
|
|
|
|
// Tables to pick from
|
|
searchTable := []posTable{}
|
|
if tSpots[s] {
|
|
searchTable = tTable
|
|
} else if s == 13 {
|
|
searchTable = bTable
|
|
} else if rSpots[s] {
|
|
searchTable = rTable
|
|
} else {
|
|
searchTable = mTable
|
|
}
|
|
|
|
// check for valid spots in table
|
|
for _, n := range searchTable {
|
|
var spot int
|
|
// check if op is positive or negitive
|
|
if n.add {
|
|
spot = s + n.offset
|
|
} else {
|
|
spot = s - n.offset
|
|
}
|
|
|
|
// Check next spot is avaliable
|
|
if b[spot] > 0 {
|
|
ok, r := FindMove(spot, b, (p + n.bits))
|
|
if ok {
|
|
paths = append(paths, r...)
|
|
}
|
|
}
|
|
}
|
|
|
|
return true, paths
|
|
}
|
|
|
|
func main() {
|
|
_, moves := FindMove(51, StartingBoard, "")
|
|
|
|
// Get valid nodes
|
|
for _, n := range moves {
|
|
fmt.Println(n)
|
|
}
|
|
}
|