Beispiel #1
0
def juego_actualizar(grilla, nivel, niveles, accion, estados, pistas):
    '''Actualiza la grilla dependiendo de la accion que el usuario haga'''
    acciones = {'NORTE': NORTE, 'SUR': SUR, 'ESTE': ESTE, 'OESTE': OESTE}
    if accion == 'REINICIAR':
        grilla = juego_crear(nivel, niveles)
        while not estados.esta_vacia():
            estados.desapilar()

    elif accion == 'VOLVER':
        estados, grilla = deshacer_movimiento(estados, grilla)

    elif accion == 'PISTA':
        if not pistas:
            pistas = buscar_pistas(pistas, grilla)
        else:
            estados = apilar_estados(estados, grilla)
            movimiento = pistas.desapilar()
            grilla = soko.mover(grilla, movimiento)
        return grilla, estados, pistas

    elif accion in acciones:
        estados = apilar_estados(estados, grilla)
        grilla = soko.mover(grilla, acciones[accion])

    elif accion == 'SALIR':
        grilla = None

    pistas = None
    return grilla, estados, pistas
Beispiel #2
0
def test16():
    '''
    Prueba de pisar el objetivo
    '''
    desc1 = [
        '########',
        '#    .@#',
        '#      #',
        '########',
    ]
    desc2 = [
        '########',
        '#    + #',
        '#      #',
        '########',
    ]
    desc3 = [
        '########',
        '#   @. #',
        '#      #',
        '########',
    ]
    grilla1 = soko.crear_grilla(desc1)
    grilla2 = soko.mover(grilla1, OESTE)
    grilla3 = soko.mover(grilla2, OESTE)
    verificar_estado(desc1, grilla1)
    verificar_estado(desc2, grilla2)
    verificar_estado(desc3, grilla3)
Beispiel #3
0
def main():
    niveles = cargar_niveles()
    nivel = 1
    teclas = cargar_teclas()
    juego = setear_juego(niveles, nivel)
    movimientos = Pila()
    soluciones = Pila()
    mensaje = ""
    while gamelib.is_alive():
        gamelib.draw_begin()
        dibujar(juego)
        gamelib.draw_end()
        gamelib.draw_text(mensaje,15,15,anchor="w")
        ev = gamelib.wait(gamelib.EventType.KeyPress)
        if not ev: break

        tecla = ev.key
        
        if tecla in teclas:
            if teclas[tecla] == "REINICIAR":
                juego = reiniciar(juego, niveles, nivel, soluciones)
            elif teclas[tecla] == "SALIR":
                break
            elif teclas[tecla] == "DESHACER": 
                if movimientos.tope:
                    juego = deshacer(movimientos, juego)
            elif teclas[tecla] == "AYUDA":
                if soluciones.esta_vacia():
                    gamelib.draw_text("Pensando...", 15, 15, anchor="w")
                    gamelib.get_events() #Utilizo .get_events() como una especie de mutex para evitar que el usuario interactúe
                    solucion_encontrada, soluciones = solver.buscar_solucion(juego, DIRECCIONES)
                    gamelib.get_events()
                    if solucion_encontrada:
                        mensaje = "Hay pista disponible"
                    else:
                        mensaje = "No hay chance"
                else:
                    movimientos.apilar(juego)
                    juego = soko.mover(juego, soluciones.desapilar())
            else:
                movimientos.apilar(juego)
                juego = soko.mover(juego, DIRECCIONES[teclas[tecla]])

            if tecla and not teclas[tecla] == "AYUDA":
                soluciones = Pila()
                mensaje = ""

            if soko.juego_ganado(juego):
                nivel = nivel + 1
                juego = setear_juego(niveles, nivel)
                movimientos = Pila()
Beispiel #4
0
def test15():
    '''
    Prueba de moverse a los limites del tablero
    '''
    desc1 = [
        '########',
        '#     @#',
        '#  *   #',
        '########',
    ]
    grilla1 = soko.crear_grilla(desc1)

    grilla2 = soko.mover(grilla1, ESTE)
    grilla3 = soko.mover(grilla1, NORTE)
    assert grilla1 == grilla3
