예제 #1
0
 def reinitialize(self, cards):
     """
 reintialize player for a new round or a new game
 """
     self.Hand = GraphicHand(name=self.name, cards=cards)  #bug with cards
     self.plis = 0
     self.generale = False  #indicator of genereale annonce
예제 #2
0
class GraphicPlayer(Player):
    """
  a game player
  """
    def __init__(self, team_number, name, random, cards, number):
        """
    team number =1 or 0 / random = T or F / cards is an array of cards / number = 1 2 3 or 4
    """
        self.name = name
        self.Hand = GraphicHand(name=name, cards=cards)  #bug with cards
        self.team = team_number
        self.plis = 0
        self.generale = False  #indicator of genereale annonce
        self.random = random
        self.number = "j" + str(number)

    def reinitialize(self, cards):
        """
    reintialize player for a new round or a new game
    """
        self.Hand = GraphicHand(name=self.name, cards=cards)  #bug with cards
        self.plis = 0
        self.generale = False  #indicator of genereale annonce

    def test(self,
             name,
             coeur=0,
             pique=0,
             carreau=0,
             trefle=0,
             points=0,
             team_number=0,
             generale=False,
             plis=0,
             random=True):
        """
    assert that the player is as it should be. It is set by default as empty
    """
        self.Hand.test(name=name,
                       coeur=coeur,
                       pique=pique,
                       carreau=carreau,
                       trefle=trefle,
                       points=points)
        assert self.name == name
        assert self.team == team_number
        assert self.plis == plis
        assert self.generale == generale  #indicator of genereale annonce
        assert self.random == random

    def display(self, screen):
        """
     display the board of cards
     """
        self.Hand.display(screen, self.number)
예제 #3
0
 def __init__(self, team_number, name, random, cards, number):
     """
 team number =1 or 0 / random = T or F / cards is an array of cards / number = 1 2 3 or 4
 """
     self.name = name
     self.Hand = GraphicHand(name=name, cards=cards)  #bug with cards
     self.team = team_number
     self.plis = 0
     self.generale = False  #indicator of genereale annonce
     self.random = random
     self.number = "j" + str(number)
예제 #4
0
    def allowed_cards(self, choosen_color, j):
        """
      return cards allowed to play by the player who has to play
      """

        #cas 1 : la color demandée est atout
        if choosen_color == self.atout:

            #cas 1.1 : a de latout
            if j.Hand.rest[choosen_color] != 0:
                atouts = []

                #cas 1.11 : atout plus fort
                for carte in j.Hand.cards:
                    if carte.atout and carte.number != None and carte.value > self.pli.cards[
                            self.pli.winner(
                            )].value:  #il faut checké que les cards sont présentes
                        atouts.append(carte)

                if len(atouts) != 0:
                    return GraphicHand("Cards allowed", cards=atouts)

            # cas 1.12 : pas d'atouts plus forts

                return j.Hand.color(choosen_color)

            #cas 1.2 pas d'atout
            return GraphicHand("Cards allowed", cards=j.Hand.cards)
        #cas 2 : la color demandée n'est pas latout

        #case 2.1 : a la color demandée
        if j.Hand.rest[choosen_color] != 0:
            return j.Hand.color(choosen_color)

        #cas 2.2 : n'a  pas la color demandée

        #cas 2.21 : a atout
        if self.atout in const.liste_couleur[:4]:

            #cas 2.211 : le partenaire mène
            if self.pli.winner() % 2 == len(
                    self.pli.cards
            ) % 2:  #permet de se defausser sur partenaire
                return GraphicHand("Cards allowed", cards=j.Hand.cards)

        #cas 2.212 : on doit couper
            if j.Hand.rest[self.atout] != 0:
                return j.Hand.color(self.atout)

        #cas 2.22 pas datout
        return GraphicHand("Cards allowed", cards=j.Hand.cards)
예제 #5
0
def test_shortcut():
    myround = GraphicRound(
        team_names=["Les winners", "Les loseurs"],
        player_names=["Bob", "Bill", "Fred", "John"],
        player_bots=[True, True, True, True],
        hidden=True,
        pioche=GraphicHand(name="pioche",
                           cards=[
                               GraphicCard(i, j) for i in const.liste_numero
                               for j in const.liste_couleur[:4]
                           ]),
        number=0)

    p = myround.shortkey()
    p[1].Hand = GraphicHand(cards=[GraphicCard("7", "trefle")])
    assert (myround.teams[1].players[0].Hand.check_card(
        GraphicCard("7", "trefle")))
