]>
Commit | Line | Data |
---|---|---|
0e27f67c SW |
1 | package main |
2 | ||
2bf3412d | 3 | import "flag" |
0e27f67c SW |
4 | import "fmt" |
5 | import "os" | |
2bf3412d | 6 | import "reflect" |
0e27f67c SW |
7 | import "strconv" |
8 | ||
2bf3412d SW |
9 | import "github.com/petar/GoLLRB/llrb" |
10 | import "github.com/willf/bloom" | |
11 | ||
12 | var bloomsize = flag.Int("bloomsize", 2000000, "Size bloomfilter for this many states.") | |
13 | ||
0e27f67c | 14 | const HOLE = 0 |
2c35054f SW |
15 | const BOARD_DIM = 4 |
16 | const BOARD_SIZE = BOARD_DIM * BOARD_DIM | |
0e27f67c SW |
17 | |
18 | type Space int8 | |
19 | type Board [BOARD_SIZE]Space | |
2bf3412d SW |
20 | type Step struct { |
21 | board Board | |
22 | prev *Step | |
23 | length int | |
24 | } | |
0e27f67c | 25 | |
2c35054f SW |
26 | const ( |
27 | LEFT = -1 | |
28 | RIGHT = +1 | |
29 | UP = -BOARD_DIM | |
30 | DOWN = +BOARD_DIM | |
31 | ) | |
32 | ||
0e27f67c | 33 | func read_board_from_strings(in []string) (*Board, error) { |
212a5629 SW |
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 | |
0e27f67c SW |
46 | } |
47 | ||
2c35054f SW |
48 | func 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 | ||
2bf3412d SW |
68 | func create_successors(start *Step) { |
69 | for _, adj := adjacent_spaces(start. | |
70 | } | |
71 | ||
72 | func 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 | ||
0e27f67c | 78 | func main() { |
2bf3412d SW |
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) | |
212a5629 | 86 | if err != nil { |
2bf3412d SW |
87 | fmt.Println(err) |
88 | os.Exit(1) | |
212a5629 | 89 | } |
0e27f67c | 90 | } |