A complete JavaScript project for solving Block Sudoku puzzle via Machine Learning Genetic Algorithm.
Try it yourself now! >> https://hashempour.github.io/GaBlockSudoku/
It was easy for me to have all Visual Features, Coding, and most importantlty Web features on one side together, therefore I could concentrrate on the algorithm implementation more! ;)
Since this project is an AI project and contains Machine Learning, another language, which can utilise the CPU and RAM best, would be a more sensible choice. But for most of other languages, like JAVA od C++, C#, etc. I had more limits for Visualisation part and it's needed to put more efforts to implement the game process on the screen. Therefore with JavaScript I did all the visualisation and AI process faster together but due to web browser restrictions, it cannot utilise all the CPU capabilities for learning. One another proper language choicw coule be Python, since it's powerful in visualisation and can utilise the CPU and RAM better than JavaScript.
Why not! Due to COVID-19 restrictions, these days I had a lot of spare time in HOME to think about a hobby or fun project!
I don't think so! You are welcome to find the probable bugs or some improvement on the implemented Algorithm :)
aX + bY + cZ + dW + eQ + f + gT + hS = 0
X: cols integrity (%)
Y: rows integrity (%)
Z: 9-blocks integrity (%)
W: total occupation (%)
Q: selected element occupation (%)
T: row/col/blockSet completeness (%)
S: board total integrity (%)
Chromosome DNA: { a, b, c, d, e, f, g, h }
All DNAs are random float numbers between -10.00 and +10.00 (with 2 number precisions)
Default Population Count: 100
Since all the data is on the client side, you could easy watch the algorithm and scripts, and also changed the data run-time inside Browser Debugger tool.
PLAY_TIME_MS = 50;
Change it into the time (in milisecond) you want the learning process steps goes on
Default value is 50
HALT_LEARNING = true;
Change it into true in case you want to halt the learning process
Default value is false
DEBUG_MODE = 0;
0: no debug message
1: some debug info
2: full debug info
Default value is 0
VISUALISE = 2;
0: no visualisation at all
1: just Text Info like Generation Number, Score, etc.
2: full Visualisation including the play sitation on board
Default is 2
GENETICS
you can find almost all variable/const and feature data like population, POPULATION_COUNT here.
GENETICS.population
An array of current population chromosome
GENETICS.populationGameScore
An array of last play score of each chromosome
Array boundry is 0 to GENETICS.POPULATION_COUNT
GENETICS.populationAvgSuccessRates
An array of avg play score of each chromosome
Each array item includes an object of S and C
S is the Average score of all plays and C is the count of play for that chrmosome
Note: C and S will reset to Zero when the chromosome is reborn or regenerated
Array boundry is 0 to GENETICS.POPULATION_COUNT
myChromosome = {
"a": -6.36,
"b": -7.96,
"c": -3.64,
"d": -8.84,
"e": -0.95,
"f": -3.73,
"g": 6.66,
"h": 1.15
};
Define your chromosome; then the custome play would use to solve the puzzle
It is undefined by default
The myChromosome DNA data will be automatically defined by the best Chromosome DNA data at the end of each learning generation.
Also you can find/copy the best Chromosome (DNAs) data from GENETICS.populationGameScore after a learning process and choosing the one according to GENETICS.populationAvgSuccessRates