-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
game; not just a generator/solver (#2)
- Loading branch information
Showing
33 changed files
with
1,288 additions
and
522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ | |
.coverprofile | ||
/.idea/ | ||
/dist | ||
/go-sudoku | ||
/go-sudoku.exe | ||
/go-sudoku* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,31 +10,45 @@ default: run | |
|
||
all: test | ||
|
||
build: | ||
go build . | ||
build: build-game build-generator | ||
|
||
demo: build | ||
./go-sudoku generate | ||
./go-sudoku -type jigsaw generate | ||
./go-sudoku -type samurai generate | ||
build-game: | ||
go build -o go-sudoku ./cmd/game | ||
|
||
demo-solve: build | ||
./go-sudoku -format csv generate | ./go-sudoku -progress solve | ||
build-generator: | ||
go build -o go-sudoku-generator ./cmd/generator | ||
|
||
dist: | ||
demo-generator: build-generator | ||
./go-sudoku-generator generate | ||
./go-sudoku-generator -type jigsaw generate | ||
./go-sudoku-generator -type samurai generate | ||
|
||
demo-solver: build-generator | ||
./go-sudoku-generator -format csv generate | ./go-sudoku-generator -progress solve | ||
|
||
dist: dist-game dist-generator | ||
|
||
dist-game: | ||
gox -ldflags="-s -w -X main.version=${VERSION}" \ | ||
-os="linux darwin windows" \ | ||
-arch="amd64" \ | ||
-output="./dist/go-sudoku_{{.OS}}_{{.Arch}}_${VERSION}" \ | ||
./cmd/game | ||
|
||
dist-generator: | ||
gox -ldflags="-s -w -X main.version=${VERSION}" \ | ||
-os="linux darwin windows" \ | ||
-arch="amd64" \ | ||
-output="./dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \ | ||
. | ||
-output="./dist/go-sudoku-generator_{{.OS}}_{{.Arch}}_${VERSION}" \ | ||
./cmd/generator | ||
|
||
fmt: tidy | ||
go fmt $(shell go list ./...) | ||
|
||
gen: gen-readme | ||
|
||
gen-readme: build | ||
./scripts/generate_readme.sh > README.md | ||
./docs/generate_readme.sh > README.md | ||
|
||
get-tools: | ||
go install github.com/mitchellh/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import "github.com/jedib0t/go-sudoku/sudoku" | ||
|
||
func handleActionHelp() { | ||
numOccurringMost, numOccurrencesMost := 1, 0 | ||
for n := 1; n <= 9; n++ { | ||
numOccurrences := grid.CountValue(n) | ||
if numOccurrences > numOccurrencesMost { | ||
numOccurringMost = n | ||
numOccurrencesMost = numOccurrences | ||
} | ||
} | ||
|
||
easiestBlock := cursor | ||
var possibilities *sudoku.Possibilities | ||
for x := 0; x < 9; x++ { | ||
for y := 0; y < 9; y++ { | ||
p := grid.Possibilities(x, y) | ||
if p != nil && (possibilities == nil || possibilities.AvailableLen() > p.AvailableLen()) { | ||
easiestBlock = sudoku.Location{X: x, Y: y} | ||
possibilities = p | ||
|
||
// stop early if we've found a number that occurs most, and fits | ||
// a block like nothing else | ||
if possibilities.AvailableLen() == 1 && possibilities.AvailableMap()[numOccurringMost] { | ||
cursor = easiestBlock | ||
return | ||
} | ||
} | ||
} | ||
} | ||
cursor = easiestBlock | ||
} | ||
|
||
func handleActionQuit() { | ||
userQuit = true | ||
} | ||
|
||
func handleActionReset() { | ||
renderMutex.Lock() | ||
defer renderMutex.Unlock() | ||
|
||
generateSudoku() | ||
} | ||
|
||
func handleActionInput(char rune) { | ||
renderMutex.Lock() | ||
defer renderMutex.Unlock() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/jedib0t/go-sudoku/sudoku/difficulty" | ||
"github.com/jedib0t/go-sudoku/sudoku/pattern" | ||
) | ||
|
||
var ( | ||
difficulties = strings.ToLower(strings.Join(difficulty.Names(), "/")) | ||
patterns = strings.ToLower(strings.Join(pattern.Names(), "/")) | ||
|
||
flagAllowWrong = flag.Bool("allow-wrong", false, "Allow incorrect values?") | ||
flagDemo = flag.Bool("demo", false, "play automatically? (this cheats to win)") | ||
flagDifficulty = flag.String("difficulty", "medium", "Difficulty ("+difficulties+")") | ||
flagHelp = flag.Bool("help", false, "Show this help-text?") | ||
flagHints = flag.Bool("hints", false, "Highlight possible values in the Keyboard?") | ||
flagPattern = flag.String("pattern", "", "Pattern to use instead of Difficulty ("+patterns+")") | ||
flagRefreshRate = flag.Int("refresh-rate", 20, "Refresh-rate per second") | ||
flagSeed = flag.Int64("seed", 0, "Randomizer Seed value (will use random number if ZERO)") | ||
flagShowWrong = flag.Bool("show-wrong", false, "Highlight incorrect values in Red?") | ||
) | ||
|
||
func initFlags() { | ||
flag.Parse() | ||
if *flagHelp { | ||
printHelp() | ||
} | ||
|
||
gameDiff = difficulty.From(*flagDifficulty) | ||
gamePtrn = pattern.Get(*flagPattern) | ||
if *flagSeed == 0 { | ||
*flagSeed = time.Now().UnixNano() % 10000 | ||
} | ||
rng = rand.New(rand.NewSource(*flagSeed)) | ||
} | ||
|
||
func printHelp() { | ||
fmt.Println(`go-sudoku: A GoLang implementation of the Sudoku game. | ||
Version: ` + version + ` | ||
Flags | ||
=====`) | ||
flag.PrintDefaults() | ||
os.Exit(0) | ||
} |
Oops, something went wrong.