2
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Dr. belisarius Oct 27 '15 at 18:08
  • $\begingroup$ @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. $\endgroup$ – martin Oct 27 '15 at 18:10
  • $\begingroup$ @belisariusisforth , or to enter 2 positions ... $\endgroup$ – martin Oct 27 '15 at 18:15
4
$\begingroup$

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

$\endgroup$
  • $\begingroup$ thank you! I should be able (I will try!!) to figure out the rest myself :) Thank you for the start in the right direction! :) $\endgroup$ – martin Oct 27 '15 at 18:32
  • 1
    $\begingroup$ @martin you're most welcome .) $\endgroup$ – Dr. belisarius Oct 27 '15 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.