package main

import (
	"log"
	"runtime"
	"strconv"

	"gitea.ligthert.net/golang/sudoku-funpark/flags"
	"gitea.ligthert.net/golang/sudoku-funpark/solver"
)

func main() {
	// Instantiate the interfaces
	solver := solver.Solver{}
	flags := flags.Flags{}

	// Parse and handle flags
	flags.ParseFlags()
	flags.TransferConfig(&solver)

	// Report number of CPUs being used, if set.
	if runtime.NumCPU() != solver.NumCPUs {
		log.Println("Using " + strconv.Itoa(solver.NumCPUs) + " CPUs, (was " + strconv.Itoa(runtime.NumCPU()) + ")")
	}

	// Load blocks from CSV file
	solver.LoadBlocks()

	// Find rows that fit with the entered rows
	solver.PopulateBlocks()

	// If needed, split the workload
	// May exit and throw an error if the work load isn't viable
	if solver.Split != 1 {
		solver.SelectWorkload()
	}

	// Print the total number of solutions to validate
	log.Println("Number of (potential) solutions:", solver.Iter)

	// Check the number of solutions
	go solver.CheckCombinations()
	solver.Tracker()

	// Print the valid solutions
	solver.PrintSolutions()
}