Beispiel #1
0
def main():
    """Fonction principale du jeu quoridor"""
    parsed_args = analyser_commande()
    game_idul = initialiser_partie(parsed_args.idul)
    game_state = game_idul['état']
    lister_parties(parsed_args.idul)
    game_completed = False

    while not game_completed:
        afficher_damier_ascii(game_state)
        print(
            'Types de coups disponibles: \n'
            ' - D: Deplacement \n - MH: Mur Horizontal \n - MV: Mur Vertical \n\n'
        )

        type_coup = input('Choisissez votre type de coup (D, MH ou MV)')
        print('Vous avez effectué le coup ' + type_coup)

        ligne = input("Definissez la ligne de votre coup")
        print('Vous avez entré la ligne ' + ligne)

        colonne = input('Definissez la colonne de votre coup')
        print('Vous avez entré la colonne ' + colonne)

        position = [colonne, ligne]
        id_partie = game_idul['id']
        game_state = jouer_coup(id_partie, type_coup, position)
Beispiel #2
0
def game():
    """Jouer en console"""
    analyser = analyser_commande()
    partie_id = initialiser_partie(analyser.idul)
    print('\n')
    if analyser.lister:
        print(lister_parties(analyser.idul), '\n')
    print(afficher_damier_ascii(partie_id[1]))
    while 1:
        try:
            position = list(
                map(
                    int,
                    input('Entrez les coordonnees du coup  x, y: ').strip().
                    split(',')))
            mouvement = input('Entrez le type de coup MH, MV ou D: ')
        except ValueError:
            print('La valeur entree est incorrect')
            position = list(
                map(
                    int,
                    input('Entrez les coordonnees du coup  x, y: ').strip().
                    split(',')))
            mouvement = input('Entrez le type de coup MH, MV ou D: ')
        else:
            print(
                afficher_damier_ascii(
                    jouer_coup(partie_id[0], mouvement, position)))
Beispiel #3
0
def main():
    """Boucle principale."""
    args = analyser_commande()

    if args.lister:
        for partie in api.lister_parties(args.idul):
            print(partie["id"])
        return

    id_partie, partie = api.débuter_partie(args.idul)
    gagnant = False
    q = None

    while not gagnant:
        if args.mode_graphique:
            q = QuoridorX(partie["joueurs"], partie["murs"])
        else:
            q = Quoridor(partie["joueurs"], partie["murs"])

        gagnant = q.partie_terminée()
        if gagnant:
            break

        if args.mode_graphique:
            q.afficher()
        else:
            print("", q, sep="\n")

        partie = jouer_coup(args, q, id_partie)

    if args.mode_graphique:
        turtle.mainloop()
    else:
        print("", q, "", f'{gagnant} a gagné la partie!', "", sep="\n")
Beispiel #4
0
def analyser_commande():
    parser = argparse.ArgumentParser(description="Jeu Quoridor - phase 1")
    parser.add_argument('idul', type=str, help='IDUL du joueur.')
    parser.add_argument('-l', '--lister', action='store_true',
     help='Lister les identifiants de vos 20 dernières parties.')
    args = parser.parse_args()
    analyser_commande.idul = args.idul
    if args.lister:
        return lister_parties(args.idul)
    return args
Beispiel #5
0
def main():
    command = analyser_commande()
    debut = api.lister_parties(command.idul)
    pp.pprint(debut)
    afficher_damier_ascii(debut['parties'][0]['état'])
    for i in debut['parties']:
        if i['id'] == id:
            afficher_damier_ascii(i['état'])
    while True:
        print("Type de coup ['D', 'MH', 'MV']: ")
        type_coup = input()
        print("Position x: ")
        position_x = int(input())
        print("Position y: ")
        position_y = int(input())
        position = (position_x, position_y)
        pp.pprint(api.jouer_coup(id, type_coup, position))
        etat = api.lister_parties(command.idul)
        for i in etat['parties']:
            if i['id'] == id:
                afficher_damier_ascii(i['état'])
Beispiel #6
0
def listing(idul):
    '''def listing(idul)
    Description:
        une fonction qui affiche les 20 dernières parties
    Input:
        idul (str)
            le idul du joueur
    Return:
        une liste contenant les réponses du joueur
    '''
    gamelist = api.lister_parties(idul)
    print("voici la liste de vos 20 dernières parties jouées")
    # itérer sur chaque parties à afficher
    for gamenumber, game in enumerate(gamelist):
        print("partie NO.", gamenumber)
        print("game ID:", game['id'])
        jeu = quoridor.Quoridor(game['état']['joueurs'], game['état']['murs'])
        print(jeu)