Beispiel #5
0
def juego_actualizar(grilla, nivel, niveles, accion):
    '''Actualiza la grilla dependiendo de la accion que el usuario haga'''
    if accion == 'REINICIAR':
        grilla = juego_crear(nivel, niveles)
    elif accion == 'NORTE':
        grilla = soko.mover(grilla, NORTE)
    elif accion == 'SUR':
        grilla = soko.mover(grilla, SUR)
    elif accion == 'ESTE':
        grilla = soko.mover(grilla, ESTE)
    elif accion == 'OESTE':
        grilla = soko.mover(grilla, OESTE)
    elif accion == 'SALIR':
        return None
    return grilla
Beispiel #6
0
def test19():
    '''
    Prueba del primer nivel del TP2
    '''
    desc1 = [
        "####  ",
        "# .#  ",
        "#  ###",
        "#*   #",
        "#@ $ #",
        "#  ###",
        "####  "
    ]
    desc2 = [
        "####  ",
        "# .#  ",
        "#$ ###",
        "#+   #",
        "#  $ #",
        "#  ###",
        "####  "
    ]
    grilla1 = soko.crear_grilla(desc1)
    grilla2 = soko.mover(grilla1, NORTE)
    verificar_estado(desc2, grilla2)
Beispiel #7
0
def backtrack(estado, visitados, nivel_inicial):
    '''Recorro diferentes posibles estados para resolver un movimiento y devuelvo una solucion'''

    dic_niveles_grilla = leer_niveles("niveles.txt")

    visitados[convertir_a_inmutable(estado)] = visitados.get(
        convertir_a_inmutable(estado), True)

    if soko.juego_ganado(estado):
        return True, []
    else:
        for mov in movs_tuplas:
            printgrilla(estado)
            print(mov)
            print()
            nuevo_estado_grilla = soko.mover(estado, mov)
            printgrilla(nuevo_estado_grilla)
            if convertir_a_inmutable(nuevo_estado_grilla) in visitados:
                print("Ya recorrido...")
                continue
            else:
                print("Utilizando pista...")
                solucion_encontrada, acciones = backtrack(
                    nuevo_estado_grilla, visitados, nivel_inicial)
                if solucion_encontrada:
                    return True, acciones + [mov]
        return False, None
Beispiel #8
0
def test18():
    '''
    Prueba de un movimiento invalido con el jugador posicionado sobre un objetivo
    '''
    desc1 = [
        '########',
        '# $$+  #',
        '#      #',
        '########',
    ]
    grilla1 = soko.crear_grilla(desc1)
    grilla2 = soko.mover(grilla1, OESTE)
    verificar_estado(desc1, grilla2)
Beispiel #9
0
def test8():
    desc = [
        '########',
        '#@ $ . #',
        '########',
    ]
    grilla = soko.crear_grilla(desc)
    verificar_estado(desc, grilla)
    assert not soko.juego_ganado(grilla)

    for direction in (OESTE, NORTE, SUR):
        grilla = soko.mover(grilla, direction)
        verificar_estado(desc, grilla)
        assert not soko.juego_ganado(grilla)

    grilla = soko.mover(grilla, ESTE)
    desc = [
        '########',
        '# @$ . #',
        '########',
    ]
    verificar_estado(desc, grilla)
    assert not soko.juego_ganado(grilla)

    for direction in (NORTE, SUR):
        grilla = soko.mover(grilla, direction)
        verificar_estado(desc, grilla)
        assert not soko.juego_ganado(grilla)

    grilla = soko.mover(grilla, ESTE)
    verificar_estado([
        '########',
        '#  @$. #',
        '########',
    ], grilla)
    assert not soko.juego_ganado(grilla)

    grilla = soko.mover(grilla, OESTE)
    verificar_estado([
        '########',
        '# @ $. #',
        '########',
    ], grilla)
    assert not soko.juego_ganado(grilla)

    grilla = soko.mover(grilla, ESTE)
    grilla = soko.mover(grilla, ESTE)
    verificar_estado([
        '########',
        '#   @* #',
        '########',
    ], grilla)
    assert soko.juego_ganado(grilla)
