-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
90 lines (78 loc) · 1.6 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* vim: set sts=4 sw=4 ts=4 noet: */
/**
* jass - just another sudoku solver
* (C) 2005-2019 Jari Tenhunen <jait@iki.fi>
*
* Go version copyright 2019
*/
package main
import (
"bufio"
"flag"
"fmt"
"jassgo/jass"
"log"
"os"
)
func main() {
game := &jass.Game{}
game.Init()
/* check args
* -f: read sudokus from file (- for stdin)
*/
var fname string
var step, verbose bool
flag.BoolVar(&step, "s", false, "step mode, pause after each solved number")
flag.BoolVar(&verbose, "v", false, "verbose debug output")
flag.StringVar(&fname, "f", "", "instead looking for the puzzle string in the arguments, read puzzles from `file` (\"-\" for stdin), one per line")
flag.Parse()
if step && !verbose {
verbose = true
}
if verbose {
jass.SetLogLevel(jass.LogDebug)
}
if step {
game.SetMode(jass.StepMode)
}
if fname != "" {
var file *os.File
var err error
if fname == "-" {
file = os.Stdin
} else {
file, err = os.Open(fname)
if err != nil {
log.Fatal(err)
}
defer file.Close()
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
str := scanner.Text()
if len(str) == 0 || str[0] == '#' {
continue
}
game.Init()
game.ParseBoard(str)
fmt.Println(str)
game.Solve()
}
if err = scanner.Err(); err != nil {
log.Fatal(err)
}
} else {
// try if there was a puzzle as argument
args := flag.Args()
if len(args) == 0 {
jass.Info("Error: no puzzle(s) given")
jass.Info("Usage: jass [options] [<puzzle>]")
flag.PrintDefaults()
}
for _, str := range args {
game.Init()
game.ParseBoard(str)
game.Solve()
}
}
}