Beispiel #7
0
                    POS_COUP = (int(LIST_POS_COUP[0]), int(LIST_POS_COUP[1]))
                except Exception:
                    raise AssertionError("Le format entré est invalide")

                if TYPE_COUP == 'D':
                    assert 1 <= POS_COUP[0] <= 9 and 1 <= POS_COUP[
                        1] <= 9, "Indice invalide"
                else:
                    assert 2 <= POS_COUP[0] <= 9 and 1 <= POS_COUP[
                        1] <= 8, "Indice invalide"

                ETAT = api.jouer_coup(ID_PARTIE, TYPE_COUP, POS_COUP)

                afficher_damier_ascii(ETAT)

            except AssertionError as err:
                print(err)

            except RuntimeError as err:
                print(err)

            except StopIteration as gagnant:
                print(str(gagnant) + 'a gagné la partie!')
                EN_JEU = False

            except KeyboardInterrupt:
                print("\nPartie annulée par l'utilisateur\n")
                EN_JEU = False
    else:
        print(api.lister_parties(IDUL_ARG))
Beispiel #8
0
    if type_coup not in ["D", "MH", "MV"]:
        return ask_type()
    return type_coup


def ask_coords():
    try:
        return literal_eval(input("coords (x,y) : "))
    except ValueError as _:
        return ask_coords()


if __name__ == "__main__":
    args = analyser_commande()
    if args.lister is not None:
        print(api.lister_parties(args.idul)[:20])

    id_game, board = api.initialiser_partie(args.idul)

    while True:
        try:
            afficher_damier_ascii(board)
            type_coup = ask_type()
            coords = ask_coords()
            board = api.jouer_coup(id_game, type_coup, coords)
        except StopIteration as e:
            print(e)
            break
        except RuntimeError as e:
            print(e)
Beispiel #9
0
    fin2 = '  | 1   2   3   4   5   6   7   8   9'
    tot = list(sui + fin + fin2)
    for j in range(len(dico)):
        tot[40 * (18 - 2 * dico['joueurs'][j]['pos'][1]) +
            4 * dico['joueurs'][j]['pos'][0]] = str(j + 1)
    for i in dico['murs']['horizontaux']:
        for ading in range(7):
            tot[40 * (19 - 2 * i[1]) + 4 * i[0] - 1 + ading] = '-'
    for place in dico['murs']['verticaux']:
        for adding in range(3):
            tot[40 * (18 - adding - 2 * place[1]) + 4 * place[0] - 2] = '|'
    return deb + ''.join(tot)


if analyser_commande().lister:
    print(api.lister_parties(analyser_commande().idul)['parties'])
else:
    IDUL = a.idul
    v = api.débuter_partie(IDUL)
    if v.get('message') is not None:
        print(v['message'])
    else:
        q = afficher_damier_ascii(v['état'])
        print(q)
        CTE = v['id']
        v = 0
        while v < 1:
            b = input('Veuillez choisir un type de coup ! D, MH ou MV : ')
            c = input('Sélectionnez un point ! (x, y) : ')
            a = api.jouer_coup(CTE, b, c)
            if str(a) == a:
Beispiel #10
0
                if (pos[0] < 10 and pos[0] >= 0) and (pos[1] < 10
                                                      and pos[1] >= 0):
                    ok2 = True
                else:
                    print('Données invalides   ex: 2,3')
            else:
                print('INVALIDE -Entrez seulement des chiffres   ex: 2,3')
        else:
            print('INVALIDE -Entrez exactement 2 données   ex: 2,3')
    return pos


GAMEDONE = False
AN = analyser_commande()
if AN.lister:
    print(api.lister_parties(AN.idul))
else:
    IDGAME, STATE = api.débuter_partie(AN.idul)
    while not GAMEDONE:
        afficher_damier_ascii(STATE)
        try:
            print('\n\n\nChoisissez une option parmi les suivantes:')
            print('\n1- Déplacer son joueur')
            print('2- Placer un mur horizontal')
            print('3- Placer un mur vertical')
            print('4- Quitter')
            OK = False
            while not OK:
                CHOIX = input()
                if str(CHOIX) == '1':
                    OK = True
Beispiel #11
0
    for i, j in enumerate(mv):
        for k in range(3):
            ligne = list(damier[18 - 2 * (j[1]) + k])
            ligne[((j[0] - 2) * 4 + 4) + 2] = '|'
            ligne = str(''.join(ligne))
            damier[18 - 2 * (j[1]) + k] = ligne

    return print(''.join(damier))