Beispiel #10
0
def pista(estado, visitados):
    '''Busca una solucion posible al estado del juego'''
    estado_actual = convertir_estado_cadena(estado)
    visitados.add(estado_actual)
    if soko.juego_ganado(estado):
        return True, []
    for movimiento in MOVIMIENTOS:
        nuevo_estado = soko.mover(estado, movimiento)
        if convertir_estado_cadena(nuevo_estado) in visitados:
            continue
        solucion_encontrada, acciones = pista(nuevo_estado, visitados)
        if solucion_encontrada:
            return True, acciones + [movimiento]
    return False, {}
Beispiel #11
0
def test14():
    '''
    Prueba de que no se pueda mover una caja en objetivo adyacente a una fuera de objetivo
    '''
    desc1 = [
        '########',
        '#   @*$#',
        '#  .   #',
        '########',
    ]
    grilla1 = soko.crear_grilla(desc1)

    grilla2 = soko.mover(grilla1, ESTE)
    assert not soko.juego_ganado(grilla2)
    assert grilla1 == grilla2
Beispiel #12
0
def test10():
    '''
    Prueba de que se pueda sacar una caja del objetivo
    '''
    desc1 = [
        '########',
        '#   @* #',
        '#      #',
        '########',
    ]
    grilla1 = soko.crear_grilla(desc1)

    grilla2 = soko.mover(grilla1, ESTE)
    assert not soko.juego_ganado(grilla2)
    assert grilla1 != grilla2
Beispiel #13
0
def test9():
    '''
    Prueba de que se pueda mover una caja hacia el objetivo
    '''
    desc1 = [
        '########',
        '#  @$. #',
        '#      #',
        '########',
    ]
    grilla1 = soko.crear_grilla(desc1)

    grilla2 = soko.mover(grilla1, ESTE)
    assert soko.juego_ganado(grilla2)
    assert grilla1 != grilla2
Beispiel #14
0
def _backtrack(grilla, visitados, acciones_posibles, movimientos):
    visitados[h(grilla)] = True
    if soko.juego_ganado(grilla):
        return True, movimientos
    for accion in acciones_posibles:
        nuevo_estado = soko.mover(grilla, accion)
        if h(nuevo_estado) in visitados:
            continue
        solucion_encontrada, movimientos = _backtrack(nuevo_estado, visitados,
                                                      acciones_posibles,
                                                      movimientos)
        if solucion_encontrada:
            movimientos.apilar(accion)
            return True, movimientos
    return False, Pila()
Beispiel #15
0
def backtrack(estado, visitados, direcciones):
    visitados.add(transformar(estado))
    if soko.juego_ganado(estado):
        return True, Pila()

    for direccion in direcciones.values():
        nuevo_estado = soko.mover(estado, direccion)
        if transformar(nuevo_estado) in visitados:
            continue
        solucion_encontrada, acciones = backtrack(nuevo_estado, visitados,
                                                  direcciones)
        if solucion_encontrada:
            acciones.apilar(direccion)
            return True, acciones

    return False, None
Beispiel #16
0
def test6():
    desc1 = [
        '######',
        '#@ $.#',
        '######',
    ]
    desc2 = [
        '######',
        '# @$.#',
        '######',
    ]

    grilla1 = soko.crear_grilla(desc1)
    grilla2 = soko.mover(grilla1, ESTE)

    # Si el movimiento es válido, la función mover() debe devolver una grilla nueva
    # y NO modificar la grilla recibida.
    verificar_estado(desc1, grilla1)
    verificar_estado(desc2, grilla2)