예제 #6
0
def test_bot():
    myround = GraphicRound(
        team_names=["Les winners", "Les loseurs"],
        player_names=["Bob", "Bill", "Fred", "John"],
        player_bots=[True, True, True, True],
        hidden=False,
        pioche=GraphicHand(name="pioche",
                           cards=[
                               GraphicCard(i, j) for i in const.liste_numero
                               for j in const.liste_couleur[:4]
                           ]),
        number=0,
        difficulty="advanced")
예제 #7
0
def test_choose_atout():  #random test
    for i in range(500):
        myround = GraphicRound(team_names=["Les winners", "Les loseurs"],
                               player_names=["Bob", "Bill", "Fred", "John"],
                               player_bots=[True, True, True, True],
                               hidden=True,
                               pioche=GraphicHand(
                                   name="pioche",
                                   cards=[
                                       GraphicCard(i, j)
                                       for i in const.liste_numero
                                       for j in const.liste_couleur[:4]
                                   ]),
                               number=0)
        myround.choose_atout(None)
예제 #8
0
def test_play_pli(hidden=True):  #•fonctionne
    for i in range(500):
        myround = GraphicRound(team_names=["Les winners", "Les loseurs"],
                               player_names=["Bob", "Bill", "Fred", "John"],
                               player_bots=[True, True, True, True],
                               hidden=True,
                               pioche=GraphicHand(
                                   name="pioche",
                                   cards=[
                                       GraphicCard(i, j)
                                       for i in const.liste_numero
                                       for j in const.liste_couleur[:4]
                                   ]),
                               number=0)
        if myround.choose_atout(None):
            myround.cards_update()
            players = myround.shortkey()
            for i in range(8):
                players = myround.play_pli(pli_number=i, players=players)
예제 #9
0
    def __init__(self, team_name, team_number, j1_name, j1_random, j1_cards,
                 j2_name, j2_random, j2_cards):

        self.name = team_name
        self.number = team_number
        self.players = [
            GraphicPlayer(team_number=team_number,
                          name=j1_name,
                          random=j1_random,
                          cards=j1_cards,
                          number=1 + team_number),
            GraphicPlayer(team_number=team_number,
                          name=j2_name,
                          random=j2_random,
                          cards=j2_cards,
                          number=3 + team_number)
        ]
        self.pli = GraphicHand(name=("plis de l'equipe " + str(team_number)),
                               cards=[],
                               sort=False)  #a reinitialiser
        self.bet = None  # == mise
예제 #10
0
def test_cut():
    myround = GraphicRound(
        team_names=["Les winners", "Les loseurs"],
        player_names=["Bob", "Bill", "Fred", "John"],
        player_bots=[True, True, True, True],
        hidden=True,
        pioche=GraphicHand(name="pioche",
                           cards=[
                               GraphicCard(i, j) for i in const.liste_numero
                               for j in const.liste_couleur[:4]
                           ]),
        number=0)

    for nb_of_try in range(100):

        myround.pioche = GraphicHand(name="pioche",
                                     cards=[
                                         GraphicCard(i, j)
                                         for i in const.liste_numero
                                         for j in const.liste_couleur[:4]
                                     ])
        players = myround.classic_draw(cut=True)

        countinghand = GraphicHand(cards=(players[0] + players[1] +
                                          players[2] + players[3]))
        cards_of_pioche = [
            GraphicCard(i, j) for i in const.liste_numero
            for j in const.liste_couleur[:4]
        ]

        countinghand.test("Cards", 8, 8, 8, 8)

        for i in range(32):
            assert (countinghand.cards[i]
                    not in (countinghand.cards[:i] +
                            countinghand.cards[i + 1:]))  #check for double
            assert (countinghand.check_card(cards_of_pioche[i]))
예제 #11
0
def test_init():
    myround = GraphicRound(
        team_names=["Les winners", "Les loseurs"],
        player_names=["Bob", "Bill", "Fred", "John"],
        player_bots=[True, True, True, True],
        hidden=False,
        pioche=GraphicHand(name="pioche",
                           cards=[
                               GraphicCard(i, j) for i in const.liste_numero
                               for j in const.liste_couleur[:4]
                           ]),
        number=0)

    "check if pioche is empty"

    myround.pli.test("Pli in progress")

    "random draw cards assert that all cards are drawing"
    countinghand = GraphicHand()
    for team in myround.teams:
        for player in team.players:
            assert (len(player.Hand.cards) == player.Hand.rest["cards"] == 8)
            countinghand += player.Hand

    cards_of_pioche = [
        GraphicCard(i, j) for i in const.liste_numero
        for j in const.liste_couleur[:4]
    ]

    countinghand.test("Cards", 8, 8, 8, 8)

    for i in range(32):
        assert (countinghand.cards[i]
                not in (countinghand.cards[:i] + countinghand.cards[i + 1:])
                )  #check for double
        assert (countinghand.check_card(cards_of_pioche[i]))
