try for dice

master
ironbound 2022-02-07 00:30:46 +01:00
parent bc2b34edc6
commit 9943a38260
1 changed files with 35 additions and 33 deletions

68
main.go
View File

@ -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 {