if __name__ == "__main__":
    ARGS = analyser_commande()
    IDUL = ARGS.idul
    if ARGS.lister is True:
        print(api.lister_parties(IDUL))
    else:
        ID_PARTIE, ÉTAT_JEU = api.débuter_partie(IDUL)
        afficher_damier_ascii(ÉTAT_JEU)
        while True:
            try:
                TYPE_COUP = input(
                    'Entrez votre coup: D pour un déplacement, '
                    'MH pour un mur horizontal ou MV pour un mur vertical: ')
                POSITION = input(
                    'Entrez les coordonnées du couple pour votre coup : ')
                ÉTAT_JEU = api.jouer_coup(ID_PARTIE, TYPE_COUP, POSITION)
                afficher_damier_ascii(ÉTAT_JEU)
            except RuntimeError as err:
                print(err)
            except StopIteration as err:
Beispiel #12
0
    plateau[8 - y_1 + 1][(x_1 - 1)*4] = '1'
    plateau[8 - y_2 + 1][(x_2 - 1)*4] = '2'

    for i in range(9):
        plateau[i].insert(0, str(9-i) + ' | ')

    plateau.append(['--|-----------------------------------\n'])
    plateau.append([' ', ' ', '| ', '1', '   2', '   3', '   4'
                    , '   5', '   6', '   7', '   8', '   9'])
    plateau[8] = plateau[8][:36]

    for pos in dic['murs']['horizontaux']:
        x, y = pos
        for i in range(7):
            plateau[9-y][35 + x*4 + i] = '-'

    for pos in dic['murs']['verticaux']:
        x, y = pos
        plateau[9-y-1][x*4 -5] = '|'
        plateau[9-y-1][34 + x*4] = '|'
        plateau[9-y][x*4 -5] = '|'

    print(premiere_ligne + ''.join(''.join(i for i in ligne) for ligne in plateau) + '\n')


if analyser_commande().lister:
    print(lister_parties(analyser_commande().idul))
else:
    jouer()
Beispiel #13
0
    jeu = QuoridorX(joueur)
    while 1:
        (coup, pos) = jeu.jouer_coup(1)
        jeu.afficher()
        état = jouer_coup(identifiant, coup, tuple(pos))
        joueur1 = état['joueurs']
        murs_j1 = état['murs']
        jeu = QuoridorX(joueur1, murs_j1)


if __name__ == '__main__':
    analyser_commande()

FONC = analyser_commande()
if FONC.lister:
    lister_parties(FONC.idul)

if not FONC.lister:
    pass


def quoridorgame(arg):
    """ Fonction servant a jouer au jeu """
    idul = arg.idul

    # Mode manuel
    if not (arg.automatique or arg.graphique):
        mode_manuel(idul)

    # mode automatique
    if arg.automatique and not arg.graphique:
Beispiel #14
0
            damier += "  |"
            for j in range(35):
                if ((j - 3) % 4) == 0 and mursh[j][(i // 2)] == " ":
                    damier += mursv[int((j - 3) / 4)][i]
                else:
                    damier += mursh[j][(i // 2)]
        damier += "|\n"
    damier += "--|" + (35 * "-") + "\n  |"
    for i in range(9):
        damier += " " + str(i + 1) + "  "
    print(damier[:-2])


ANALYSEUR = analyser_commande()
if ANALYSEUR.affichage:
    print(api.lister_parties(ANALYSEUR.idul))
else:
    PARTIE = api.débuter_partie(ANALYSEUR.idul)
    ETAT = PARTIE[1]
    IDPARTIE = PARTIE[0]
    PARTIETERMINEE = False
    while not PARTIETERMINEE:
        afficher_damier_ascii(ETAT)
        ERROR = True
        while ERROR:
            try:
                print("\nQuelle action voulez-vous effectuer?")
                print("1- Vous déplacer")
                print("2- Placer un mur horizontal")
                print("3- Placer un mur vertical")
                print("\n4- Quitter")
Beispiel #15
0
                        action='store_true',
                        help="Activer le mode automatique.")
    # -x
    parser.add_argument("-x",
                        '--graphique',
                        action='store_true',
                        help="Activer le mode graphique.")

    return parser.parse_args()


if __name__ == "__main__":
    COMMANDE = analyser_commande()

    if COMMANDE.lister:
        print(api.lister_parties(COMMANDE.idul))

    # Mode automatique avec graphique (commande : python main.py -ax idul)
    elif COMMANDE.automatique and COMMANDE.graphique:
        DEBUTER = api.débuter_partie(COMMANDE.idul)
        JEU = quoridorx.QuoridorX(DEBUTER[1]['joueurs'], DEBUTER[1]['murs'])
        ID_PARTIE = DEBUTER[0]

        JEU.afficher()

        GAGNANT = True
        while GAGNANT:
            try:
                COUP = JEU.jouer_coup(1)

                JOUER = api.jouer_coup(ID_PARTIE, COUP[0], COUP[1])