示例#1
0
    def showHist(self):
        """Show history of the played pieces."""
        dom = domino()

        # Show history
        self.msgr.prnt({
            'eng': "\n-> This is the played history:",
            'por': "\n-> Este é o histórico de jogadas:"
        })
        indPl = self.starts
        # print(indPl)
        for ind in self.piecHist:
            # print(ind)
            strPrnt = "Pl." + str(indPl) + ": "
            # print("strPrnt = '"+strPrnt+"'")

            if ind is None:
                if self.msgr.lang == 'eng':
                    strPrnt += "Passed."
                elif self.msgr.lang == 'por':
                    strPrnt += "Passei."
                else:
                    strPrnt += "None"
            else:
                strPrnt += str(dom.getPiecPair(ind)) + " (" + str(ind) + ")"
            #
            self.msgr.prnt(strPrnt)
            indPl = (indPl + 1) % 4
示例#2
0
    def updtCurrPiec(self, move):
        """Update current piece.

        Updates the table's .currPiec attribute and returns None.
        """
        dom = domino()
        piec, posi, ornt = move

        if self.currPiec is None:
            self.currPiec = piec
        else:
            piecPair = dom.getPiecPair(piec)
            currPiecPair = dom.getPiecPair(self.currPiec)

            if ornt:
                # True orientation:
                # greater side exposed, lesser side replaced
                ppIndx = 1
            else:
                # False orientation:
                # lesser side exposed, greater side replaced
                ppIndx = 0

            if posi == 0:
                # left position. Replace lesser side
                currPiecPair[0] = piecPair[ppIndx]
            else:
                # right position. Replace greater side
                currPiecPair[1] = piecPair[ppIndx]

            self.currPiec = dom.getPiecNum(currPiecPair)
示例#3
0
 def showStat(self):
     """Show current state of the table."""
     dom = domino()
     cp = self.currPiec
     if cp is not None:
         self.msgr.prnt({
             'eng':
             "\n-> This is the current piece " + "(state) in the table:",
             'por':
             "\n-> Esta é a peça atual (estado) " + "do jogo:"
         })
         self.msgr.prnt(str(cp) + " (" + str(dom.getPiecPair(cp)) + ")")
示例#4
0
 def showHand(self):
     """Show the player's hands."""
     dom = domino()
     self.msgr.prnt({
         'eng': "\nThese are the players' hands:",
         'por': "\nAqui estão as mãos dos jogadores:"
     })
     for pl in range(4):
         p = self.players[pl]
         self.msgr.prnt({
             'eng': "  Player #" + str(pl) + ":",
             'por': "  Jogador #" + str(pl) + ":"
         })
         handStr = '    '
         for ind in range(len(p.hand)):
             handStr += str(dom.getPiecPair(p.hand[ind])) + ', '
         self.msgr.prnt(handStr)
示例#5
0
    def specFnshTest(self, move):
        """Check for special finishings.

        Special finishings are:
            - "carroça": for finishing with a double piece such as [3,3];
                         (this yields 2 points)
            - "lailot": for finishing at both ends simultaneously;
                         (this yields 3 points)
            - "cruzado": for finishing with a double piece at both ends;
                         (this yields 4 points)

        """
        self.msgr.prnt({'eng': "\nDONE!", 'por': "\nBATI!"})
        dom = domino()

        piec, _, _ = move
        piecPair = dom.getPiecPair(piec)

        # Test for final double piece
        if piecPair[0] == piecPair[1]:
            isCarr = True
        else:
            isCarr = False

        # Test for finish at both ends
        compScor = dom.isComp(piec, self.currPiec)
        # print(compScor)

        # 1 & 2, or 4 & 8
        isOne, isTwo, isFour, isEig = False, False, False, False
        if compScor % 2 == 1:
            isOne = True
            compScor -= 1
        if compScor % 4 == 2:
            isTwo = True
            compScor -= 2
        if compScor % 8 == 4:
            isFour = True
            compScor -= 4
        if compScor > 0:
            isEig = True

        if (isTwo and isFour) or (isEig and isOne):
            bothSide = True
        else:
            bothSide = False

        # Final count for points

        if isCarr:
            if bothSide:
                nPtsAdd = 4
                self.msgr.prnt("\n----- CRUZADO!! 4 pts! -----")
            else:
                nPtsAdd = 2
                self.msgr.prnt("\n----- CARROÇA!! 2 pts! -----")
        else:
            if bothSide:
                nPtsAdd = 3
                self.msgr.prnt("\n----- LAILOT!!  3 pts! -----")
            else:
                nPtsAdd = 1
                self.msgr.prnt("\n-----     OK!  1 pt. -----")

        self.nPtsAdd = nPtsAdd
示例#6
0
    def play(self, isFirst=False):
        """Put the players to play."""
        dom = domino()
        win = None
        pl = self.players[self.plays]
        if not pl.isAuto:
            self.showTabl()
        if isFirst:
            move = pl.play(self.currPiec,
                           self.piecHist,
                           strtWith=self.strtWith,
                           msgr=self.msgr)
        else:
            move = pl.play(self.currPiec, self.piecHist, msgr=self.msgr)
        piec, posi, ornt = move
        self.piecHist.append(piec)

        if piec is None:
            # no piece was played. Update the 'hasNot' arrays:
            thisPiecPair = dom.getPiecPair(self.currPiec)
            self.hasNot[self.plays, thisPiecPair[0]] = True
            self.hasNot[self.plays, thisPiecPair[1]] = True
        else:
            # Player has played a proper piece

            if len(pl.hand) == 0:
                # this player has just finished the game!
                win = self.plays % 2

                self.specFnshTest(move)
            else:
                self.updtCurrPiec(move)
            #
        #

        # Deadlock test
        if len(self.piecHist) > 4 and \
                (self.piecHist[-1] is None) and \
                (self.piecHist[-2] is None) and \
                (self.piecHist[-3] is None) and \
                (self.piecHist[-4] is None):
            ptOdd, ptEvn = 0, 0
            for indPl in range(4):
                for ind in self.players[indPl].hand:
                    pair = dom.getPiecPair(ind)
                    if indPl % 2 == 0:
                        ptEvn += (pair[0] + pair[1])
                    else:
                        ptOdd += (pair[0] + pair[1])

            # TODO: solve the tie condition in a less biased way
            self.msgr.prnt({'eng': "\nDeadlock!", 'por': "\nTravou!"})
            self.showAll()
            self.msgr.prnt({
                'eng':
                "\nEven team: " + str(ptEvn) + " points, Odd team: " +
                str(ptOdd) + " points...",
                'por':
                "\nTime par: " + str(ptEvn) + " pontos, Time ímpar: " +
                str(ptOdd) + " pontos..."
            })
            if ptEvn <= ptOdd:
                win = 0
            elif ptOdd < ptEvn:
                win = 1
            #
        #

        # Next player to play
        self.plays = (self.plays + 1) % 4

        return win