13 votos

Zelda Twilight Tutor Rompecabezas : la Ruta más corta (ACTUALIZACIÓN: se ha AÑADIDO REGLAS)

Estoy jugando un juego de video ahora mismo y es un rompecabezas (ver aquí). Hay soluciones para resolverlo (ver aquí) en el Internet, pero me gustaría saber si este camino es el camino más corto (menor cantidad de movimientos) posible para resolver el rompecabezas.

Las reglas del juego son claras desde el vídeo. Hay una red de nodos. La frontera nodos están delimitadas con limitadas opciones de ruta. Hay tres cuerpos en movimiento. El principal uno elige un camino que refleja el camino decisiones de los otros dos. El objetivo es guiar a los otros dos a la tierra en ciertos nodos al mismo tiempo.

REGLAS IMPORTANTES:

Si los guardianes de la cara unos a otros y el Vínculo, el jugador, se mueve de una manera que chocan, en efecto, permanecer en la misma posición y el Vínculo que mantiene su movimiento: youtube.com/watch?v=ZNnSwc0w1oE#t=4m58s

Top-tutor-Link conga permitido: youtube.com/watch?v=oUh88KsZYCc#t=3m53s – Liz Wesley 21 minutos hace

El juego termina si el jugador salta en un cuadrado de un tutor se establece para saltar al mismo tiempo: youtube.com/watch?v=ZNnSwc0w1oE#t=2m55s

Estoy en busca de una ruta más corta de la prueba basado en este juego de reglas. Cualquier ayuda se agradece.

Es importante tener en cuenta que la parte superior del tutor se mueve en la dirección opuesta como enlace y en la parte inferior tutor imita Enlace de la dirección.


Daniel Wagner de 12 pasos de Haskell Solución:

enter image description here

Tutor Ruta De Superposición:

enter image description here

8voto

Daniel Wagner Puntos 196

Bajo algunos supuestos, calculo que el camino más corto requiere de 12 pasos; el jugador debe hacer los movimientos ESNNNWWSSSEN. (Este es un paso más corta que las dos soluciones se vincula a.) Los supuestos que he hecho son:

  1. Entidades que paso fuera de la mesa de juego no se mueven.
  2. Las tres entidades paso de forma simultánea.
  3. El jugador no puede hacer un movimiento que podría causar una entidad a cambio de su ubicación a la que actualmente está ocupado. (El restante en el lugar está bien.)
  4. El jugador no puede permanecer en su lugar.
  5. El jugador no puede hacer un movimiento que podría causar que dos entidades para ocupar el mismo celular.

A continuación se incluyen un completo listado de código (en Haskell), que describe el juego y realiza Una* búsqueda como el implementado por el astar paquete para encontrar una trayectoria mínima. Como una heurística, consideramos que las dos formas de emparejamiento de los tutores y la meta de las células; en cada emparejamiento, se calcula la distancia de Manhattan el tutor que tiene más a caminar, luego tomar la menor distancia máxima de estos dos emparejamientos. Ciertamente, este es admisible, ya que debemos tomar al menos tantos pasos como los guardianes están lejos de su objetivo células. Asunción (1) está codificado en stepValid; (2) en unsafeMove; (3)-(5) movementIsValid. Más corta de las soluciones puede ser posible si estas suposiciones son incorrectas.

import Data.List
import Data.Graph.AStar
import Data.Ord
import Data.Set (Set, fromList)

type Position = (Int, Int)
data Direction = N | E | S | W deriving (Eq, Ord, Read, Show, Bounded, Enum)

allDirections :: [Direction]
allDirections = [N, E, S, W]

mirror :: Direction -> Direction
mirror N = S
mirror E = W
mirror S = N
mirror W = E

dx, dy :: Direction -> Int
dx E =  1
dx W = -1
dx _ =  0
dy N =  1
dy S = -1
dy _ =  0

step :: Direction -> Position -> Position
step d (x, y) = (x + dx d, y + dy d)

data Configuration = Configuration
    { valid :: [Position]
    , goalA :: Position
    , goalB :: Position
    } deriving (Eq, Ord, Read, Show)

data State = State
    { player         :: Position
    , guardianSame   :: Position
    , guardianMirror :: Position
    } deriving (Eq, Ord, Read, Show)

stepValid :: Configuration -> Direction -> Position -> Position
stepValid c d p
    | p' `elem` valid c = p'
    | otherwise = p
    where p' = step d p

unsafeMove :: Configuration -> Direction -> State -> State
unsafeMove c d State { player = p, guardianSame = gs, guardianMirror = gm } = State
    { player         = stepValid c d p
    , guardianSame   = stepValid c d gs
    , guardianMirror = stepValid c (mirror d) gm
    }

movementIsValid :: State -> State -> Bool
movementIsValid old new
    =  player         new `notElem`                             oldPositions
    && guardianSame   new `notElem` delete (guardianSame   old) oldPositions
    && guardianMirror new `notElem` delete (guardianMirror old) oldPositions
    && nub newPositions == newPositions
    where
    newPositions = [player new, guardianSame new, guardianMirror new]
    oldPositions = [player old, guardianSame old, guardianMirror old]

movements :: Configuration -> State -> Set State
movements c old = fromList
    [ new
    | d <- allDirections
    , let new = unsafeMove c d old
    , movementIsValid old new
    ]

manhattan :: Position -> Position -> Int
manhattan (x, y) (x', y') = abs (x-x') + abs (y-y')

heuristic :: Configuration -> State -> Int
heuristic c s = min
    (max (manhattan (guardianSame s) (goalA c)) (manhattan (guardianMirror s) (goalB c)))
    (max (manhattan (guardianSame s) (goalB c)) (manhattan (guardianMirror s) (goalA c)))

cost :: State -> State -> Int
cost _ _ = 1

finished :: Configuration -> State -> Bool
finished c s = heuristic c s == 0

data Cell = Player | Goal | GuardianSame | GuardianMirror | Valid
    deriving (Eq, Ord, Read, Show, Bounded, Enum)

label :: String -> [(Position, Cell)]
label board = do
    (y, row)  <- zip [0..] (reverse (lines board))
    (x, char) <- zip [0..] row
    let cell c = [((x, y), c)]
    case char of
        'x' -> cell Valid
        'g' -> cell Goal
        's' -> cell GuardianSame
        'm' -> cell GuardianMirror
        'p' -> cell Player
        _   -> []

parse :: String -> (Configuration, State)
parse board = (Configuration
    { valid = map fst labels
    , goalA = gA
    , goalB = gB
    }, State
    { player         = p
    , guardianSame   = gs
    , guardianMirror = gm
    })
    where
    labels = label board
    (p, Player):(gA, Goal):(gB, Goal):(gs, GuardianSame):(gm, GuardianMirror):_
        = sortBy (comparing snd) labels

(testConfiguration, testState) = parse
    "xx xx\n\
    \xgmgx\n\
    \xxxxx\n\
    \ xpx \n\
    \ xxx \n\
    \  s  \n"

main = case aStar (movements testConfiguration) cost (heuristic testConfiguration) (finished testConfiguration) testState of
    Nothing       -> putStrLn "no solution exists for the test board"
    Just solution -> mapM_ print solution

1voto

Sam Puntos 19

He construido el juego en Mathematica usando las reglas creo que estamos tratando de lograr. Aquí está el código si tienes Mathematica:

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

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

i-Ciencias.com

I-Ciencias es una comunidad de estudiantes y amantes de la ciencia en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X