olimpiada/ejercicios/olimpiada I/life_game.py
def comprobar_vecindario(tablero, y, x, vecinas_para_sobrevivir, vecinas_para_nacer):
    """Comprueba el numero de celulas vecinas"""
    merece_vivir = False
    cv = 0
    pre_y = y
    pre_x = x
    post_x = None
    post_y = None
    if y <= len(tablero)-2:
        post_y = y+1
    # else:
        # post_y = 0
    if x <= len(tablero[y])-2:
        post_x = x+1
    # else:
        # post_x = 0
    if tablero[pre_y][pre_x] == celda["viva"]:
        cv += 1
    if tablero[pre_y][x] == celda["viva"]:
        cv += 1
    if tablero[y][pre_x] == celda["viva"]:
        cv += 1
    if (post_x is None) and (post_y is None):
        pass
    else:
        if post_x is None:
            if tablero[post_y][pre_x] == celda["viva"]:
                cv += 1
            if tablero[post_y][x] == celda["viva"]:
                cv += 1
        if post_y is None:
            if tablero[pre_y][post_x] == celda["viva"]:
                cv += 1
            if tablero[y][post_x] == celda["viva"]:
                cv += 1
        if (post_x is not None) and (post_y is not None):
            if tablero[post_y][post_x] == celda["viva"]:
                cv += 1

    cell = tablero[y][x]
    tablero[y][x] = "·"
    mostrar_tablero(tablero)
    tablero[y][x] = cell
    print cv
    if tablero[y][x] == celda["viva"]:
        print "vecinas_para_sobrevivir:", vecinas_para_sobrevivir
        for vps in vecinas_para_sobrevivir:
            if cv == vps:
                merece_vivir = True
            print "vps", vps, "cv", cv, "cv == vps", cv == vps, "merece_vivir", merece_vivir
        if merece_vivir == False:
            tablero[y][x] = celda["vacia"]
    else:
        print "vecinas_para_nacer:", vecinas_para_nacer
        if tablero[y][x] == celda["vacia"]:
            for vpn in vecinas_para_nacer:
                if cv == vpn:
                    merece_vivir = True
                print "vpn", vpn, "cv", cv, "cv == vpn", cv == vpn, "merece_vivir", merece_vivir
            if merece_vivir == True:
                tablero[y][x] = celda["viva"]
Comprueba el numero de celulas vecinas
Comprueba el numero de celulas vecinas
Comprueba el numero de celulas vecinas
def comprobar_vecindario(tablero, y, x, vecinas_para_sobrevivir, vecinas_para_nacer):
    merece_vivir = False
    cv = 0
    pre_y = y
    pre_x = x
    post_x = None
    post_y = None
    if y <= len(tablero)-2:
        post_y = y+1
    if x <= len(tablero[y])-2:
        post_x = x+1
    if tablero[pre_y][pre_x] == celda["viva"]:
        cv += 1
    if tablero[pre_y][x] == celda["viva"]:
        cv += 1
    if tablero[y][pre_x] == celda["viva"]:
        cv += 1
    if (post_x is None) and (post_y is None):
        pass
    else:
        if post_x is None:
            if tablero[post_y][pre_x] == celda["viva"]:
                cv += 1
            if tablero[post_y][x] == celda["viva"]:
                cv += 1
        if post_y is None:
            if tablero[pre_y][post_x] == celda["viva"]:
                cv += 1
            if tablero[y][post_x] == celda["viva"]:
                cv += 1
        if (post_x is not None) and (post_y is not None):
            if tablero[post_y][post_x] == celda["viva"]:
                cv += 1
    cell = tablero[y][x]
    tablero[y][x] = "·"
    mostrar_tablero(tablero)
    tablero[y][x] = cell
    print cv
    if tablero[y][x] == celda["viva"]:
        print "vecinas_para_sobrevivir:", vecinas_para_sobrevivir
        for vps in vecinas_para_sobrevivir:
            if cv == vps:
                merece_vivir = True
            print "vps", vps, "cv", cv, "cv == vps", cv == vps, "merece_vivir", merece_vivir
        if merece_vivir == False:
            tablero[y][x] = celda["vacia"]
    else:
        print "vecinas_para_nacer:", vecinas_para_nacer
        if tablero[y][x] == celda["vacia"]:
            for vpn in vecinas_para_nacer:
                if cv == vpn:
                    merece_vivir = True
                print "vpn", vpn, "cv", cv, "cv == vpn", cv == vpn, "merece_vivir", merece_vivir
            if merece_vivir == True:
                tablero[y][x] = celda["viva"]
def comprobar_vecindario ( tablero , y , x , vecinas_para_sobrevivir , vecinas_para_nacer ) : merece_vivir = False cv = 0 pre_y = y pre_x = x post_x = None post_y = None if y <= len ( tablero ) - 2 : post_y = y + 1 if x <= len ( tablero [ y ] ) - 2 : post_x = x + 1 if tablero [ pre_y ] [ pre_x ] == celda [ "viva" ] : cv += 1 if tablero [ pre_y ] [ x ] == celda [ "viva" ] : cv += 1 if tablero [ y ] [ pre_x ] == celda [ "viva" ] : cv += 1 if ( post_x is None ) and ( post_y is None ) : pass else : if post_x is None : if tablero [ post_y ] [ pre_x ] == celda [ "viva" ] : cv += 1 if tablero [ post_y ] [ x ] == celda [ "viva" ] : cv += 1 if post_y is None : if tablero [ pre_y ] [ post_x ] == celda [ "viva" ] : cv += 1 if tablero [ y ] [ post_x ] == celda [ "viva" ] : cv += 1 if ( post_x is not None ) and ( post_y is not None ) : if tablero [ post_y ] [ post_x ] == celda [ "viva" ] : cv += 1 cell = tablero [ y ] [ x ] tablero [ y ] [ x ] = "·" mostrar_tablero ( tablero ) tablero [ y ] [ x ] = cell print cv if tablero [ y ] [ x ] == celda [ "viva" ] : print "vecinas_para_sobrevivir:" , vecinas_para_sobrevivir for vps in vecinas_para_sobrevivir : if cv == vps : merece_vivir = True print "vps" , vps , "cv" , cv , "cv == vps" , cv == vps , "merece_vivir" , merece_vivir if merece_vivir == False : tablero [ y ] [ x ] = celda [ "vacia" ] else : print "vecinas_para_nacer:" , vecinas_para_nacer if tablero [ y ] [ x ] == celda [ "vacia" ] : for vpn in vecinas_para_nacer : if cv == vpn : merece_vivir = True print "vpn" , vpn , "cv" , cv , "cv == vpn" , cv == vpn , "merece_vivir" , merece_vivir if merece_vivir == True : tablero [ y ] [ x ] = celda [ "viva" ]
Comprueba el numero de celulas vecinas
Comprueba el numero de celulas vecinas
"""Comprueba el numero de celulas vecinas""" # else: # post_y = 0 # else: # post_x = 0
tablero
y
x
vecinas_para_sobrevivir
vecinas_para_nacer