3
$\begingroup$

Here is the game outline:

$\hspace{2.5cm}$enter image description here

There is one player. The player ($\mathscr{L}$) moves from node to node limited by the directed arrows. As the player moves, $\mathscr{G}_{\Huge\cdot}$ chooses to move in the opposite direction while $\mathscr{G}_{\circ}$ moves in the same direction as the player, all three step simultaneously. If the player makes a move that would cause the guardians to jump off the playing board they remain in place, and the player keeps his/her move. Also, if the player makes a move that would cause him/her to jump off the playing board, then he/she remains in place. The object of the game is to guide the guardians to the circle-cross ($\bigoplus$) nodes so that they individually land on each in whatever order and whatever way simultaneously. A 12-step solution to solve the puzzle has been uncovered, however, I am seeking the shortest possible step solution to this puzzle.

I want to be able to move a green dot from node to node with the red dots (guardians) mirroring the green dot's moves in the direction indicated and with the following rules:

$\hspace{2.5cm}$enter image description here

I'm currently making a Windows application (win32 C++), but I just wanted to know if I can make such a game, and if so could someone here get me started with a basic outline that I can pickup on my own and develop into the final game.

Baby Attempt:

DynamicModule[{pos1 = {x1, y1} = {2, 2}, pos2 = {x2, y2} = {2, 4}, 
  pos3 = {x3, y3} = {2, 0}}, 
 EventHandler[
  Dynamic[Graphics[{Gray, Disk[{0, 5}, .1], Gray, Disk[{0, 4}, .1], 
     Gray, Disk[{0, 3}, .1], Gray, Disk[{1, 5}, .1], Gray, 
     Disk[{1, 4}, .1], Gray, Disk[{1, 3}, .1], Gray, Disk[{3, 5}, .1],
      Gray, Disk[{3, 4}, .1], Gray, Disk[{3, 3}, .1], Gray, 
     Disk[{4, 5}, .1], Gray, Disk[{4, 4}, .1], Gray, Disk[{4, 3}, .1],
      Gray, Disk[{1, 1}, .1], Gray, Disk[{2, 1}, .1], Gray, 
     Disk[{3, 1}, .1], Gray, Disk[{1, 2}, .1], Gray, Disk[{2, 2}, .1],
      Gray, Disk[{3, 2}, .1], Gray, Disk[{2, 0}, .1], Gray, 
     Disk[{2, 3}, .1], Gray, Disk[{2, 4}, .1], Green, Disk[pos1, .25],
      Red, Disk[pos2, .25], Red, 
     Disk[pos3, .25]}]], {"UpArrowKeyDown" :> {pos1 = 
      pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}} , 
     pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 - 1}} , 
     pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 + 1}}}, 
   "DownArrowKeyDown" :> {pos1 = 
      pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}, 
     pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 + 1}}, 
     pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 - 1}}}, 
   "LeftArrowKeyDown" :> {pos1 = 
      pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}, 
     pos2 = pos2 /. {{x2, y2} -> {x2 = x2 + 1, y2 = y2}} , 
     pos3 = pos3 /. {{x3, y3} -> {x3 = x3 - 1, y3 = y3}}}, 
   "RightArrowKeyDown" :> {pos1 = 
      pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}, 
     pos2 = pos2 /. {{x2, y2} -> {x2 = x2 - 1, y2 = y2}}, 
     pos3 = pos3 /. {{x3, y3} -> {x3 = x3 + 1, y3 = y3}}}}]]
$\endgroup$
  • $\begingroup$ I saw this and thought why not make it in Mathematica. $\endgroup$ – Liz May 13 '15 at 2:12
  • $\begingroup$ LocatorPane maybe? $\endgroup$ – Liz May 13 '15 at 2:19
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 May 13 '15 at 2:19
  • $\begingroup$ Your exposition of the game's rules is incomplete and obscure. Please clarify them. What are the circles with circle-pluses in them? What does the empty game board look like? what is starting the position? You refer to red dots, but don't show any; what are they? $\endgroup$ – m_goldberg May 13 '15 at 2:45
  • $\begingroup$ @m_goldberg, added some code. I've never used Mathematica before. $\endgroup$ – Liz May 13 '15 at 4:19
