Make godoc happy, and add extra comments.
This commit is contained in:
@ -13,6 +13,7 @@ import (
|
||||
//go:embed blocks.csv
|
||||
var f embed.FS
|
||||
|
||||
// Load all possible blocks from CSV in to memory
|
||||
func (solver *Solver) LoadBlocks() {
|
||||
|
||||
defer solver.timeTrack(time.Now(), "Loaded blocks")
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Find all possible blocks that can be used to find a solution.
|
||||
func (solver *Solver) PopulateBlocks() {
|
||||
|
||||
defer solver.timeTrack(time.Now(), "Populated blocks")
|
||||
@ -26,6 +27,7 @@ func (solver *Solver) PopulateBlocks() {
|
||||
|
||||
}
|
||||
|
||||
// The actual function that finds the blocks matching the partial blocks.
|
||||
func (solver *Solver) findBlocks(row *string, rows *[]int) {
|
||||
// Declare selection
|
||||
var selection []int
|
||||
@ -61,6 +63,7 @@ func (solver *Solver) findBlocks(row *string, rows *[]int) {
|
||||
*rows = selection
|
||||
}
|
||||
|
||||
// Iterate through all combination of blocks and validate them.
|
||||
func (solver *Solver) CheckCombinations() {
|
||||
for rows1Index := range solver.row1s {
|
||||
for rows2Index := range solver.row2s {
|
||||
@ -83,6 +86,7 @@ func (solver *Solver) CheckCombinations() {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the provided rows and verify it is a valid solution.
|
||||
func (solver *Solver) validator(rows1Index int, rows2Index int, rows3Index int, rows4Index int, rows5Index int, rows6Index int, rows7Index int, rows8Index int, rows9Index int) {
|
||||
|
||||
solver.counter.Add(1)
|
||||
@ -93,6 +97,8 @@ func (solver *Solver) validator(rows1Index int, rows2Index int, rows3Index int,
|
||||
|
||||
}
|
||||
|
||||
// Keep track and output progress.
|
||||
// Calculate rates, display percentages, estimate the ETA till completion.
|
||||
func (solver *Solver) Tracker() {
|
||||
|
||||
// Add time tracking
|
||||
@ -187,6 +193,7 @@ func (solver *Solver) Tracker() {
|
||||
|
||||
}
|
||||
|
||||
// Validate combination
|
||||
func (solver *Solver) validateCombination(row1 int, row2 int, row3 int, row4 int, row5 int, row6 int, row7 int, row8 int, row9 int) (retval bool) {
|
||||
retval = true
|
||||
|
||||
@ -242,6 +249,7 @@ func (solver *Solver) validateCombination(row1 int, row2 int, row3 int, row4 int
|
||||
return retval
|
||||
}
|
||||
|
||||
// Calculate the average rate in a stored slice of rates.
|
||||
func (solver *Solver) calcAVG() (avg int64) {
|
||||
var avgSum int64
|
||||
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Perform some checks
|
||||
// and
|
||||
// Modify solver.row1s so it limits the workload to what is only desired.
|
||||
// Renders workload for an agent.
|
||||
// Checks if this feature can be used, otherwise exits.
|
||||
// Modify solver.row1s so it limits the workload to what is only desired
|
||||
func (solver *Solver) SelectWorkload() {
|
||||
if solver.Controller.Split > len(solver.row1s) {
|
||||
log.Println("ERROR: Unable to divide the workload in " + strconv.Itoa(solver.Controller.Split) + " parts, when only " + strconv.Itoa(len(solver.row1s)) + " are available.\n\n")
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Prepare a valid solution for storage.
|
||||
func (solver *Solver) renderCombination(row1 int, row2 int, row3 int, row4 int, row5 int, row6 int, row7 int, row8 int, row9 int) string {
|
||||
|
||||
row1s := strconv.Itoa(row1)
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// A simple function to track time
|
||||
// Use with `defer`
|
||||
func (solver *Solver) timeTrack(start time.Time, msg string) {
|
||||
elapsed := time.Since(start)
|
||||
log.Printf("%s (%s)", msg, elapsed)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"gitea.ligthert.net/golang/sudoku-funpark/controller"
|
||||
)
|
||||
|
||||
// Struct/Interface containing all the important variabes it functions need access to.
|
||||
// Solve a given Sudoku puzzle by iterating through all possible solutions.
|
||||
type Solver struct {
|
||||
Controller *controller.Controller
|
||||
row1s []int
|
||||
|
Reference in New Issue
Block a user