main game
This commit is contained in:
parent
88ecb3a2e2
commit
7a10317630
1 changed files with 79 additions and 0 deletions
79
marinbad/game_numy.py
Normal file
79
marinbad/game_numy.py
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
from AI import AI
|
||||||
|
from Board import Board
|
||||||
|
from os import system
|
||||||
|
from random import shuffle
|
||||||
|
|
||||||
|
|
||||||
|
def play(board: list, **kwargs):
|
||||||
|
def strArray(array):
|
||||||
|
"""
|
||||||
|
Convert an array to a string array and add one to every value
|
||||||
|
Used to stringigy range() and start value from 1
|
||||||
|
:param array:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return [str(el + 1) for el in array]
|
||||||
|
|
||||||
|
def intable(value):
|
||||||
|
"""
|
||||||
|
Return True if value can be cast to integer
|
||||||
|
:param value: The value to convert in integer
|
||||||
|
:type value str
|
||||||
|
:return: bool
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
int(value)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Filter row input
|
||||||
|
row = "string"
|
||||||
|
strRange = strArray(range(len(board)))
|
||||||
|
while not(intable(row)) or not(row in strRange):
|
||||||
|
row = input(f"Choisissez une rangée entre 1 et {len(board)}: ")
|
||||||
|
row = int(row)
|
||||||
|
|
||||||
|
# Filter remove allumettes
|
||||||
|
remove = "0"
|
||||||
|
while not(intable(remove)) or not("1" <= remove <= str(board[row - 1])):
|
||||||
|
remove = input(f"Choisissez le nombre d'allumettes à retirer entre 1 et {board[row - 1]}: ")
|
||||||
|
remove = int(remove)
|
||||||
|
|
||||||
|
print(f"{kwargs['name']}: L{row} => {remove}")
|
||||||
|
# Return board after player move
|
||||||
|
return game_board.retirer(board, row, remove)
|
||||||
|
|
||||||
|
|
||||||
|
game_board = Board()
|
||||||
|
|
||||||
|
players = [
|
||||||
|
{
|
||||||
|
"name": "Jean Yves",
|
||||||
|
"func": play
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gérald",
|
||||||
|
"func": AI().compute
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
# Choisi le 1er joueur
|
||||||
|
shuffle(players)
|
||||||
|
|
||||||
|
# Creation du plateau de jeu
|
||||||
|
print("Entrez une liste sous cette forme: X Y Z A B C")
|
||||||
|
allumettes = [int(el) for el in input(">>> ").split(" ")]
|
||||||
|
|
||||||
|
print(f"Voici l'ordre des joueurs: {' => '.join([player['name'] for player in players])}")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
for player in players:
|
||||||
|
game_board.show_board(allumettes)
|
||||||
|
|
||||||
|
allumettes = player["func"](allumettes, name=player["name"])
|
||||||
|
|
||||||
|
if game_board.nb_allumettes(allumettes) == 0:
|
||||||
|
print(f"Le {player['name']} à gagné !!")
|
||||||
|
exit(0)
|
||||||
|
print("")
|
Loading…
Reference in a new issue