sober-bishop/main.go

110 lines
2.1 KiB
Go
Raw Normal View History

2022-02-05 09:53:11 +00:00
package main
2022-02-05 10:45:14 +00:00
import "fmt"
2022-02-06 16:24:39 +00:00
type posTable struct {
bits string
offset int
add bool
}
2022-02-05 09:53:11 +00:00
var (
// 4x4 board with node counts
2022-02-06 23:30:46 +00:00
// 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{'
2022-02-06 14:50:07 +00:00
StartingBoard = map[int]int{
2022-02-06 23:30:46 +00:00
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,
2022-02-05 09:53:11 +00:00
}
2022-02-06 16:24:39 +00:00
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"},
2022-02-06 23:30:46 +00:00
{offset: 10, bits: "01"},
2022-02-06 16:24:39 +00:00
{offset: 9, add: true, bits: "10"},
2022-02-06 23:30:46 +00:00
{offset: 10, add: true, bits: "11"},
2022-02-06 16:24:39 +00:00
}
bTable = []posTable{
{offset: 1, bits: "00"},
{offset: 0, bits: "01"},
{offset: 9, add: true, bits: "10"},
2022-02-06 23:30:46 +00:00
{offset: 10, add: true, bits: "11"},
2022-02-06 16:24:39 +00:00
}
2022-02-06 23:30:46 +00:00
tSpots = map[int]bool{10: true, 11: true, 12: true, 13: true}
rSpots = map[int]bool{23: true, 33: true, 43: true}
2022-02-05 09:53:11 +00:00
)
2022-02-06 14:50:07 +00:00
func FindMove(s int, b map[int]int, p string) (ok bool, paths []string) {
2022-02-06 16:24:39 +00:00
// finsh point found return path
2022-02-06 23:30:46 +00:00
if s == 42 {
2022-02-06 14:50:07 +00:00
return true, append(paths, p)
}
2022-02-06 23:30:46 +00:00
// deincrement current spot
2022-02-06 14:50:07 +00:00
b[s] -= 1
2022-02-05 10:45:14 +00:00
2022-02-06 23:30:46 +00:00
// 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
}
2022-02-06 16:24:39 +00:00
2022-02-06 23:30:46 +00:00
// check for valid spots in table
for _, n := range searchTable {
2022-02-06 16:24:39 +00:00
var spot int
// check if op is positive or negitive
if n.add {
spot = s + n.offset
} else {
spot = s - n.offset
2022-02-06 14:50:07 +00:00
}
2022-02-06 16:24:39 +00:00
// Check next spot is avaliable
2022-02-06 23:30:46 +00:00
if b[spot] > 0 {
2022-02-06 16:24:39 +00:00
ok, r := FindMove(spot, b, (p + n.bits))
if ok {
paths = append(paths, r...)
}
2022-02-06 14:50:07 +00:00
}
2022-02-05 10:45:14 +00:00
}
2022-02-06 14:50:07 +00:00
return true, paths
}
func main() {
2022-02-06 23:30:46 +00:00
_, moves := FindMove(51, StartingBoard, "")
2022-02-05 09:53:11 +00:00
2022-02-05 10:45:14 +00:00
// Get valid nodes
2022-02-06 14:50:07 +00:00
for _, n := range moves {
2022-02-05 10:45:14 +00:00
fmt.Println(n)
}
2022-02-05 09:53:11 +00:00
}