try for dice
parent
bc2b34edc6
commit
9943a38260
68
main.go
68
main.go
|
@ -10,11 +10,19 @@ type posTable struct {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// 4x4 board with node counts
|
// 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{
|
StartingBoard = map[int]int{
|
||||||
10: 2, 11: 3, 12: 3, 13: 3,
|
10: 0, 11: 0, 12: 0, 13: 2,
|
||||||
20: 1, 21: 4, 22: 5, 23: 9,
|
20: 0, 21: 0, 22: 3, 23: 0,
|
||||||
30: 0, 31: 2, 32: 2, 33: 4,
|
30: 0, 31: 6, 32: 0, 33: 1,
|
||||||
40: 0, 41: 1, 42: 3, 43: 0,
|
40: 4, 41: 0, 42: 1, 43: 0,
|
||||||
|
50: 0, 51: 0, 52: 0, 53: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
mTable = []posTable{
|
mTable = []posTable{
|
||||||
|
@ -33,50 +41,44 @@ var (
|
||||||
|
|
||||||
rTable = []posTable{
|
rTable = []posTable{
|
||||||
{offset: 9, bits: "00"},
|
{offset: 9, bits: "00"},
|
||||||
{offset: 11, bits: "01"},
|
{offset: 10, bits: "01"},
|
||||||
{offset: 9, add: true, bits: "10"},
|
{offset: 9, add: true, bits: "10"},
|
||||||
{offset: 11, add: true, bits: "11"},
|
{offset: 10, add: true, bits: "11"},
|
||||||
}
|
}
|
||||||
|
|
||||||
bTable = []posTable{
|
bTable = []posTable{
|
||||||
{offset: 1, bits: "00"},
|
{offset: 1, bits: "00"},
|
||||||
{offset: 0, bits: "01"},
|
{offset: 0, bits: "01"},
|
||||||
{offset: 9, add: true, bits: "10"},
|
{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) {
|
func FindMove(s int, b map[int]int, p string) (ok bool, paths []string) {
|
||||||
// finsh point found return path
|
// finsh point found return path
|
||||||
if s == 20 {
|
if s == 42 {
|
||||||
return true, append(paths, p)
|
return true, append(paths, p)
|
||||||
}
|
}
|
||||||
// deincrement spot count
|
// deincrement current spot
|
||||||
b[s] -= 1
|
b[s] -= 1
|
||||||
|
|
||||||
// // T moves
|
// Tables to pick from
|
||||||
// // map[int]bool{10:true, 11:true, 12:true}
|
searchTable := []posTable{}
|
||||||
// NW := s - 1
|
if tSpots[s] {
|
||||||
// NE := s + 1
|
searchTable = tTable
|
||||||
// SW := s + 9
|
} else if s == 13 {
|
||||||
// SE := s + 11
|
searchTable = bTable
|
||||||
|
} else if rSpots[s] {
|
||||||
|
searchTable = rTable
|
||||||
|
} else {
|
||||||
|
searchTable = mTable
|
||||||
|
}
|
||||||
|
|
||||||
// // b move
|
// check for valid spots in table
|
||||||
// if s == 13 {
|
for _, n := range searchTable {
|
||||||
// }
|
|
||||||
// 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
|
var spot int
|
||||||
// check if op is positive or negitive
|
// check if op is positive or negitive
|
||||||
if n.add {
|
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
|
// Check next spot is avaliable
|
||||||
if b[spot] != 0 {
|
if b[spot] > 0 {
|
||||||
ok, r := FindMove(spot, b, (p + n.bits))
|
ok, r := FindMove(spot, b, (p + n.bits))
|
||||||
if ok {
|
if ok {
|
||||||
paths = append(paths, r...)
|
paths = append(paths, r...)
|
||||||
|
@ -98,7 +100,7 @@ func FindMove(s int, b map[int]int, p string) (ok bool, paths []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
_, moves := FindMove(22, StartingBoard, "")
|
_, moves := FindMove(51, StartingBoard, "")
|
||||||
|
|
||||||
// Get valid nodes
|
// Get valid nodes
|
||||||
for _, n := range moves {
|
for _, n := range moves {
|
||||||
|
|
Loading…
Reference in New Issue