Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- import numpy as np
- #init
- format = 4
- jeu = np.zeros((format,format), dtype=np.int)
- perdu = False
- lx = len(jeu)
- ly = len(jeu[0])
- #process
- cx, cy = (randint(0,lx-1),randint(0,ly-1))
- jeu[cx][cy] = randint(1,2) * 2
- print(jeu)
- while not perdu:
- #question
- action = ""
- while (action != "z" and action != "q" and action != "s" and action != "d" and action != "quitter"): #or not possible:
- action = input("Taper 'z/q/s/d' ou 'quitter': ")
- #traitement
- result = jeu.copy()
- while jeu.all() == result.all() and not perdu:
- if action == "z":
- result
- elif action == "q":
- result
- elif action == "s":
- result
- elif action == "d":
- result
- perdu = True
- jeu = result
- #génération
- compteur = []
- for x in range(lx):
- for y in range(ly):
- if jeu[x][y] == 0:
- compteur = compteur + [(x,y)]
- cx, cy = compteur[randint(0,len(compteur)-1)]
- jeu[cx][cy] = randint(1,2) * 2
- #affichage
- print(jeu)
- #score
- perdu = True
- for x in range(lx): #test horizontal
- for y in range(ly-1):
- if jeu[x][y+1] == jeu[x][y] or jeu[x][y] == 0:
- perdu = False
- for x in range(lx-1):
- for y in range(ly):
- if jeu[x+1][y] == jeu[x][y] or jeu[x][y] == 0:
- perdu = False
- if action == "quitter":
- perdu = True
- print("Game Over")
- print(jeu)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement