]> git.scottworley.com Git - slidingtile/blame_incremental - sliding_tile.go
Incomplete thoughts
[slidingtile] / sliding_tile.go
... / ...
CommitLineData
1package main
2
3import "flag"
4import "fmt"
5import "os"
6import "reflect"
7import "strconv"
8
9import "github.com/petar/GoLLRB/llrb"
10import "github.com/willf/bloom"
11
12var bloomsize = flag.Int("bloomsize", 2000000, "Size bloomfilter for this many states.")
13
14const HOLE = 0
15const BOARD_DIM = 4
16const BOARD_SIZE = BOARD_DIM * BOARD_DIM
17
18type Space int8
19type Board [BOARD_SIZE]Space
20type Step struct {
21 board Board
22 prev *Step
23 length int
24}
25
26const (
27 LEFT = -1
28 RIGHT = +1
29 UP = -BOARD_DIM
30 DOWN = +BOARD_DIM
31)
32
33func read_board_from_strings(in []string) (*Board, error) {
34 if len(in) != BOARD_SIZE {
35 return nil, fmt.Errorf("Please provide %d values", BOARD_SIZE)
36 }
37 var b Board
38 for i, s := range in {
39 num, err := strconv.Atoi(s)
40 b[i] = Space(num)
41 if err != nil {
42 return nil, err
43 }
44 }
45 return &b, nil
46}
47
48func adjacent_spaces(s Space) []Space {
49 if s < 0 || s >= BOARD_SIZE {
50 panic("Invalid space")
51 }
52 var adjacent []Space
53 if s >= BOARD_DIM {
54 adjacent = append(adjacent, s+UP)
55 }
56 if s < BOARD_SIZE-BOARD_DIM {
57 adjacent = append(adjacent, s+DOWN)
58 }
59 if s%BOARD_DIM != 0 {
60 adjacent = append(adjacent, s+LEFT)
61 }
62 if s%BOARD_DIM != BOARD_DIM-1 {
63 adjacent = append(adjacent, s+RIGHT)
64 }
65 return adjacent
66}
67
68func create_successors(start *Step) {
69 for _, adj := adjacent_spaces(start.
70}
71
72func sliding_tile(start *Board) error {
73 seen := bloom.NewWithEstimates(uint(*bloomsize), 0.0001)
74 seen.Add(reflect.ValueOf(*start).Bytes())
75 return nil
76}
77
78func main() {
79 flag.Parse()
80 start, err := read_board_from_strings(flag.Args())
81 if err != nil {
82 fmt.Println(err)
83 os.Exit(1)
84 }
85 err = sliding_tile(start)
86 if err != nil {
87 fmt.Println(err)
88 os.Exit(1)
89 }
90}