예제 #12
0
def test_graphic_player():
    cards1 = []
    cards2 = []
    cards3 = []
    cards4 = []
    mypli = GraphicHand(name="Pli", cards=[])

    i = 0
    for numero in const.liste_numero:
        cards1.append(
            GraphicCard(numero,
                        "carreau",
                        position=gconst.area["cards"]["j1"][i]))
        cards2.append(
            GraphicCard(numero,
                        "pique",
                        position=gconst.area["cards"]["j3"][i]))
        cards3.append(
            GraphicCard(numero,
                        "trefle",
                        position=gconst.area["cards"]["j2"][i]))
        cards4.append(
            GraphicCard(numero,
                        "coeur",
                        position=gconst.area["cards"]["j4"][i]))

        i += 1
    myplayer1 = GraphicPlayer(team_number=0,
                              name="Bob",
                              random=False,
                              cards=cards1,
                              number=1)
    myplayer2 = GraphicPlayer(team_number=0,
                              name="Fred",
                              random=True,
                              cards=cards2,
                              number=3)
    myplayer3 = GraphicPlayer(team_number=1,
                              name="Fred",
                              random=True,
                              cards=cards3,
                              number=2)
    myplayer4 = GraphicPlayer(team_number=1,
                              name="Fred",
                              random=True,
                              cards=cards4,
                              number=4)

    pygame.init()
    screen = pygame.display.set_mode(gconst.screen_size)
    screen.fill(gconst.GREEN)
    pygame.display.flip()

    while True:
        event = pygame.event.poll()

        if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:  #escape
            break

        if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
            myplayer1.Hand.play(screen,
                                player=myplayer1.number,
                                random=myplayer1.random,
                                pli=mypli,
                                hand=myplayer1.Hand)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_1:
            screen.fill(gconst.BLUE, gconst.area["j1"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_2:
            screen.fill(gconst.BLUE, gconst.area["j2"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_3:
            screen.fill(gconst.BLUE, gconst.area["j3"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_4:
            screen.fill(gconst.BLUE, gconst.area["j4"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_5:
            screen.fill(gconst.BLUE, gconst.area["middle"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_6:
            screen.fill(gconst.BLUE, gconst.area["points"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_7:
            myplayer1.display(screen)
            myplayer2.display(screen)
            myplayer3.display(screen)
            myplayer4.display(screen)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_9:
            screen.fill(gconst.GREEN)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_KP2:
            myplayer2.Hand.play(screen,
                                player=myplayer2.number,
                                random=myplayer2.random,
                                pli=mypli,
                                hand=myplayer2.Hand)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_KP3:
            myplayer3.Hand.play(screen,
                                player=myplayer3.number,
                                random=myplayer3.random,
                                pli=mypli,
                                hand=myplayer3.Hand)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_KP4:
            myplayer4.Hand.play(screen,
                                player=myplayer4.number,
                                random=myplayer4.random,
                                pli=mypli,
                                hand=myplayer4.Hand)

        pygame.display.flip()

    pygame.quit()
예제 #13
0
class GraphicRound(Round):
    """
  One Round of coinche
  """
    def __init__(self,
                 team_names,
                 player_names,
                 player_bots,
                 number,
                 pioche,
                 hidden=False,
                 screen=None,
                 difficulty="beginner"):
        self.number = number
        self.atout = None
        self.coinche = False  #indicator of coinche
        self.surcoinche = False
        self.pli = GraphicHand(name="Pli in progress", cards=[], sort=False)
        assert (self.pli.rest["cards"] == 0)
        self.pioche = pioche

        if self.number == 0:
            players_cards = self.random_draw()
        else:
            players_cards = self.classic_draw()

        #bots creation
        # number_of_bots = j1_random+j2_random+j3_random+j4_random) #count number of bots

        self.bots = {}

        if difficulty == "beginner":
            for playerNumber in range(4):
                if player_bots[playerNumber]:
                    self.bots[player_names[playerNumber]] = Bot(
                        players_cards[playerNumber],
                        name=player_names[playerNumber],
                        allyName=player_names[(playerNumber + 2) % 4],
                        ennemyNames=[
                            player_names[(playerNumber + 1) % 4],
                            player_names[(playerNumber + 3) % 4]
                        ])

        if difficulty == "advanced":

            for playerNumber in range(4):
                if player_bots[playerNumber]:
                    self.bots[player_names[playerNumber]] = AdvancedBot(
                        players_cards[playerNumber],
                        name=player_names[playerNumber],
                        allyName=player_names[(playerNumber + 2) % 4],
                        ennemyNames=[
                            player_names[(playerNumber + 1) % 4],
                            player_names[(playerNumber + 3) % 4]
                        ])

        self.teams = [
            GraphicTeam(team_name=team_names[0],
                        team_number=0,
                        j1_name=player_names[0],
                        j1_random=player_bots[0],
                        j1_cards=players_cards[0],
                        j2_name=player_names[2],
                        j2_random=player_bots[2],
                        j2_cards=players_cards[2]),
            GraphicTeam(team_name=team_names[1],
                        team_number=1,
                        j1_name=player_names[1],
                        j1_random=player_bots[1],
                        j1_cards=players_cards[1],
                        j2_name=player_names[3],
                        j2_random=player_bots[2],
                        j2_cards=players_cards[3])
        ]

        self.hidden = hidden
        self.screen = screen

    def display(self, screen):
        """
    display the four hands
    """

        if not self.hidden:
            for player in self.shortkey():
                player.display(screen)
                player.display(screen)  # BIG PROBLEM HERE DONT GET WHY
        """
    self.teams[0].players[0].display(screen)
    graphic_yesorno(screen,question="montrer ?",question_surface=gconst.area["choice"]["question"],
                    yes_surface=gconst.area["choice"]["yes"],no_surface=gconst.area["choice"]["no"])
    self.teams[0].players[0].display(screen)
    """

    def graphic_choose_atout(self, screen, annonce_actuelle):
        for announce in gconst.area["announce"]["value"]:
            draw_text(screen, announce,
                      gconst.area["announce"]["value"][announce])
        for announce in gconst.area["announce"]["color"]:
            draw_text(screen, announce,
                      gconst.area["announce"]["color"][announce])
        color = self.choose_announce(screen, "color")
        while True:
            bet = self.choose_announce(screen, "value")
            annonce_voulue = const.liste_annonce.index(bet)
            if annonce_voulue > annonce_actuelle:
                annonce_actuelle = annonce_voulue
                break
            draw_text(screen, "you must bet higher ! ", gconst.area["message"])

        screen.fill(gconst.GREEN, gconst.area["middle"])
        return (color, bet, annonce_actuelle)

    def choose_announce(self, screen, value_or_color):
        assert ((value_or_color == "color") or (value_or_color == "value"))
        confirmation_zone = None
        while True:
            event = pygame.event.poll()
            if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:  #escape
                break
            for announce in gconst.area["announce"][value_or_color]:
                if gconst.get_mouse(
                        gconst.area["announce"][value_or_color][announce]):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if confirmation_zone == gconst.area["announce"][
                                value_or_color][announce]:  #second click
                            draw_text(screen,
                                      announce,
                                      gconst.area["announce"][value_or_color]
                                      [announce],
                                      background_color=gconst.RED)
                            pygame.display.flip()
                            return announce
                        else:
                            if confirmation_zone != None:  # already click elsewhere
                                draw_text(screen, confirmed_announce,
                                          confirmation_zone)
                            draw_text(screen,
                                      announce,
                                      gconst.area["announce"][value_or_color]
                                      [announce],
                                      background_color=gconst.YELLOW)
                            pygame.display.flip()
                            confirmation_zone = gconst.area["announce"][
                                value_or_color][
                                    announce]  #click once to highligth, click twice to confirm
                            confirmed_announce = announce

    def coincher(self, screen, player, bet):
        """
    make a turn of coince take as argument the player who just bet
    This method fixes the bet
    """
        self.teams[
            player.
            team].bet = bet  #fixe la bet de lteam attention bet est un char
        self.teams[(player.team + 1) % 2].bet = None
        if bet == "generale":
            player.generale = True

        for coincheur in self.teams[(player.team + 1) % 2].players:
            if not self.coinche:
                #BOT
                if coincheur.random:

                    #too stupid to coinche
                    if self.bots[coincheur.name].level == "beginner":
                        self.coinche = False

                    elif self.bots[coincheur.name].level == "advanced":
                        self.coinche = self.bots[coincheur.name].coinche(
                            bet, self.atout)

                #PLAYER
                else:
                    self.coinche = graphic_yesorno(
                        screen,
                        question="coincher ?",
                        question_surface=gconst.area["choice"]["question"],
                        yes_surface=gconst.area["choice"]["yes"],
                        no_surface=gconst.area["choice"]["no"])
                if self.coinche:

                    if not self.hidden:  #GRAPHIC
                        draw_text(
                            screen, ' {} coinche sur {} {} !'.format(
                                coincheur.name, bet, self.atout),
                            gconst.area["message"])
                        wait_or_pass(2)

                    for surcoincheur in self.teams[player.team].players:

                        if not self.surcoinche:
                            #BOT
                            if surcoincheur.random:
                                self.surcoinche = False  # TODO : surCOINCHE
                                #self.surcoinche=generic.decision(random=surcoincheur.random, question='surcoincher sur {} {} ?'.format(bet,self.atout), ouverte=False)
                            #PLAYER
                            else:
                                self.surcoinche = graphic_yesorno(
                                    screen,
                                    question="surcoincher ?",
                                    question_surface=gconst.area["choice"]
                                    ["question"],
                                    yes_surface=gconst.area["choice"]["yes"],
                                    no_surface=gconst.area["choice"]["no"])
                            if self.surcoinche:
                                if not self.hidden:  #GRAPHIC
                                    draw_text(
                                        screen,
                                        ' {} surcoinche sur {} {} !'.format(
                                            surcoincheur.name, bet,
                                            self.atout),
                                        gconst.area["message"])
                                    wait_or_pass(2)

    def choose_atout(
        self,
        screen,
        background_color="GREEN"
    ):  # pensez a display avant surcoinche empecher danooncer 170 180 tout atout sans atout
        """
    select the atout and return true if someone didnt pass his turn
    """
        players = self.shortkey()
        bet = 0
        annonce_actuelle = -1
        turn = 0
        while turn != 4 and bet != 'generale' and not self.coinche:
            for player in players:
                if turn == 4 or bet == 'generale' or self.coinche:
                    break
                else:

                    #BOT
                    if player.random:

                        wanted_bet, betColor = self.bots[player.name].bet()

                        if wanted_bet != None:
                            annonce_voulue = const.liste_annonce.index(
                                wanted_bet)

                            if annonce_voulue > annonce_actuelle:
                                bet = wanted_bet
                                annonce_actuelle = annonce_voulue
                                self.atout = betColor

                                if self.bots[player.name].level == "advanced":
                                    #Keep in mind that he has announced in this color
                                    self.bots[player.name].announcetracker[
                                        betColor] = True

                                if not self.hidden:  #GRAPHIC
                                    draw_text(
                                        screen, ' {} prend à {} {} !'.format(
                                            player.name, bet, self.atout),
                                        gconst.area["message"])
                                    draw_text(
                                        screen, '{} : {} {}'.format(
                                            self.teams[player.team].name, bet,
                                            self.atout), gconst.area["points"])
                                    wait_or_pass(2)

                                self.coincher(screen, player, bet)

                                #If our partner is not stupid he adapted his bet according to ours
                                allyName = self.bots[player.name].ally

                                #Our ally is a bot
                                if allyName in self.bots:

                                    if self.bots[allyName].level == "advanced":
                                        self.bots[allyName].adaptBetStrength(
                                            PartnerBet=bet, BetColor=betColor)

                                turn = 1

                            else:  #bet too low

                                turn += 1

                        else:  #doesnt bet

                            turn += 1
                        #print(player.name,turn,wanted_bet,betColor) # TODO : for test only remove this

                    #PLAYER
                    else:
                        if not graphic_yesorno(
                                screen,
                                question="annoncer ?",
                                question_surface=gconst.area["choice"]
                            ["question"],
                                yes_surface=gconst.area["choice"]["yes"],
                                no_surface=gconst.area["choice"]["no"]):
                            turn += 1
                        else:
                            turn = 1
                            self.atout, bet, annonce_actuelle = self.graphic_choose_atout(
                                screen, annonce_actuelle)
                            if not self.hidden:  #GRAPHIC
                                draw_text(screen, '{} : {} {}'.format(
                                    self.teams[player.team].name, bet,
                                    self.atout),
                                          gconst.area["points"])  #WE ASSUME

                            self.coincher(screen, player, bet)

                            #If our partner is not stupid he adapted his bet according to ours
                            allyName = self.teams[0].players[
                                1].name  # TODO: I assume here that we are the player 1

                            #Our ally is a bot
                            if allyName in self.bots:

                                if self.bots[allyName].level == "advanced":
                                    self.bots[allyName].adaptBetStrength(
                                        PartnerBet=bet, BetColor=self.atout)

        if (self.atout == None):
            return False

        if not self.hidden:  #GRAPHIC
            for team in self.teams:
                if team.bet != None:
                    draw_text(
                        screen, "L'équipe '{}' a pris {} {} !!!".format(
                            team.name, team.bet, self.atout),
                        gconst.area["message"])
                    screen.fill(gconst.GREEN, gconst.area["middle"])

        return True

    def allowed_cards(self, choosen_color, j):
        """
      return cards allowed to play by the player who has to play
      """

        #cas 1 : la color demandée est atout
        if choosen_color == self.atout:

            #cas 1.1 : a de latout
            if j.Hand.rest[choosen_color] != 0:
                atouts = []

                #cas 1.11 : atout plus fort
                for carte in j.Hand.cards:
                    if carte.atout and carte.number != None and carte.value > self.pli.cards[
                            self.pli.winner(
                            )].value:  #il faut checké que les cards sont présentes
                        atouts.append(carte)

                if len(atouts) != 0:
                    return GraphicHand("Cards allowed", cards=atouts)

            # cas 1.12 : pas d'atouts plus forts

                return j.Hand.color(choosen_color)

            #cas 1.2 pas d'atout
            return GraphicHand("Cards allowed", cards=j.Hand.cards)
        #cas 2 : la color demandée n'est pas latout

        #case 2.1 : a la color demandée
        if j.Hand.rest[choosen_color] != 0:
            return j.Hand.color(choosen_color)

        #cas 2.2 : n'a  pas la color demandée

        #cas 2.21 : a atout
        if self.atout in const.liste_couleur[:4]:

            #cas 2.211 : le partenaire mène
            if self.pli.winner() % 2 == len(
                    self.pli.cards
            ) % 2:  #permet de se defausser sur partenaire
                return GraphicHand("Cards allowed", cards=j.Hand.cards)

        #cas 2.212 : on doit couper
            if j.Hand.rest[self.atout] != 0:
                return j.Hand.color(self.atout)

        #cas 2.22 pas datout
        return GraphicHand("Cards allowed", cards=j.Hand.cards)

    def play_pli(self, players, pli_number):  #•fonctionne
        """
      prends en entrée le tableau ORDONNEE des players de ce pli et le renvoi réordonné
      """

        #la meilleure card est le 1er joueur pour l'ini
        choosen_color = players[0].Hand.play(self.screen,
                                             players[0].number,
                                             players[0].random,
                                             self.pli,
                                             hand=players[0].Hand)

        for j in players[1:]:
            allowed_hand = self.allowed_cards(choosen_color, j)
            j.Hand.play(self.screen,
                        j.number,
                        j.random,
                        self.pli,
                        hand=allowed_hand)
        if not self.hidden:
            wait_or_pass(4)
        """
      choosen_color=players[0].Hand.play_card( self.pli, players[0].Hand.choose_card(random=players[0].random))

      for j in players[1:]:
          if not self.hidden :#GRAPHIC
            self.pli.display(self.screen,"board")
          allowed_hand=self.allowed_cards( choosen_color, j)
          choosen_card=allowed_hand.choose_card(random=j.random)           # trois lignes a verifier
          j.Hand.play_card( self.pli, choosen_card)
      if not self.hidden :# GRAPHIC
        self.pli.display(self.screen,"board")
      """

        winner = self.pli.winner()

        if not self.hidden:  #GRAPHIC
            draw_text(
                self.screen,
                str("{} a gagné avec le {} de {}".format(
                    players[winner].name, self.pli.cards[winner].number,
                    self.pli.cards[winner].color)), gconst.area["points"])

        new_order = [
            players[winner], players[(winner + 1) % 4],
            players[(winner + 2) % 4], players[(winner + 3) % 4]
        ]
        players[winner].plis += 1
        self.teams[players[winner].team].pli += self.pli  #reinitialise le pli
        assert (self.pli.rest["cards"] == 0)

        #compter 10 de der
        if pli_number == 8:
            self.teams[players[winner].team].pli.points += 10

        return new_order
예제 #14
0
    def __init__(self,
                 team_names,
                 player_names,
                 player_bots,
                 number,
                 pioche,
                 hidden=False,
                 screen=None,
                 difficulty="beginner"):
        self.number = number
        self.atout = None
        self.coinche = False  #indicator of coinche
        self.surcoinche = False
        self.pli = GraphicHand(name="Pli in progress", cards=[], sort=False)
        assert (self.pli.rest["cards"] == 0)
        self.pioche = pioche

        if self.number == 0:
            players_cards = self.random_draw()
        else:
            players_cards = self.classic_draw()

        #bots creation
        # number_of_bots = j1_random+j2_random+j3_random+j4_random) #count number of bots

        self.bots = {}

        if difficulty == "beginner":
            for playerNumber in range(4):
                if player_bots[playerNumber]:
                    self.bots[player_names[playerNumber]] = Bot(
                        players_cards[playerNumber],
                        name=player_names[playerNumber],
                        allyName=player_names[(playerNumber + 2) % 4],
                        ennemyNames=[
                            player_names[(playerNumber + 1) % 4],
                            player_names[(playerNumber + 3) % 4]
                        ])

        if difficulty == "advanced":

            for playerNumber in range(4):
                if player_bots[playerNumber]:
                    self.bots[player_names[playerNumber]] = AdvancedBot(
                        players_cards[playerNumber],
                        name=player_names[playerNumber],
                        allyName=player_names[(playerNumber + 2) % 4],
                        ennemyNames=[
                            player_names[(playerNumber + 1) % 4],
                            player_names[(playerNumber + 3) % 4]
                        ])

        self.teams = [
            GraphicTeam(team_name=team_names[0],
                        team_number=0,
                        j1_name=player_names[0],
                        j1_random=player_bots[0],
                        j1_cards=players_cards[0],
                        j2_name=player_names[2],
                        j2_random=player_bots[2],
                        j2_cards=players_cards[2]),
            GraphicTeam(team_name=team_names[1],
                        team_number=1,
                        j1_name=player_names[1],
                        j1_random=player_bots[1],
                        j1_cards=players_cards[1],
                        j2_name=player_names[3],
                        j2_random=player_bots[2],
                        j2_cards=players_cards[3])
        ]

        self.hidden = hidden
        self.screen = screen
예제 #15
0
def test_graphic_round():
    """
  Playing as Bob
  """

    pygame.init()
    screen = pygame.display.set_mode(gconst.screen_size)

    screen.fill(gconst.GREEN)
    pygame.display.flip()

    myround = GraphicRound(
        team_names=["Les winners", "Les loseurs"],
        player_names=["Bob", "Bill", "Fred", "John"],
        player_bots=[True, True, True, True],
        hidden=False,
        pioche=GraphicHand(name="pioche",
                           cards=[
                               GraphicCard(i, j) for i in const.liste_numero
                               for j in const.liste_couleur[:4]
                           ]),
        number=0)
    myround.display(screen)

    while True:
        event = pygame.event.poll()

        if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:  #escape
            break

        if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
            myround.pioche.display(screen, "j1")

        if event.type == pygame.KEYDOWN and event.key == pygame.K_1:
            screen.fill(gconst.BLUE, gconst.area["j1"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_2:
            screen.fill(gconst.BLUE, gconst.area["j2"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_3:
            screen.fill(gconst.BLUE, gconst.area["j3"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_4:
            screen.fill(gconst.BLUE, gconst.area["j4"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_5:
            screen.fill(gconst.BLUE, gconst.area["middle"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_6:
            screen.fill(gconst.BLUE, gconst.area["points"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_KP1:
            if myround.choose_atout(screen):
                myround.cards_update()

        if event.type == pygame.KEYDOWN and event.key == pygame.K_9:
            screen.fill(gconst.GREEN)

        pygame.display.flip()

    pygame.quit()
예제 #16
0
def test_graphic_team():
    cards1 = []
    cards2 = []
    cards3 = []
    cards4 = []
    mypli = GraphicHand(name="Pli", cards=[])

    i = 0
    for numero in const.liste_numero:
        cards1.append(GraphicCard(numero, "carreau", position=None))
        cards2.append(GraphicCard(numero, "pique", position=None))
        cards3.append(GraphicCard(numero, "trefle", position=None))
        cards4.append(GraphicCard(numero, "coeur", position=None))

        i += 1

    myteam1 = GraphicTeam(team_name="Les winners",
                          team_number=0,
                          j1_name="Bob",
                          j1_random=True,
                          j1_cards=cards4,
                          j2_name="Fred",
                          j2_random=True,
                          j2_cards=cards2)

    myteam2 = GraphicTeam(team_name="Les losers",
                          team_number=1,
                          j1_name="Bill",
                          j1_random=True,
                          j1_cards=cards3,
                          j2_name="Boule",
                          j2_random=True,
                          j2_cards=cards1)

    pygame.init()
    screen = pygame.display.set_mode(gconst.screen_size)
    screen.fill(gconst.GREEN)
    pygame.display.flip()

    while True:
        event = pygame.event.poll()

        if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:  #escape
            break

        if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
            myplayer1.Hand.play(screen,
                                player=myplayer1.number,
                                random=myplayer1.random,
                                pli=mypli)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_1:
            screen.fill(gconst.BLUE, gconst.area["j1"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_2:
            screen.fill(gconst.BLUE, gconst.area["j2"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_3:
            screen.fill(gconst.BLUE, gconst.area["j3"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_4:
            screen.fill(gconst.BLUE, gconst.area["j4"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_5:
            screen.fill(gconst.BLUE, gconst.area["middle"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_6:
            screen.fill(gconst.BLUE, gconst.area["points"])

        if event.type == pygame.KEYDOWN and event.key == pygame.K_7:
            for player in myteam1.players:
                if graphic_yesorno(
                        screen,
                        question="montrer ?",
                        question_surface=gconst.area["choice"]["question"],
                        yes_surface=gconst.area["choice"]["yes"],
                        no_surface=gconst.area["choice"]["no"]):
                    player.display(screen)
            for player in myteam2.players:
                if graphic_yesorno(
                        screen,
                        question="montrer ?",
                        question_surface=gconst.area["choice"]["question"],
                        yes_surface=gconst.area["choice"]["yes"],
                        no_surface=gconst.area["choice"]["no"]):
                    player.display(screen)
            pygame.display.flip()

        if event.type == pygame.KEYDOWN and event.key == pygame.K_8:
            myteam1.players[1].display(screen)
            #print(myteam1.players[1].Hand.cards)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_9:
            screen.fill(gconst.GREEN)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_KP2:
            myplayer2.Hand.play(screen,
                                player=myplayer2.number,
                                random=myplayer2.random,
                                pli=mypli)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_KP3:
            myplayer3.Hand.play(screen,
                                player=myplayer3.number,
                                random=myplayer3.random,
                                pli=mypli)

        if event.type == pygame.KEYDOWN and event.key == pygame.K_KP4:
            myplayer4.Hand.play(screen,
                                player=myplayer4.number,
                                random=myplayer4.random,
                                pli=mypli)

        pygame.display.flip()

    pygame.quit()
예제 #17
0
def test_classic_drawing():
    myround = GraphicRound(
        team_names=["Les winners", "Les loseurs"],
        player_names=["Bob", "Bill", "Fred", "John"],
        player_bots=[True, True, True, True],
        hidden=True,
        pioche=GraphicHand(name="pioche",
                           cards=[
                               GraphicCard(i, j) for i in const.liste_numero
                               for j in const.liste_couleur[:4]
                           ]),
        number=0)
    myround.pioche = GraphicHand(name="pioche",
                                 cards=[
                                     GraphicCard(i, j)
                                     for i in const.liste_numero
                                     for j in const.liste_couleur[:4]
                                 ])
    players = myround.classic_draw()

    "check if pioche is empty"

    myround.pli.test("Pli in progress")

    "check drawing"

    "the order should be"
    "7 8 9 coeur d r 10 pique 7 8 trefle"
    "v d r coeur As pique 7 8 carreau 9 v trefle"
    "10 as coeur 7 pique 9 v d carreau d r trefle"
    "8 9 v pique r 10 as carreau 10 as trefle"
    players_cards = []
    players_cards.append([
        GraphicCard("7", "coeur"),
        GraphicCard("8", "coeur"),
        GraphicCard("9", "coeur"),
        GraphicCard("D", "pique"),
        GraphicCard("R", "pique"),
        GraphicCard("10", "pique"),
        GraphicCard("7", "trefle"),
        GraphicCard("8", "trefle")
    ])

    players_cards.append([
        GraphicCard("V", "coeur"),
        GraphicCard("D", "coeur"),
        GraphicCard("R", "coeur"),
        GraphicCard("As", "pique"),
        GraphicCard("7", "carreau"),
        GraphicCard("8", "carreau"),
        GraphicCard("9", "trefle"),
        GraphicCard("V", "trefle")
    ])

    players_cards.append([
        GraphicCard("10", "coeur"),
        GraphicCard("As", "coeur"),
        GraphicCard("7", "pique"),
        GraphicCard("9", "carreau"),
        GraphicCard("V", "carreau"),
        GraphicCard("D", "carreau"),
        GraphicCard("D", "trefle"),
        GraphicCard("R", "trefle")
    ])

    players_cards.append([
        GraphicCard("8", "pique"),
        GraphicCard("9", "pique"),
        GraphicCard("V", "pique"),
        GraphicCard("R", "carreau"),
        GraphicCard("10", "carreau"),
        GraphicCard("As", "carreau"),
        GraphicCard("10", "trefle"),
        GraphicCard("As", "trefle")
    ])

    for p in range(4):
        myhand = GraphicHand(cards=players[p])
        for i in range(8):
            assert (myhand.check_card(players_cards[p][i]))