Task 2C: Building colour variations of sudoku

Dependency makes it easy for us to explore extensions to sudoku. This is how the colour sudoku environment was originally conceived. In this task we will attempt to build a colour sudoku environment and explore other ways that colour could be used to support the solving of sudoku puzzles.

Colouring cells

As mentioned in Task 1, it is possible to change the colour of each cell by redefining 'XY_bgcolour' where X is the column letter and Y is the row number. For example, the following should change the cell containing a '7' on the 2nd row to green:

C2_bgcolour = "green";

How would you change the colour of the bottom right cell to blue in the puzzle grid?

Making colours depend on cell contents

Rather than giving cells fixed colours, we can make the colours change by using dependency. For example, we could set the colour to grey if the cell already contains a digit (just for the first cell on the top row):

A1_bgcolour is isempty(a1) ? "white" : "grey";

With this definition included, when you enter a digit into cell A1 the background colour will change from white to grey. It will only work for one cell, if you want to do the same for the entire first row then you should add these too:

B1_bgcolour is isempty(b1) ? "white" : "grey";

C1_bgcolour is isempty(c1) ? "white" : "grey";

D1_bgcolour is isempty(d1) ? "white" : "grey";

E1_bgcolour is isempty(e1) ? "white" : "grey";

F1_bgcolour is isempty(f1) ? "white" : "grey";

G1_bgcolour is isempty(g1) ? "white" : "grey";

H1_bgcolour is isempty(h1) ? "white" : "grey";

I1_bgcolour is isempty(i1) ? "white" : "grey";

This demonstrates how the colour of cells can change depending on their contents. In the following pages you will make changes that are more helpful for guiding the solver.

Operators you can define yourself

A new feature has been illustrated on the previous page. The definitions discussed in previous tasks have made use of predefined operators. In the Eden notation, you can define your own operators and use these alongside standard operators in formulae. The function isempty() is a simple example. It returns TRUE or FALSE according to whether the string associated with a cell is empty. You can use a query of the form

0.000000e+00den

?isempty;

to find out how such a function is defined. Other examples of functions include makecolour() - to be discussed later. Changing the definition of an operator affects the values of all observables that are defined using it.

Using plausibles for colouring

The sudoku model contains observables that hold the plausibles information for each cell. For example, the observable A1_plausibles contains a list of plausibles for a particular cell. If you try the following, it will tell you (on the output window) the plausibles for the last cell on the second row:

writeln(I2_plausibles);

If there is only one plausible digit then it means that that digit can be placed in that cell. The condition for checking if there is only one plausible is: A1_plausibles#==1

Can you make the background of a cell green if it has only one plausible? Do this for the entire first row and see if this helps you enter some digits into the puzzle.

Recreating colour sudoku

You are now very close to making the final step towards creating colour sudoku. On the previous page the background of a cell could be one of two colours based on the plausible information. To make colour sudoku, we want to colour the cell using a wide range of colours (one colour for each plausible digit). The colour information is stored in an observable called 'colourvalues'. The plausible information for a cell, e.g. A1, is stored in 'A1_plausibles'.

To generate a colour from the plausible and colour information, you use the function 'makecolour'. For example, makecolour([1,4,7],colourvalues), will generate a colour based on 1, 4, and 7 being plausible digits.

Make the background of each cell dependent on the plausibles using the makecolour function. Hint: make a definition of the form: ... is makecolour(XY_plausibles, colourvalues);

Extensions to colour sudoku

If you have time then you can experiment with different colouring techniques. For example, you can accept the following new definition for makecolour() through the Input Window to change the way the colours are generated:

func makecolour {

para components, colours;

auto i, red, green, blue;

red = green = blue = 255;

for (i=1; i<=components#; i++) {

red = red - (colours[components[i][1]][1]);

green = green - (colours[components[i][1]][2]);

blue = blue - (colours[components[i][1]][3]);

}

if (red < 0) red = 0;

if (green < 0) green = 0;

if (blue < 0) blue = 0;

return rgb2colour(red, green, blue);

}

What effect does this have? Can you think of any other ways of colouring the sudoku grid that may enhance solving?

The End

This is the end of Workshop 2. Please fill out the Feedback 2 form on the Sudoku Experience website - when it arrives there!