Beispiel #17
0
def test17():
    '''
    Prueba de mover una caja con objetivo hacia otro objetivo
    '''
    desc1 = [
        '########',
        '#   @*.#',
        '#      #',
        '########',
    ]
    desc2 = [
        '########',
        '#    +*#',
        '#      #',
        '########',
    ]
    grilla1 = soko.crear_grilla(desc1)
    grilla2 = soko.mover(grilla1, ESTE)
    verificar_estado(desc1, grilla1)
    verificar_estado(desc2, grilla2)
Beispiel #18
0
def backtrack(estado, visitados):  # nivel juego, conjunto
    '''
    Función recursiva que recibe el estado del juego y un conjunto vacio, que tiene como caso base
    si el juego se gano de lo contrario entra en un ciclo definido que llama recursivamente hasta
    agotar todas las posibilidades.
    '''
    visitados.add(transformar_a_cadena(estado))
    if soko.juego_ganado(estado):
        # ¡encontramos la solución!
        return True, []

    for _, direccion in DIRECCIONES.items():
        nuevo_estado = soko.mover(estado, direccion)  #a = (-1,0)
        if transformar_a_cadena(nuevo_estado) in visitados:
            continue
        solución_encontrada, acciones = backtrack(
            nuevo_estado, visitados)  #solucion encontrada es true o false
        if solución_encontrada:
            acciones.append(direccion)
            return True, acciones
    return False, None
Beispiel #19
0
    def _backtrack(self, estado, visitados):
        '''Busca los movimientos disponibles para el estado del juego. Devuelve si es posible realizar el movimiento,
        y almacena los movimientos requeridos para llegar a ese estado valido.'''
        visitados[str(estado)] = estado

        if soko.juego_ganado(estado):
            return True

        for direccion in DIRECCIONES:
            nuevo_estado = soko.mover(estado, direccion)

            if str(nuevo_estado) in visitados:
                continue

            solucion_encontrada = self._backtrack(nuevo_estado, visitados)
            if solucion_encontrada:

                self.acciones_solucion.apilar(direccion)

                return True

        return False
Beispiel #20
0
def main():
    '''Inicializa el juego'''

    gl.title("Sokoban")

    try:
        # Genera la lista de niveles, con la matriz de objetos, y el nombre del nivel.
        niveles = parser.lista_niveles(ARCHIVO_NIVELES)
    except (IOError, FileNotFoundError):
        render.error_archivo(ARCHIVO_NIVELES)

        ev = gl.wait(gl.EventType.KeyPress)
        return

    try:
        # Genera el diccionario con las teclas, y la accion que generan esas teclas
        controles = parser.dict_controles(ARCHIVO_CONTROLES)
    except (IOError, FileNotFoundError):
        render.error_archivo(ARCHIVO_CONTROLES)

        ev = gl.wait(gl.EventType.KeyPress)
        return

    nivel_nro = PRIMER_NIVEL - 1

    # Empezar contador de tiempo para dar tiempo total luego de finalizados todos los niveles
    tiempo_inicial = time.time()

    # Itera por cada nivel
    while gl.is_alive():

        nivel = niveles[nivel_nro].copy()

        grilla = nivel["grilla"]
        titulo = nivel["title"]

        nivel_actual = soko.crear_grilla(grilla)

        x, y = render.cambiar_tamanio_ventana(nivel_actual)

        render.titulo(titulo, (x, y))
        time.sleep(1)

        accion = (0, 1)

        # Crea nuevas instancias, para que no genere errores cuando pase de nivel
        deshacer = Deshacer()
        backtraking = Backtracking()

        # Este ciclo solo espera al input del jugador
        while True:
            gl.draw_begin()

            render.nivel(nivel_actual, accion)

            gl.draw_end()

            ev = gl.wait(gl.EventType.KeyPress)
            if not ev:
                return

            tecla = ev.key

            if not tecla in controles:
                continue

            accion = controles[tecla]

            # Actualizar el estado del juego, según la `tecla` presionada
            if type(accion) == tuple:
                deshacer.agregar_estado(nivel_actual)
                backtraking.solucion_disponible = False
                nivel_actual = soko.mover(nivel_actual, accion)

            elif accion == "REINICIAR":
                deshacer.agregar_estado(nivel_actual)
                nivel_actual = soko.crear_grilla(grilla)
                backtraking.solucion_disponible = False

            elif accion == "PISTA":
                if not backtraking.solucion_disponible:
                    render.pensando_solucion(nivel_actual)
                    try:
                        backtraking.generar_solucion(nivel_actual)
                    except:
                        render.error_backtracking()
                        ev = gl.wait(gl.EventType.KeyPress)
                        render.cambiar_tamanio_ventana(nivel_actual)

                else:
                    deshacer.agregar_estado(nivel_actual)
                    accion = backtraking.obtener_mov()
                    nivel_actual = soko.mover(nivel_actual, accion)

            elif accion == "DESHACER":
                if deshacer.se_puede_deshacer():
                    nivel_actual = deshacer.deshacer_movimiento()
                    backtraking.solucion_disponible = False
                else:
                    gl.play_sound('src/alert.wav')

            elif accion == "SALIR":
                return

            if soko.juego_ganado(nivel_actual):
                break

        # Paso al siguiente nivel
        nivel_nro += 1

        # Verifica que haya terminado todos los niveles
        if nivel_nro >= len(niveles):

            tiempo_final = time.time()
            tiempo_total = tiempo_final - tiempo_inicial

            # Genera horas, minutos y segundos
            tiempo = "Tiempo total " + convertir_segundos(tiempo_total)

            render.final((x, y), tiempo)

            ev = gl.wait(gl.EventType.KeyPress)

            return
