Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import json
- import api
- def analyser_commande():
- parser = argparse.ArgumentParser(description="Jeu Quoridor - phase 1")
- parser.add_argument('idul', help='IDUL du joueur')
- parser.add_argument(
- '-l', '--lister', action = 'store_true',
- help="Lister les identifiants de vos 20 dernières parties."
- )
- return parser.parse_args()
- print(analyser_commande())
- def afficher_damier_ascii(dico):
- """Description:
- Une fonction qui permet d'afficher un damier complet."""
- res = f'Légende: 1={dico["joueurs"][0]["nom"]}, 2={dico["joueurs"][1]["nom"]}' + '\n' + ' ' + '-'*35 + '\n'
- for y in range(18, 1, -1):
- if y % 2 == 0:
- res += str(int(y / 2)) + ' | '
- for x in range(0, 8, 1):
- if dico["joueurs"][0]["pos"] == [x + 1, y / 2]:
- res += '1 '
- elif dico["joueurs"][1]["pos"] == [x + 1, y / 2]:
- res += '2 '
- else:
- mur_présent2 = False
- mur_présent5 = False
- for mur_vertical in dico["murs"]["verticaux"]:
- if [x + 2, (y) // 2] == mur_vertical:
- mur_présent2 = True
- if [x + 2, ((y) // 2)-1] == mur_vertical:
- mur_présent5 = True
- if mur_présent2 == True:
- res += '. | '
- elif mur_présent5 == True:
- res += '. | '
- else:
- res += '. '
- if dico["joueurs"][0]["pos"] == [9, y]:
- res += '1 ' + '|'
- elif dico["joueurs"][1]["pos"] == [9, y]:
- res += '2 ' + '|'
- else:
- res += '. ' + '|'
- else:
- res += '\n' + ' |'
- for x in range(1, 10):
- if x != 9:
- murs_présent4 = False
- murs_présent3 = False
- for mur_horizontal in dico["murs"]["horizontaux"]:
- if [x - 1, (y + 1) // 2] == mur_horizontal:
- murs_présent3 = True
- if mur_horizontal == [x, (y + 1) // 2]:
- murs_présent4 = True
- if murs_présent4 == True:
- res += '-' * 4
- elif murs_présent3 == True:
- mur_présent6 = False
- for mur_vertical in dico["murs"]["verticaux"]:
- if [x + 1, (y) // 2] == mur_vertical:
- mur_présent6 = True
- if mur_présent6 == True:
- res += '---|'
- else:
- res += '--- '
- else:
- mur_présent1 = False
- for mur_vertical in dico["murs"]["verticaux"]:
- if [x + 1, (y) // 2] == mur_vertical:
- mur_présent1 = True
- if mur_présent1 == True:
- res += ' |'
- else:
- res += ' ' * 4
- else:
- res += ' |' + '\n'
- res += '\n' + '--|-----------------------------------' + '\n' + ' | 1 2 3 4 5 6 7 8 9'
- return res
- if __name__ == '__main__':
- analyser = analyser_commande()
- if analyser.lister:
- print(api.lister_parties(analyser.idul))
- else:
- afficher_damier_ascii(api.débuter_partie(analyser.idul)[1])
- id_partie = api.débuter_partie(analyser.idul)[0]
- pas_victoire = True
- while pas_victoire:
- type_coup = input("entrer le type de coup (D, MH ou MV)")
- position = input("entrer la position sous forme de tuple")
- choix_jeu = True
- while choix_jeu:
- try:
- afficher_damier_ascii(api.jouer_coup(id_partie, type_coup, position))
- choix_jeu = False
- except StopIteration as fin:
- pas_victoire = False
- choix_jeu = False
- print(f'Victoire de {fin}')
- except RuntimeError as re:
- choix_jeu = False
- print(re)
- print(afficher_damier_ascii({
- "joueurs": [
- {"nom": "idul", "murs": 7, "pos": [5, 5]},
- {"nom": "automate", "murs": 3, "pos": [3, 8]}
- ],
- "murs": {
- "horizontaux": [[4, 4], [2, 6], [3, 8], [5, 8], [7, 8]],
- "verticaux": [[6, 2], [4, 4], [2, 6], [7, 5], [7, 7]]
- }
- }
- ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement