sober-bishop/main.go

72 lines
1.2 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-05 09:53:11 +00:00
var (
// 4x4 board with node counts
2022-02-06 14:50:07 +00:00
StartingBoard = map[int]int{
2022-02-05 10:45:14 +00:00
10: 2, 11: 3, 12: 3, 13: 3,
20: 1, 21: 4, 22: 5, 23: 9,
30: 0, 31: 2, 32: 2, 33: 4,
40: 0, 41: 1, 42: 3, 43: 0,
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) {
// Found possible path
if s == 20 {
return true, append(paths, p)
}
// deincrement the starting point
b[s] -= 1
2022-02-05 10:45:14 +00:00
2022-02-06 14:50:07 +00:00
// what are M valid directions
NW := s - 11
NE := s - 9
SW := s + 9
SE := s + 11
2022-02-05 10:45:14 +00:00
2022-02-06 14:50:07 +00:00
if b[NW] != 0 { // NW
ok, r := FindMove(NW, b, (p + "NW"))
if ok {
paths = append(paths, r...)
}
2022-02-05 10:45:14 +00:00
}
2022-02-06 14:50:07 +00:00
if b[NE] != 0 { // NE
ok, r := FindMove(NE, b, (p + "NE"))
if ok {
paths = append(paths, r...)
}
2022-02-05 10:45:14 +00:00
}
2022-02-06 14:50:07 +00:00
if b[SW] != 0 { // SW
ok, r := FindMove(SW, b, (p + "SW"))
if ok {
paths = append(paths, r...)
}
2022-02-05 10:45:14 +00:00
}
2022-02-06 14:50:07 +00:00
if b[SE] != 0 { // SE
ok, r := FindMove(SE, b, (p + "SE"))
if ok {
paths = append(paths, r...)
}
2022-02-05 10:45:14 +00:00
}
2022-02-06 14:50:07 +00:00
return true, paths
}
func main() {
// queue := make(chan int, 4)
// walk and find nodes
// := FindPath()
board := StartingBoard
board[22] -= 1
_, moves := FindMove(22, board, "")
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
}