Beispiel #21
0
def main():
    niveles = cargar_memoria("niveles.txt")
    configuracion = cargar_configuracion_teclas("teclas.txt")
    for nivel in niveles:
        # Inicializar el estado del juego
        grilla = soko.crear_grilla(nivel[1])
        gamelib.resize(len(grilla[0]) * 64, len(grilla) * 64)
        movimientos = Pila()

        while gamelib.is_alive():
            # Dibujar la pantalla
            gamelib.draw_begin()
            juego_mostrar(grilla, nivel[0])
            gamelib.draw_end()

            ev = gamelib.wait(gamelib.EventType.KeyPress)
            if not ev:
                break

            tecla = ev.key
            accion = pedir_accion(configuracion, tecla)

            # Actualizar el estado del juego, según la `tecla` presionada

            if accion == "PISTA":
                gamelib.draw_begin()
                juego_mostrar(grilla, nivel[0])
                gamelib.draw_text("Pensando...", 40, 10, size=10, fill="white")
                gamelib.draw_end()
                solucion = buscar_solucion(grilla)
                gamelib.get_events()

                if not solucion[0]:
                    gamelib.draw_begin()
                    juego_mostrar(grilla, nivel[0])
                    gamelib.draw_text("No hay pistas disponibles :(",
                                      85,
                                      10,
                                      size=10,
                                      fill="white")
                    gamelib.draw_end()
                    ev = gamelib.wait(gamelib.EventType.KeyPress)
                    continue

                if solucion[0]:
                    gamelib.draw_begin()
                    juego_mostrar(grilla, nivel[0])
                    gamelib.draw_text("Pista Disponible",
                                      50,
                                      10,
                                      size=10,
                                      fill="white")
                    gamelib.draw_end()
                    while not solucion[1].esta_vacia():
                        ev = gamelib.wait(gamelib.EventType.KeyPress)
                        if not ev:
                            break
                        tecla = ev.key
                        accion = pedir_accion(configuracion, tecla)
                        if accion != None and accion != "PISTA":
                            break
                        if accion == "PISTA":
                            movimientos.apilar(grilla)
                            grilla = soko.mover(grilla,
                                                solucion[1].desapilar())
                            gamelib.draw_begin()
                            juego_mostrar(grilla, nivel[0])
                            gamelib.draw_text("Pista Disponible",
                                              50,
                                              10,
                                              size=10,
                                              fill="white")
                            gamelib.draw_end()

            if soko.juego_ganado(grilla):
                sleep(0.1)
                break

            if accion == "SALIR":
                return

            if accion == "REINICIAR":
                grilla = soko.crear_grilla(nivel[1])
                movimientos = Pila()
                continue

            if accion == "DESHACER":
                if movimientos.esta_vacia():
                    continue
                grilla = movimientos.desapilar()
                continue

            if not accion:
                continue

            movimientos.apilar(grilla)
            grilla = soko.mover(grilla, accion)

            if soko.juego_ganado(grilla):
                gamelib.draw_begin()
                juego_mostrar(grilla, nivel[0])
                gamelib.draw_end()
                sleep(0.1)
                break
