Пример #1
0
def traiterCocher(clu, arguments):
    """
    permet au joueur humain de completer sa fiche en plus de ce que l'ordinateur aura automatique mis à jour
    """
    commande = arguments.split()
    if len(commande) < 4:
        return -1, "La commande cocher doit contenir la categorie et le numéro de la carte, le numéro du joueur et le type d'info\nPar exemple: 1 4 2 + pour indiquer que l'on pense que le joueur 2 possède la carte 4 de la catégorie PERSONNE"
    if commande[3] not in '+-':
        return -1, "L'indication doit être + (possède) ou - (ne possède pas)"
    if commande[0] not in str(carte.PROFESSEUR) + str(carte.MATIERE) + str(
            carte.SALLE):
        return -1, "la catégorie de carte doit être " + str(
            carte.PROFESSEUR) + " " + str(carte.MATIERE) + " " + str(
                carte.SALLE)
    if not commande[1].isdigit() or int(
            commande[1]) not in jeucarte.getListeNumCarteCategorie(
                cluedo.getJeuCartes(cluedo)):
        return -1, "les numéros de carte possibles pour cette catégorie sont " + str(
            jeucarte.getListeNumCarteCategorie(cluedo.getJeuCartes(cluedo)))
    if not commande[1].isdigit() or int(commande[1]) not in range(
            1,
            getNbJoueurs(cluedo) + 1):
        return -1, "les numéros de joueur possibles sont les chiffres entre 1 et " + str(
            getNbJoueurs(cluedo) + 1)
    ficheIndices.connaissance(joueur.getFiche(cluedo.getJoueurCourant(cluedo)),joueur.getNum(cluedo.getJoueurCourant(cluedo)),\
                              int(commande[1]),int(commande[0]),commande[3])
    return 0, "Indication prise en compte"
Пример #2
0
def jouer(clu):
    joueurCourant = cluedo.getJoueurCourant(clu)
    if joueur.estElimine(
            joueurCourant):  # le joueur est éliminé donc il ne peut plus jouer
        return False
    # le joueur courant n'est pas éliminé
    numP = phaseDeplacement(clu)

    # suite du tour
    if numP == cluedo.getNumPieceHypothese(
            clu):  #on est dans la pièce permettant de tenter de gagner
        res = phaseSolution(clu)
    elif numP > 0:  # on est dans une autre pièce
        phaseHypothese(clu, numP)
        res = False
    else:
        res = False
    cluedo.incNumTour(clu)
    return res
Пример #3
0
def phaseHypothese(clu, numP):
    joueurCourant = cluedo.getJoueurCourant(clu)
    numJoueurCourant = joueur.getNum(joueurCourant)
    jeu = cluedo.getJeuCartes(clu)
    courantPrincipal = joueurCourant == cluedo.getJoueurPrincipal(clu)
    courantHumain = joueur.estHumain(joueurCourant)
    information = ""
    messageErreur = ""
    if courantPrincipal:
        debutInformation="Vous êtes dans la pièce "+jeucarte.getNomCarteParNum(jeu,carte.SALLE,numP)+'\n'+\
            'Entrez votre hypothèse sous la forme p,m\n'
        information = jeucarte.stringCat(
            jeu, carte.PROFESSEUR) + '\n' + jeucarte.stringCat(
                jeu, carte.MATIERE) + '\n'
    else:
        debutInformation = "Le joueur " + str(
            numJoueurCourant
        ) + " est dans la pièce " + jeucarte.getNomCarteParNum(
            jeu, carte.SALLE, numP) + '\n'

    # Interaction pour faire une hypothèse
    fini = False
    while not fini:
        cluedo.afficherCluedo(clu,
                              debutInformation + messageErreur + information)
        hp = getHypothese(clu, numP, courantPrincipal and courantHumain)
        fini = hp != None
        messageErreur = "ATTENTION! vous n'avez pas formulé votre hypothèse correctement\n"

    if courantPrincipal:
        information = "Vous pensez que\n"
    else:
        information = "Il pense que\n"
    information+=jeucarte.getNomCarteParNum(jeu,1,hp[1]) +" donnera un cours de "+\
        jeucarte.getNomCarteParNum(jeu,2,hp[2])+" dans la pièce "+jeucarte.getNomCarteParNum(jeu,3,hp[3])+"\n"
    cluedo.afficherCluedo(clu, debutInformation + information)
    input()
    # interrogation des joueurs sur cette hypothèse
    information += interrogerJoueurs(clu, hp)
    cluedo.afficherCluedo(clu, debutInformation + information)
    input()
