test basic moves

master
ironbound 2022-02-06 15:50:07 +01:00
parent 40d9640271
commit 5710801758
1 changed files with 49 additions and 18 deletions

67
main.go
View File

@ -4,7 +4,7 @@ import "fmt"
var (
// 4x4 board with node counts
board = map[int]int{
StartingBoard = map[int]int{
10: 2, 11: 3, 12: 3, 13: 3,
20: 1, 21: 4, 22: 5, 23: 9,
30: 0, 31: 2, 32: 2, 33: 4,
@ -12,29 +12,60 @@ var (
}
)
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
// what are M valid directions
NW := s - 11
NE := s - 9
SW := s + 9
SE := s + 11
if b[NW] != 0 { // NW
ok, r := FindMove(NW, b, (p + "NW"))
if ok {
paths = append(paths, r...)
}
}
if b[NE] != 0 { // NE
ok, r := FindMove(NE, b, (p + "NE"))
if ok {
paths = append(paths, r...)
}
}
if b[SW] != 0 { // SW
ok, r := FindMove(SW, b, (p + "SW"))
if ok {
paths = append(paths, r...)
}
}
if b[SE] != 0 { // SE
ok, r := FindMove(SE, b, (p + "SE"))
if ok {
paths = append(paths, r...)
}
}
return true, paths
}
func main() {
q := make(chan int, 4)
// queue := make(chan int, 4)
// board[p]
p := 22
// walk and find nodes
// := FindPath()
if board[p-11] != 0 { // NW
q <- (p - 11)
}
if board[p-9] != 0 { // NE
q <- (p - 9)
}
if board[p+9] != 0 { // SW
q <- (p + 9)
}
if board[p+11] != 0 { // SE
q <- (p + 11)
}
close(q)
board := StartingBoard
board[22] -= 1
_, moves := FindMove(22, board, "")
// Get valid nodes
for n := range q {
for _, n := range moves {
fmt.Println(n)
}
}