# Building a two-player game

I would like to make a MMA version of this game.

Modifying @belisariusisforth's code from this answer, I get

DynamicModule[{x = 0, s = 6},
Grid @
Map[
Button[ToString @ #, x = #,
Background ->
Dynamic[
If[MemberQ[Divisors[x], #] && x != #,
Lighter @ Red,
If[x == #, Lighter@Blue, Lighter@Lighter@Gray]]],
ImageSize -> 30] &,
Partition[Range@(s^2), s], {2}]]


which gives the desired effect for the first move, but I have no idea how to go about keeping the game going.

### Update

As @belisariusisforth pointed out below, any pointers on entering 2 numbers, one for player one and one for player 2, i.e., just the first two steps of the game would be much appreciated :)

• The Mathematica dynamic interface isn't well suited for this kind of app. There are a lot of boring and code-wise painful problems to solve. Perhaps instead of asking for the full blown game you may start trying to perform just the next step and asking for a narrower problem if the need arises. Oct 27, 2015 at 18:08
• @belisariusisforth Any hints on how to add another step would be more that appreciated - I have know idea how to get it to "remember" the previous position. Oct 27, 2015 at 18:10
• @belisariusisforth , or to enter 2 positions ... Oct 27, 2015 at 18:15

Here is a possible coding for the next step:

DynamicModule[{x = 0, s = 6, bkgs},
col1 = Lighter@Lighter@Green;
col2 = Lighter@Lighter@Blue;
col3 = Lighter@Lighter@Red;
bkgs = Table[col1, {s^2}];
Grid@Map[Button[ToString@#, x = #,
Background -> Dynamic[
If[bkgs[[#]] == col1,
If[x == #, bkgs[[#]] = col2,
If[MemberQ[Divisors[x], #], bkgs[[#]] = col3
]]]; bkgs[[#]]],
ImageSize -> 30] &,
Partition[Range@(s^2), s], {2}]]


• thank you! I should be able (I will try!!) to figure out the rest myself :) Thank you for the start in the right direction! :) Oct 27, 2015 at 18:32
• @martin you're most welcome .) Oct 27, 2015 at 18:34