Sep 23, 2012

Sudoku on the NXT

Not exactly a robot (in that there are no motors), but Leon is showing off some great programming skills by cramming an entire Soduku engine into the NXT.  It displays the grid on the NXT screen and you use the NXT Brick buttons to navigate around and enter in the numbers.

The software has several levels of difficulty, and generates a completely random game every time.

From the article

So here’s how it works:
  1. The user selects a difficulty (the higher the difficulty, the less visible clues) using the left and right arrow keys and then clicks the orange button
  2. A completely random Sudoku is generated and displayed on the screen
  3. The arrow keys are used for navigating the grid: the left key moves the cursor over one spot to the left, and the right arrow key moves the cursor down one spot. If the user reaches a side/ corner, the next arrow click will bring the cursor to the other side of the playing field, as illustrated below:
  1. Clicking the square orange key when an editable cell is selected (“clue” cells aren’t editable) will increment the cell’s value by 1, unless its value is 9, in which case the cell will be reset to 0
  2. Clicking the rectangular gray key will check the user’s version of the sudoku against the answer key (a copy of the generated sudoku without the non-clue cells removed), and tell the user how many errors there are. If there aren’t any, a “You win!” message will appear and the program will be aborted; if there are errors (including un-solved cells), the user will be asked if he/ she wants the wrong cells reset — if yes, the program will clear these cells, if no, they’ll remain wrong and the user will return to the game

Leon describes the whole project in 4 separate posts, and it's a great read to see the process someone goes through when developing such a program.
Start here - http://worldofmindstorms.com/2012/07/19/sudoku-part-1/ and work your way through.
Source code is available on the last page.


No comments:

Related Posts Plugin for WordPress, Blogger...