add tables and loop next spot check

master
ironbound 2022-02-06 17:24:39 +01:00
parent 5710801758
commit bc2b34edc6
1 changed files with 72 additions and 36 deletions

108
main.go
View File

@ -2,6 +2,12 @@ package main
import "fmt"
type posTable struct {
bits string
offset int
add bool
}
var (
// 4x4 board with node counts
StartingBoard = map[int]int{
@ -10,44 +16,81 @@ var (
30: 0, 31: 2, 32: 2, 33: 4,
40: 0, 41: 1, 42: 3, 43: 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: 11, bits: "01"},
{offset: 9, add: true, bits: "10"},
{offset: 11, add: true, bits: "11"},
}
bTable = []posTable{
{offset: 1, bits: "00"},
{offset: 0, bits: "01"},
{offset: 9, add: true, bits: "10"},
{offset: 11, add: true, bits: "11"},
}
)
func FindMove(s int, b map[int]int, p string) (ok bool, paths []string) {
// Found possible path
// finsh point found return path
if s == 20 {
return true, append(paths, p)
}
// deincrement the starting point
// deincrement spot count
b[s] -= 1
// what are M valid directions
NW := s - 11
NE := s - 9
SW := s + 9
SE := s + 11
// // T moves
// // map[int]bool{10:true, 11:true, 12:true}
// NW := s - 1
// NE := s + 1
// SW := s + 9
// SE := s + 11
if b[NW] != 0 { // NW
ok, r := FindMove(NW, b, (p + "NW"))
if ok {
paths = append(paths, r...)
// // b move
// if s == 13 {
// }
// NW := s - 1
// NE := s
// SW := s + 9
// SE := s + 10
// // R moves
// map[int]bool{23: true, 33: true, 43: true}
// NW := s - 11
// NE := s - 10
// SW := s + 9
// SE := s + 11
for _, n := range mTable {
var spot int
// check if op is positive or negitive
if n.add {
spot = s + n.offset
} else {
spot = s - n.offset
}
}
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...)
// Check next spot is avaliable
if b[spot] != 0 {
ok, r := FindMove(spot, b, (p + n.bits))
if ok {
paths = append(paths, r...)
}
}
}
@ -55,14 +98,7 @@ func FindMove(s int, b map[int]int, p string) (ok bool, paths []string) {
}
func main() {
// queue := make(chan int, 4)
// walk and find nodes
// := FindPath()
board := StartingBoard
board[22] -= 1
_, moves := FindMove(22, board, "")
_, moves := FindMove(22, StartingBoard, "")
// Get valid nodes
for _, n := range moves {