Situation:
You are a mathematics teacher in a primary school and you want to develop an Android
application to train junior students how to play with Sudoku. To let them get familiar
with Sudoku, the application is based on a simpler version with a 4×4 playing board. A
typical 4×4 Sudoku puzzle is shown below:
4 3 1 2
2 1 4 3
3 4 2 1
1 2 3 4
A player wins if the final 4×4 Sudoku puzzle satisfies the following two conditions:
1) Condition 1: Each column, each row, and each of the four 2×2 sub-grids that compose
the grid contains all of the digits from 1 to 4.
2) Condition 2: The same single integer may not appear twice in the same 4×4 playing
board row or column or in any of the four 2×2 sub-grids.
You application should provide two basic levels for the user to choose from:
1) Level 1: The player is allowed to fill in a completely-blank Sudoku puzzle. Upon
clicking a “Submit” button, your application should check whether it is correct (i.e.
both Condition 1 and Condition 2 above are satisfied) and then display a correctness
message to inform the player.
2) Level 2: The player is allowed to fill in a partially-filled Sudoku puzzle. Upon
clicking a “Submit” button, your application should check whether it is correct (i.e.
both Condition 1 and Condition 2 above are satisfied) and then display a correctness
message to inform the player.
Steps:
You should develop your Android application by following the steps below:
1) Design three pages. The first page contains a menu for the user to choose Level 1 or
Level 2. This page should also contain your name and university number for
identification purpose. The second page contains a Level 1 instance. The third page
contains a Level 2 instance. The user should be able to go from the first page to the
second or the third page or from the second or the third page back to the first page
conveniently.
2) For both Level 1 and Level 2, design a user interface which contains one 4×4 table,
one Button for submitting the answer and one TextView for displaying the
correctness message. Inside the table, each cell in turn contains one EditText field.
3) Implement an answer checking function to tell whether the input answer forms a
correct Sudoku matrix (i.e. both Condition 1 and Condition 2 above are satisfied).
4) Implement a listener for the button. Upon th e button is clicked, the answer checking
function is invoked and the correctness message is then displayed.
5) For Level 2, construct a puzzle generator to generate a partially-filled Sudoku puzzle
at random. The puzzle should have 8 cells blank and there must be a correct solution
for the instance concerned.
Hint 1: You may first make use of the following Java codes to generate a correct
Sudoku matrix and then “properly” shuffle some rows or columns or rotate the
generated matrix to obtain a random instance.
int n = 2;
int[][] field = new int[n*n][n*n];
for (int i = 0; i < n*n; i ++)
for (int j = 0; j < n*n; j ++)
field[i][j] = (i*n + i/n + j) % (n*n) + 1;
Hint 2: You may need to use the setText() function of the EditText class to set values
of EditText fields.
|