From 9943a38260e43293a25aebca7641aa07ecfa8630 Mon Sep 17 00:00:00 2001 From: ironbound Date: Mon, 7 Feb 2022 00:30:46 +0100 Subject: [PATCH] try for dice --- main.go | 68 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/main.go b/main.go index 7b7683f..f71b57d 100644 --- a/main.go +++ b/main.go @@ -10,11 +10,19 @@ type posTable struct { 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: 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, + 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{ @@ -33,50 +41,44 @@ var ( rTable = []posTable{ {offset: 9, bits: "00"}, - {offset: 11, bits: "01"}, + {offset: 10, bits: "01"}, {offset: 9, add: true, bits: "10"}, - {offset: 11, add: true, bits: "11"}, + {offset: 10, 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"}, + {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 == 20 { + if s == 42 { return true, append(paths, p) } - // deincrement spot count + // deincrement current spot b[s] -= 1 - // // T moves - // // map[int]bool{10:true, 11:true, 12:true} - // NW := s - 1 - // NE := s + 1 - // SW := s + 9 - // SE := s + 11 + // 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 + } - // // 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 { + // check for valid spots in table + for _, n := range searchTable { var spot int // check if op is positive or negitive if n.add { @@ -86,7 +88,7 @@ func FindMove(s int, b map[int]int, p string) (ok bool, paths []string) { } // Check next spot is avaliable - if b[spot] != 0 { + if b[spot] > 0 { ok, r := FindMove(spot, b, (p + n.bits)) if ok { paths = append(paths, r...) @@ -98,7 +100,7 @@ func FindMove(s int, b map[int]int, p string) (ok bool, paths []string) { } func main() { - _, moves := FindMove(22, StartingBoard, "") + _, moves := FindMove(51, StartingBoard, "") // Get valid nodes for _, n := range moves {