How can we help the player out a little without solving the whole puzzle for them? How about if we draw the background of each tile differently depending on how many possible moves it has. Add this to onDraw() before drawing the selection:

// Pick a hint color based on #moves left Paint hint = new Paint();

int c[] = { getResources().getColor(R.color.puzzle_hint_0), getResources().getColor(R.color.puzzle_hint_1), getResources().getColor(R.color.puzzle_hint_2), }; Rect r = new Rect(); for (int i =0; i <9; i++) { for (int j =0; j <9; j++) {

int movesleft = 9 - game.getUsedTiles(i, j).length; if (movesleft < c.length) { getRect(i, j, r); hint.setColor(c[movesleft]); canvas.drawRect(r, hint);

Figure 4.6: Tiles are highlighted based on how many possible values the tile can have.

We use three states for zero, one, and two possible moves. If there are zero moves, that means the player has done something wrong and needs to backtrack.

The result will look like Figure 4.6. Can you spot the mistake(s) made by the player?2

0 0