1
$\begingroup$

THIS WORKS:

$\hspace{3cm}$enter image description here

Although... I can't get it so that it stops exiting the dynamic window when the message changes, and I think the logic might not be robust.

bound = {{2, -1}, {2, 5}, {1, 0}, {3, 0}, {0, 1}, {4, 1}, {0, 2}, {4, 
   2}, {-1, 3}, {5, 3}, {-1, 4}, {5, 4}, {-1, 5}, {5, 5}, {0, 6}, {1, 
   6}, {3, 6}, {4, 6}}

DynamicModule[{pos1 = {x1, y1} = {2, 2}, pos2 = {x2, y2} = {2, 4}, 
  pos3 = {x3, y3} = {2, 0}, message = "Start", 
  DotT = {a2, b2} = {x2, (y2 - 0.51)}, 
  DotL = {a1, b1} = {x1, (y1 + 0.51)}, 
  DotB = {a3, b3} = {x3, (y3 + 0.51)}, Switch = True, Stick = False}, 
 EventHandler[
  Dynamic[Magnify[
    Graphics[{Opacity[0.9], 
      Style[Text[message, {2, 5}], FontFamily -> "Helvetica", Small, 
       Gray, FontSize -> 15], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{0, 5}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{0, 4}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{0, 3}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{1, 5}, .35], Yellow, Disk[{1, 4}, .35], 
      EdgeForm[Directive[Thick, Magenta]], Cyan, Disk[{1, 3}, .35], 
      EdgeForm[Directive[Thick, Magenta]], Cyan, Disk[{3, 5}, .35], 
      Yellow, Disk[{3, 4}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{3, 3}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{4, 5}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{4, 4}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{4, 3}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{1, 1}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{2, 1}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{3, 1}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{1, 2}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{2, 2}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{3, 2}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{2, 0}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{2, 3}, .35], EdgeForm[Directive[Thick, Magenta]], 
      Cyan, Disk[{2, 4}, .35], Darker[Green, 0.5], 
      Style[Text[\[NeutralSmiley], pos1], FontSize -> 36], Blue, 
      Style[Text[\[FreakedSmiley], pos2], FontSize -> 48], Orange, 
      Style[Text[\[FreakedSmiley], pos3], 
       FontSize -> 48]}]]], {"UpArrowKeyDown" :> {message = "", 
     Switch = True, Stick = False, 
     If[(**){x1, y1 + 1} == {x2, y2 - 1} || {x1, y1 + 1} == {x2, 
         y2} || {x1, y1 + 1} == {x3, y3} || {x3, y3 + 1} == {x2, 
         y2 - 1} || {x3, y3 + 1} == {x2, 
         y2}, {Which[{x3, y3 + 1} == {x2, y2 - 1}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}, pos2 = pos2, 
         pos3 = pos3}, {x3, y3 + 1} == {x2, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}, pos2 = pos2, 
         pos3 = pos3}, {x1, y1 + 1} == {x2, y2 - 1}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}}, 
         message = "Gameover", DotT = {2, (4 - .51)}, 
         DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)}, 
         Switch = False}, {x1, y1 + 1} == {x2, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x1, 
          y1 + 1} == {x3, y3}, {Which[
          Intersection[
            bound, {{x3, y3 + 1}}] == {{x3, y3 + 1}}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x3, 
            y3 + 1} == {x2, y2 - 1}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}}, 
           message = "Gameover", DotT = {2, (4 - .51)}, 
           DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)}, 
           Switch = False}, 
          Intersection[
            bound, {{x3, y3 + 1}}] != {{x3, y3 + 1}}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 - 1}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, 
                y3 = y3 + 
                  1}}}]}]}, {If[(*Test if next move out of bound.*)
        Intersection[bound, {{x1, y1 + 1}}] == {{x1, y1 + 1}}, {pos1 =
           pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True}, 
        pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}], 
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x2, y2 - 1}}] == {{x2, y2 - 1}}, 
        pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
        If[Stick == True, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 - 1}}]], 
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x3, y3 + 1}}] == {{x3, y3 + 1}}, 
        pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}, 
        If[Stick == True, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 + 1}}]]}], 
     If[Switch == True, {DotT = {a2 = x2, b2 = y2 - .51}, 
       DotL = {a1 = x1, b1 = y1 + .51}, 
       DotB = {a3 = x3, b3 = y3 + .51}}], Switch = True, 
     If[{x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1, 
          4} && {x2, y2} == {3, 4}, message = "Win"]}, 
   "DownArrowKeyDown" :> {message = "", Switch = True, Stick = False, 
     If[(**){x1, y1 - 1} == {x2, y2 + 1} || {x1, y1 - 1} == {x2, 
         y2} || {x1, y1 - 1} == {x3, y3} || {x3, y3 - 1} == {x2, 
         y2 + 1} || {x3, y3 - 1} == {x2, 
         y2}, {Which[{x3, y3 - 1} == {x2, y2 + 1}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}, pos2 = pos2, 
         pos3 = pos3}, {x3, y3 - 1} == {x2, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}, pos2 = pos2, 
         pos3 = pos3}, {x1, y1 - 1} == {x2, y2 + 1}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}}, 
         message = "Gameover", DotT = {2, (4 - .51)}, 
         DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)}, 
         Switch = False}, {x1, y1 - 1} == {x2, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x1, 
          y1 - 1} == {x3, y3}, {Which[
          Intersection[
            bound, {{x3, y3 - 1}}] == {{x3, y3 - 1}}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x3, 
            y3 - 1} == {x2, y2 + 1}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}}, 
           message = "Gameover", DotT = {2, (4 - .51)}, 
           DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)}, 
           Switch = False}, 
          Intersection[
            bound, {{x3, y3 - 1}}] != {{x3, y3 - 1}}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 + 1}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, 
                y3 = y3 - 
                  1}}}]}]}, {If[(*Test if next move out of bound.*)
        Intersection[bound, {{x1, y1 - 1}}] == {{x1, y1 - 1}}, {pos1 =
           pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True}, 
        pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}], 
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x2, y2 + 1}}] == {{x2, y2 + 1}}, 
        pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
        If[Stick == True, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 + 1}}]], 
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x3, y3 - 1}}] == {{x3, y3 - 1}}, 
        pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}, 
        If[Stick == True, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 - 1}}]]}], 
     If[Switch == True, {DotT = {a2 = x2, b2 = y2 + .51}, 
       DotL = {a1 = x1, b1 = y1 - .51}, 
       DotB = {a3 = x3, b3 = y3 - .51}}], Switch = True, 
     If[{x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1, 
          4} && {x2, y2} == {3, 4}, message = "Win"]}, 
   "LeftArrowKeyDown" :> {message = "", Switch = True, Stick = False, 
     If[(**){x1 - 1, y1} == {x2 + 1, y2} || {x1 - 1, y1} == {x2, 
         y2} || {x1 - 1, y1} == {x3, y3} || {x3 - 1, y3} == {x2 + 1, 
         y2} || {x3 - 1, y3} == {x2, 
         y2}, {Which[{x3 - 1, y3} == {x2 + 1, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}, pos2 = pos2, 
         pos3 = pos3}, {x3 - 1, y3} == {x2, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}, pos2 = pos2, 
         pos3 = pos3}, {x1 - 1, y1} == {x2 + 1, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}}, 
         message = "Gameover", DotT = {2, (4 - .51)}, 
         DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)}, 
         Switch = False}, {x1 - 1, y1} == {x2, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x1 - 1, 
          y1} == {x3, y3}, {Which[
          Intersection[
            bound, {{x3 - 1, y3}}] == {{x3 - 1, y3}}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x3 - 1, 
            y3} == {x2 + 1, y2}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}}, 
           message = "Gameover", DotT = {2, (4 - .51)}, 
           DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)}, 
           Switch = False}, 
          Intersection[
            bound, {{x3 - 1, y3}}] != {{x3 - 1, y3}}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2 + 1, y2 = y2}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3 - 1, 
                y3 = y3}}}]}]}, {If[(*Test if next move out of bound.*)
        Intersection[bound, {{x1 - 1, y1}}] == {{x1 - 1, y1}}, {pos1 =
           pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True}, 
        pos1 = pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}], 
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x2 + 1, y2}}] == {{x2 + 1, y2}}, 
        pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
        If[Stick == True, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2 + 1, y2 = y2}}]], 
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x3 - 1, y3}}] == {{x3 - 1, y3}}, 
        pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}, 
        If[Stick == True, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3 - 1, y3 = y3}}]]}], 
     If[Switch == True, {DotT = {a2 = x2 + .51, b2 = y2}, 
       DotL = {a1 = x1 - .51, b1 = y1}, 
       DotB = {a3 = x3 - .51, b3 = y3}}], Switch = True, 
     If[{x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1, 
          4} && {x2, y2} == {3, 4}, message = "Win"]}, 
   "RightArrowKeyDown" :> {message = "", Switch = True, Stick = False,
      If[(**){x1 + 1, y1} == {x2 - 1, y2} || {x1 + 1, y1} == {x2, 
         y2} || {x1 + 1, y1} == {x3, y3} || {x3 + 1, y3} == {x2 - 1, 
         y2} || {x3 + 1, y3} == {x2, 
         y2}, {Which[{x3 + 1, y3} == {x2 - 1, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}, pos2 = pos2, 
         pos3 = pos3}, {x3 + 1, y3} == {x2, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}, pos2 = pos2, 
         pos3 = pos3}, {x1 + 1, y1} == {x2 - 1, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}}, 
         message = "Gameover", DotT = {2, (4 - .51)}, 
         DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)}, 
         Switch = False}, {x1 + 1, y1} == {x2, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x1 + 1, 
          y1} == {x3, y3}, {Which[
          Intersection[
            bound, {{x3 + 1, y3}}] == {{x3 + 1, y3}}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 

           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}}, {x3 + 1, 
            y3} == {x2 - 1, y2}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}}, 
           message = "Gameover", DotT = {2, (4 - .51)}, 
           DotL = {2, (2 + .51)}, DotB = {2, (0 + .51)}, 
           Switch = False}, 
          Intersection[
            bound, {{x3 + 1, y3}}] != {{x3 + 1, y3}}, {pos1 = 
            pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}, 
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2 - 1, y2 = y2}}, 
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3 + 1, 
                y3 = y3}}}]}]}, {If[(*Test if next move out of bound.*)
        Intersection[bound, {{x1 + 1, y1}}] == {{x1 + 1, y1}}, {pos1 =
           pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True}, 
        pos1 = pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}], 
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x2 - 1, y2}}] == {{x2 - 1, y2}}, 
        pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
        If[Stick == True, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}}, 
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2 - 1, y2 = y2}}]], 
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x3 + 1, y3}}] == {{x3 + 1, y3}}, 
        pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}, 
        If[Stick == True, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}, 
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3 + 1, y3 = y3}}]]}], 
     If[Switch == True, {DotT = {a2 = x2 - .51, b2 = y2}, 
       DotL = {a1 = x1 + .51, b1 = y1}, 
       DotB = {a3 = x3 + .51, b3 = y3}}], Switch = True, 
     If[{x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1, 
          4} && {x2, y2} == {3, 4}, message = "Win"]}}]]
$\endgroup$

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.