2

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 :)

martin
  • 8,678
  • 4
  • 23
  • 70
  • 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. – Dr. belisarius Oct 27 '15 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. – martin Oct 27 '15 at 18:10
  • @belisariusisforth , or to enter 2 positions ... – martin Oct 27 '15 at 18:15

1 Answers1

4

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}]]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453