From: Scott Worley Date: Mon, 28 Dec 2015 22:40:28 +0000 (-0800) Subject: Read a board from the command line X-Git-Url: http://git.scottworley.com/slidingtile/commitdiff_plain/0e27f67c88ac6fac3cce4cfdf6856e94cd716154?ds=inline Read a board from the command line --- 0e27f67c88ac6fac3cce4cfdf6856e94cd716154 diff --git a/sliding_tile.go b/sliding_tile.go new file mode 100644 index 0000000..a934b4e --- /dev/null +++ b/sliding_tile.go @@ -0,0 +1,34 @@ +package main + +import "fmt" +import "os" +import "strconv" + +const HOLE = 0 +const BOARD_SIZE = 16 + +type Space int8 +type Board [BOARD_SIZE]Space + +func read_board_from_strings(in []string) (*Board, error) { + if len(in) != BOARD_SIZE { + return nil, fmt.Errorf("Please provide %d values", BOARD_SIZE) + } + var b Board + for i, s := range in { + num, err := strconv.Atoi(s) + b[i] = Space(num) + if err != nil { + return nil, err + } + } + return &b, nil +} + +func main() { + start, err := read_board_from_strings(os.Args[1:]) + if err != nil { + panic(err) + } + fmt.Println(start) +}