Пример #4
0
def phaseDeplacement(clu):
    joueurCourant = cluedo.getJoueurCourant(clu)
    numJoueur = joueur.getNum(joueurCourant)
    courantPrincipal = joueurCourant == cluedo.getJoueurPrincipal(clu)
    courantHumain = joueur.estHumain(joueurCourant)
    passageSecret = cluedo.passageSecretJoueurCourant(clu)
    if passageSecret != None:
        numP, lig, col = passageSecret
        rep = getReponsePassage(clu, numP, courantHumain and courantPrincipal)
        if rep == "O":
            if courantPrincipal:
                information = "Vous avez choisi de prendre le passage secret vers la salle " + str(
                    numP) + '\n'
            else:
                information = "Le joueur " + str(
                    numJoueur
                ) + " a choisi de prendre le passage secret vers la salle " + str(
                    numP) + '\n'
            cluedo.deplacerJoueurCourant(clu, lig, col)
            cluedo.afficherCluedo(clu, information)
            return numP

    de, distances = cluedo.jouerDe(clu)

    information = ""
    messageErreur = ""

    if courantPrincipal:
        information += "Les dés valent " + str(de) + "\n" + infoDistance(
            distances) + "\nVeuillez choisir votre pièce destination\n"
    # Interaction pour choisir une destination
    fini1 = False
    while not fini1:
        cluedo.afficherCluedo(clu, messageErreur + information)
        lig, col = getDestination(clu, distances, courantHumain
                                  and courantPrincipal)
        fini1 = lig != -1
        messageErreur = "ATTENTION! Cette pièce n'existe pas\n"

    numP = cluedo.deplacerJoueurCourant(clu, lig, col)
    return numP
Пример #5
0
def phaseSolution(clu):
    joueurCourant = cluedo.getJoueurCourant(clu)
    numJoueurCourant = joueur.getNum(joueurCourant)
    jeu = cluedo.getJeuCartes(clu)
    courantPrincipal = joueurCourant == cluedo.getJoueurPrincipal(clu)
    courantHumain = joueur.estHumain(joueurCourant)
    messageErreur = ""
    information = ""
    if courantPrincipal:
        debutInformation="Vous êtes dans la pièce "+jeucarte.getNomCarteParNum(jeu,carte.SALLE,cluedo.getNumPieceHypothese(clu))+\
        '\nVeuillez formuler votre réponse sous la forme numProf,numMat,numSalle\n'
    else:
        debutInformation="Le joueur "+ str(numJoueurCourant)+" est dans la pièce "+\
            jeucarte.getNomCarteParNum(jeu,carte.SALLE,cluedo.getNumPieceHypothese(clu))+'\n'
    # Interaction pour faire donner une solution
    fini = False
    while not fini:
        cluedo.afficherCluedo(clu,
                              debutInformation + messageErreur + information)
        hp = getLaSolution(clu, courantPrincipal and courantHumain)
        fini = hp != None
        messageErreur = "ATTENTION! vous n'avez pas formulé votre solution correctement\n"

    if courantPrincipal:
        information = "Vous pensez que\n"
    else:
        information = "Il pense que\n"
    information+=jeucarte.getNomCarteParNum(jeu,1,hp[0]) +" donnera un cours de "+\
        jeucarte.getNomCarteParNum(jeu,2,hp[1])+" dans la pièce "+jeucarte.getNomCarteParNum(jeu,3,hp[2])+"\n"
    fini = hp == cluedo.getSolution(clu)
    if fini:
        information += " et c'est la bonne réponse !"
        showinfo('CLUEDO', "BRAVO C'EST GAGNE")
    else:
        information += " et ce n'est pas la bonne réponse !!"
        cluedo.elimineJoueurCourant(clu)

    cluedo.afficherCluedo(clu, debutInformation + information)

    return fini
Пример #6
0
def interrogerJoueurs(clu, hypothese):
    joueurCourant = cluedo.getJoueurCourant(clu)
    ficheJoueurCourant = joueur.getFiche(joueurCourant)
    indiceJoueurCourant = cluedo.getIndiceJoueurCourant(clu)
    nbJoueurs = cluedo.getNbJoueurs(clu)
    listeJoueurs = cluedo.getListeJoueurs(clu)
    information = ""
    for i in range(1, nbJoueurs):
        indiceInterroge = (indiceJoueurCourant + i) % nbJoueurs
        joueurInterroge = listeJoueurs[indiceInterroge]
        numJoueurInterroge = joueur.getNum(joueurInterroge)
        information += "\nle joueur " + str(
            numJoueurInterroge) + " est interrogé"
        if joueur.estHumain(joueurInterroge) and joueurInterroge==cluedo.getJoueurPrincipal(clu) and\
           joueur.reponseHypothese(joueurInterroge,hypothese)!=None:
            cluedo.afficherCluedo(clu, information)
            rep = demanderJoueurHumain(clu, information, joueurInterroge,
                                       hypothese)
        else:
            rep = cluedo.demanderJoueurOrdinateur(clu, joueurInterroge,
                                                  hypothese)
        if rep != None:
            ficheIndices.connaissance(ficheJoueurCourant,numJoueurInterroge,carte.getNum(rep),carte.getCategorie(rep),\
                                      ficheIndices.POSSEDE)
            if joueurCourant == cluedo.getJoueurPrincipal(clu):
                information += "\nLe joueur " + str(
                    numJoueurInterroge) + " vous a montré " + carte.getNom(rep)
            else:
                information += "\nLe joueur " + str(
                    numJoueurInterroge) + " a montré une carte"
            break
        else:
            information += "\nLe joueur " + str(
                numJoueurInterroge) + " ne possède aucune carte"
            for cat, num in hypothese.items():
                for j in range(nbJoueurs):
                    ficheIndices.connaissance(joueur.getFiche(listeJoueurs[j]),numJoueurInterroge,\
                                              num,cat,ficheIndices.NEPOSSEDEPAS)
    return information