Beispiel #22
0
def main():
    # Inicializar el estado del juego

    nivel_inicial = 1

    dic_niveles_grilla = leer_niveles("niveles.txt")

    grilla = dic_niveles_grilla[nivel_inicial]

    tablero_mov = PilaMovimiento()

    cola_pista = ColaPista()

    tamaño = cargar_tamaño(grilla)

    x, y = tamaño

    cont_indices = 0

    if x > 300 or y > 300:
        gamelib.resize(
            x * 5, y * 5
        )  # Agrando la pantalla en base a gamelib(300 px) dividido la cant de px que tengo por celda (60px) = 5

    else:

        gamelib.resize(300, 300)

    while gamelib.is_alive():

        gamelib.draw_begin()
        # Dibujar la pantalla
        dibujo_juego(grilla)
        gamelib.draw_end()

        ev = gamelib.wait(gamelib.EventType.KeyPress)

        if not ev:
            break

        tecla = ev.key

        # Actualizar el estado del juego, según la `tecla` presionada

        if ev.type == gamelib.EventType.KeyPress and tecla == 'Escape':
            # El usuario presionó la tecla Escape, cerrar la aplicación.
            break

        if ev.type == gamelib.EventType.KeyPress and tecla == 'w':
            # El usuario presiono la tecla w, mover hacia arriba.
            grilla = soko.mover(grilla, coordenadas_teclas('w', grilla))
            grilla, nivel_inicial = pasar_nivel(grilla, dic_niveles_grilla,
                                                nivel_inicial)
            tablero_mov.apilar(grilla)

        if ev.type == gamelib.EventType.KeyPress and tecla == 's':
            # El usuario presiono la tecla s, mover hacia abajo
            grilla = soko.mover(grilla, coordenadas_teclas('s', grilla))
            grilla, nivel_inicial = pasar_nivel(grilla, dic_niveles_grilla,
                                                nivel_inicial)
            tablero_mov.apilar(grilla)

        if ev.type == gamelib.EventType.KeyPress and tecla == 'd':
            # El usuario presiono la tecla d, mover hacia la derecha
            grilla = soko.mover(grilla, coordenadas_teclas('d', grilla))
            grilla, nivel_inicial = pasar_nivel(grilla, dic_niveles_grilla,
                                                nivel_inicial)
            tablero_mov.apilar(grilla)

        if ev.type == gamelib.EventType.KeyPress and tecla == 'a':
            #El usuario presiono la tecla a, mover hacia la izquierda
            grilla = soko.mover(grilla, coordenadas_teclas('a', grilla))
            grilla, nivel_inicial = pasar_nivel(grilla, dic_niveles_grilla,
                                                nivel_inicial)
            tablero_mov.apilar(grilla)

        if ev.type == gamelib.EventType.KeyPress and tecla == 'r':
            #El usuario presiono la tecla r, reiniciar la posicion
            grilla = dic_niveles_grilla[nivel_inicial]
            tablero_mov.apilar(grilla)

        if ev.type == gamelib.EventType.KeyPress and tecla == 'u':
            #El usuario presiono la tecla u, deshacer la posicion
            if tablero_mov.esta_vacia():
                grilla = dic_niveles_grilla[nivel_inicial]
            else:
                grilla = tablero_mov.desapilar()

        if ev.type == gamelib.EventType.KeyPress and tecla == 'c':
            #El usuario presiono la tecla c, dar pista
            if not cola_pista.esta_vacia():
                mov = cola_pista.desencolar()
                grilla = soko.mover(grilla, mov)
                grilla, nivel_inicial = pasar_nivel(grilla, dic_niveles_grilla,
                                                    nivel_inicial)
            else:
                pista, movs = buscar_solucion(
                    dic_niveles_grilla[nivel_inicial], nivel_inicial)
                for mov in movs[::-1]:
                    cola_pista.encolar(mov)
