Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
import random import os ON = "O" OFF = "X" uno = { "A" : [1,2,4,5], "B" : [1,3,5], "C" : [2,3,4], "D" : [1,3,5], "E" : [1,2,4,5] } dos = { "A" : [2,3], "B" : [1,2,4,5], "C" : [2,4], "D" : [1,3,5], "E" : [1,3,5] } tres = { "A" : [1,5], "B" : [1,2,4,5], "C" : [3], "D" : [1,3], "E" : [1,3,4] } cuatro = { "A" : [1,2,4,5], "C" : [1,2,4,5], "D" : [5], "E" : [1,2] } cinco = { "A" : [4,5], "B" : [4,5], "D" : [1,2], "E" : [1,2] } NIVELES = [uno, dos, tres, cuatro, cinco] def crear_tablero(dimension=5): """Crea y devuelve un tablero definido por la dimension""" tam_tablero = dimension +1 tablero = [] for fila in range(tam_tablero): tablero.append([" "]*(tam_tablero)) #+1 para los indices return tablero def formato_tablero(tablero): """Da formato a las filas y columnas""" dimension = len(tablero) for i in range(1, dimension): if i == 1: tablero[0][i] = " " + chr(64 + i) else: tablero[0][i] = chr(64+i) for i in range(1, dimension): if i == 10: tablero[i][0] = "10" + "|" else: tablero[i][0] = " " + chr(48+i) + "|" for i in range(1, dimension): for j in range(1, dimension): tablero[i][j] = OFF def mostrar_tablero(tablero): """Imprime un tablero en pantalla""" for fila in range(len(tablero)): if fila == 0: print(" ".join(tablero[fila])) else: print(" ".join(tablero[fila])) def validar_entrada(entrada, dimension = 5): """Valida que el usuario ingrese una posicion dentro del rango""" letra = entrada[0] #va del 1-10, va a ser siempre una unica letra numero = entrada[1:] #puede ser mas largo que uno (10) if numero.isdigit() and not letra.isdigit(): valor_letra = ord(letra.upper()) - 64 valor_numero = int(numero) + 1 if( 0 < valor_letra <= dimension+1 and 0 < valor_numero <= dimension+1): return True return False def entrada_a_coordenada(entrada): """Pasa la entrada a letra y numero""" y = ord(entrada[0].upper()) - 64 x = int(entrada[1]) return x, y def crear_nivel(tablero, nivel): """Crea el nivel tomando como clave la columna, y en fila los numeros respectivos a la letra, que son las posiciones de las luces encendidas""" for fila in nivel: for columna in nivel[fila]: x,y = entrada_a_coordenada(fila+str(columna)) tablero[x][y] = ON def swap_offon(tablero, x, y): """Cambia el estado de las luces en el tablero""" if tablero[x][y] == ON: tablero[x][y] = OFF else: tablero[x][y] = ON def validar_on_off(tablero, pos, mov): """Se fija en los casos borde donde cambia el estado de las luces, valida que estas esten dentro del tablero""" tam = len(tablero) x = pos[0] - mov[0] y = pos[1] - mov[1] if (x < tam and x > 0) and (y < tam and y > 0): swap_offon(tablero, x, y) def mov_onoff(tablero, pos): """Cambia el estado de las luces proximas a la afectada, arriba abajo derecha izquierda""" direcciones = [(0, 1), (0, -1), (1, 0), (-1, 0)] for mov in direcciones: validar_on_off(tablero, pos, mov) swap_offon(tablero, pos[0], pos[1]) def gano_partida(tablero): """Chequea que todas las fichas del tablero esten apagadas para declarar el juego ganado""" dimension = len(tablero) for i in range(1, dimension): for j in range(1, dimension): if tablero[i][j] != OFF: #SI TODAS LAS LUCES ESTAN APAGADAS return False return True def luces_en_on(tablero): """Cuenta la cantidad de luces que hay encendidas en el tablero""" luces_on = 0 dimension = len(tablero) for i in range(1, dimension): for j in range(1, dimension): if tablero[i][j] != OFF: luces_on += 1 return luces_on def condiciones_iniciales(nivel, tam_tablero): """Setea al tablero a las condiciones cero para cuando el usuario elija resetear el nivel""" tablero = crear_tablero(tam_tablero) formato_tablero(tablero) crear_nivel(tablero, nivel[0]) return tablero def jugar_onoff(nivel, tam_tablero=5): """Realiza el proceso de jugar""" gano = False tablero = condiciones_iniciales(nivel, tam_tablero) turnos = len(tablero) * 3 puntaje = 0 os.system('cls' if os.name == 'nt' else 'clear') while not gano and turnos != 0: turnos -= 1 print("-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-") print(nivel[1]) mostrar_tablero(tablero) entrada_valida = True while entrada_valida: coordenada = input("ingrese la fila y la columna en formato A:1") entrada_valida = not validar_entrada(coordenada) coordenada = entrada_a_coordenada(coordenada) mov_onoff(tablero, coordenada) reset = input("Desea Resetear el Nivel? S para continuar, si no, precione cualquier tecla") if reset.upper() == "S": tablero = condiciones_iniciales(nivel, tam_tablero) turnos = len(tablero) * 3 puntaje += -50 * luces_en_on(tablero) mostrar_tablero(tablero) print ("El puntaje parcial es" + str(puntaje)) #LIMPIA LA PANTALLA os.system('cls' if os.name == 'nt' else 'clear') gano = gano_partida(tablero) if gano: puntaje += 500 else: puntaje += -300 print("Nivel Completado") return puntaje def niveles_predeterminado(): """Setea el nivel acorde a nom_nivel, que son los niveles predeterminados""" nom_nivel = ["Uno", "Dos", "Tres", "Cuatro", "Cinco"] puntaje_total = 0 print("LightsOut:") for nivel, nom in zip(NIVELES, nom_nivel): puntaje_nivel = 0 puntaje_nivel = jugar_onoff((nivel,"nivel: " + nom)) puntaje_total += puntaje_nivel print("El puntaje obtenido en este nivel fue de ", puntaje_nivel, "y el puntaje total de esta partida es de ", puntaje_total) def niveles_random(tam_tablero): """Del modulo random importa randrange, que va a dar valores aleatorios a las coordenadas x e y, formando asi los niveles aleatorios""" puntaje_total = 0 nivel_random = {} print("LightsOut:") for nivel in range(5): for i in range(random.randrange(1, (tam_tablero*3))): x = random.randrange(1, tam_tablero) y = random.randrange(1, tam_tablero) x = chr(64+x) if x in nivel_random: nivel_random[x].append(y) else: nivel_random[x] = [y] puntaje_nivel = jugar_onoff((nivel_random,"nivel " + str(nivel+1)), tam_tablero) puntaje_total += puntaje_nivel print("El puntaje obtenido en este nivel fue de ", puntaje_nivel, "y el puntaje total de esta partida es de ", puntaje_total) def main(): """Llama a todas las funciones correspondientes para jugar a Lightsout""" print("Bienvenido a Lightsout") modo_de_juego = (input("Ingrese opcion, " "A: modo predeterminado " "B: modo aleatorio. " "C: salir")).upper() if modo_de_juego == "A": niveles_predeterminado() elif modo_de_juego == "B": dimension_valida = False while not dimension_valida: dimension = int(input("Ingrese una dimension para el tablero, tiene que ser entre 5 y 10.")) if dimension <= 10 and dimension >= 5: dimension_valida = True os.system('cls' if os.name == 'nt' else 'clear') niveles_random(dimension) elif modo_de_juego == "c": exit() else: os.system('cls' if os.name == 'nt' else 'clear') main() main()
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
API-Flaw Profit Guide
CSS | 18 min ago | 0.99 KB
⭐ $12,000 two day
CSS | 37 min ago | 0.99 KB
Schrödinger's Crit
2 days ago | 15.37 KB
PRCE internal cursor
3 days ago | 0.73 KB
AI Interaction Method
3 days ago | 1.60 KB
awkwrapper.c
C | 3 days ago | 2.35 KB
z66is_archive.zip.txt
3 days ago | 39.19 KB
Clients: Setting up 2FA
4 days ago | 1.44 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!