Beispiel #23
0
def main():
    # Inicializar el estado del juego
    deshacer = Pila()
    pistas = []

    teclas = archivo_teclas(RUTA_TECLAS)
    niveles = archivo_niveles(RUTA_NIVELES)

    contador = es_nivel(gamelib.input("Eliga un nivel:"), niveles)
    juego = emparejar(niveles[contador])  #lista de cadenas

    c, f = soko.dimensiones(juego)
    gamelib.resize(c * DIM_CELDA, f * DIM_CELDA)

    juego = soko.crear_grilla(juego)  #lista de listas
    dibujar_juego(contador, juego, 1)

    while gamelib.is_alive():
        ev = gamelib.wait(gamelib.EventType.KeyPress)
        if not ev:
            break
        # Actualizar el estado del juego, según la `tecla` presionada
        tecla = ev.key

        if es_tecla(tecla, teclas) == None:
            continue

        if tecla == 'Escape':
            gamelib.say("Gracias por jugar Sokoban :)")
            break

        if tecla == 'h':
            if len(pistas) == 0:
                pistas = backtraking(contador, juego)
                if pistas == None:
                    pistas = []
            else:
                pista = pistas.pop()
                juego = soko.mover(juego, pista)
                deshacer.apilar(juego)
                dibujar_juego(contador, juego, 2)  #pista disponible

        if soko.juego_ganado(juego):
            contador += 1
            while not deshacer.esta_vacia():
                deshacer.desapilar()
            gamelib.say("Pasaste al siguiente nivel :)")

            juego = emparejar(niveles[contador])
            c, f = soko.dimensiones(juego)
            gamelib.resize(c * DIM_CELDA, f * DIM_CELDA)
            juego = soko.crear_grilla(juego)
            dibujar_juego(contador, juego, 1)

        if tecla == 'r':
            if len(pistas) != 0:
                pistas = []
            juego = emparejar(niveles[contador])
            c, f = soko.dimensiones(juego)
            gamelib.resize(c * DIM_CELDA, f * DIM_CELDA)
            juego = soko.crear_grilla(juego)
            dibujar_juego(contador, juego, 1)

        if tecla == 'Control_L':
            if not deshacer.esta_vacia():
                juego = deshacer.desapilar()
            dibujar_juego(contador, juego, 1)

        if teclas[tecla] in DIRECCIONES:
            deshacer.apilar(juego)
            juego = soko.mover(juego, DIRECCIONES[teclas[tecla]])
            dibujar_juego(contador, juego, 1)

        if tecla != 'h':  #vaciar la lista
            if len(pistas) != 0:
                pistas = []
Beispiel #24
0
def test7():
    desc = [
        '    ###   ',
        '    #.#   ',
        '    #$#   ',
        '   ##$####',
        '####@ $$.#',
        '#.$$  ####',
        '####$##   ',
        '   #$#    ',
        '   #.#    ',
        '   ###    ',
    ]
    grilla = soko.crear_grilla(desc)

    assert soko.mover(grilla, OESTE) == grilla
    assert soko.mover(grilla, NORTE) == grilla

    grilla = soko.mover(grilla, ESTE)

    assert soko.mover(grilla, ESTE) == grilla
    assert soko.mover(grilla, NORTE) == grilla

    grilla = soko.mover(grilla, SUR)

    assert soko.mover(grilla, ESTE) == grilla
    assert soko.mover(grilla, SUR) == grilla

    grilla = soko.mover(grilla, OESTE)

    assert soko.mover(grilla, OESTE) == grilla
    assert soko.mover(grilla, SUR) == grilla