Exemplo n.º 1
0
    def add_result(self, result):
        if isinstance(result, RubberResult):
            # Rubber results are split into 'above' and 'below' scores.
            score = sum(result.score)
        else:
            score = result.score

        if result.contract is None:  # Bidding passed out.
            row = (str(result.board['num']), _('Passed out'), '-', '', '')

        else:
            absScore = abs(score)
            if result.contract.declarer in (Direction.North, Direction.South) and score > 0 \
            or result.contract.declarer in (Direction.East, Direction.West) and score < 0:
                scoreNS, scoreEW = str(absScore), ''
                self.totalNS += absScore
            else:
                scoreNS, scoreEW = '', str(absScore)
                self.totalEW += absScore

            row = (str(result.board['num']),
                   voc.render_contract(result.contract),
                   str(result.tricksMade), scoreNS, scoreEW)

        self.store.remove(self.totalsRow)
        self.store.append(row)
        self.totalsRow = self.store.append(
            ('Total', '', '', str(self.totalNS), str(self.totalEW)))
Exemplo n.º 2
0
 def test_redoubled_takes_precedence_over_doubled(self):
     contract = Mock(spec=Contract)
     contract.doubleBy = True
     contract.redoubleBy = True
     call = Mock(spec=Call.Bid)
     call.level = Level.Two
     call.strain = Strain.NoTrump
     contract.declarer = Direction.West
     contract.bid = call
     self.assertEqual("2NT XX by West", render_contract(contract))
Exemplo n.º 3
0
 def test_render_contract_doubled(self):
     contract = Mock(spec=Contract)
     contract.doubleBy = True
     contract.redoubleBy = False
     call = Mock(spec=Call.Bid)
     call.level = Level.Six
     call.strain = Strain.NoTrump
     contract.declarer = Direction.South
     contract.bid = call
     self.assertEqual("6NT X by South", render_contract(contract))
Exemplo n.º 4
0
 def test_render_contract_undoubled(self):
     contract = Mock(spec=Contract)
     contract.doubleBy = False
     contract.redoubleBy = False
     call = Mock(spec=Call.Bid)
     call.level = Level.Four
     call.strain = Strain.Spade
     contract.declarer = Direction.North
     contract.bid = call
     with patch('pybridge.ui.vocabulary.config',
                {'Appearance': {
                    'Colours': {
                        'Spade': '000000000000'
                    }
                }}), patch('pybridge.ui.vocabulary.STRAIN_SYMBOLS',
                           {Strain.Spade: 'S'}):
         self.assertEqual("4<span color='#000000000000'>S</span> by North",
                          render_contract(contract))
Exemplo n.º 5
0
 def test_render_contract_redoubled(self):
     contract = Mock(spec=Contract)
     contract.doubleBy = False
     contract.redoubleBy = True
     call = Mock(spec=Call.Bid)
     call.level = Level.Three
     call.strain = Strain.Heart
     contract.declarer = Direction.East
     contract.bid = call
     with patch('pybridge.ui.vocabulary.config',
                {'Appearance': {
                    'Colours': {
                        'Heart': '000000000000'
                    }
                }}), patch('pybridge.ui.vocabulary.STRAIN_SYMBOLS',
                           {Strain.Heart: 'H'}):
         self.assertEqual(
             "3<span color='#000000000000'>H</span> XX by East",
             render_contract(contract))
Exemplo n.º 6
0
    def gameComplete(self):
        # Display all previously revealed hands - the server will reveal the others.
        for position in self.table.game.visibleHands:
            self.redrawHand(position, all=True)

        self.setTurnIndicator()

        dialog = Gtk.MessageDialog(parent=self.window,
                                   type=Gtk.MessageType.INFO)
        dialog.set_title(_('Game result'))

        # Determine and display score in dialog box and score sheet.
        if self.table.game.contract:
            #self.scoresheet.add_result(self.table.game.result)

            tricksMade = self.table.game.result.tricksMade
            tricksRequired = self.table.game.contract.bid.level.value + 7
            offset = tricksMade - tricksRequired

            fields = {
                'contract': render_contract(self.table.game.contract),
                'offset': abs(offset)
            }
            if offset > 0:
                if offset == 1:
                    resultText = _(
                        'Contract %(contract)s made by 1 trick.') % fields
                else:
                    resultText = _(
                        'Contract %(contract)s made by %(offset)s tricks.'
                    ) % fields
            elif offset < 0:
                if offset == -1:
                    resultText = _(
                        'Contract %(contract)s failed by 1 trick.') % fields
                else:
                    resultText = _(
                        'Contract %(contract)s failed by %(offset)s tricks.'
                    ) % fields
            else:
                resultText = _('Contract %(contract)s made exactly.') % fields

            score = self.table.game.result.score
            if isinstance(score, tuple):  # Rubber scoring.
                score = sum(score)  # TODO: display above, below separately.

            pair = _('declarer') if score >= 0 else _('defence')
            scoreText = _('Score %(points)s points for %(pair)s.') % {
                'points': abs(score),
                'pair': pair
            }

            dialog.set_markup(resultText + '\n' + scoreText)

        else:
            dialog.set_markup(_('Bidding passed out.'))
            dialog.format_secondary_text(_('No score.'))

        if self.player:
            dialog.add_button(_('Leave Seat'), Gtk.ResponseType.CANCEL)
            dialog.format_secondary_text(_('Click OK to start next game.'))
        dialog.add_button('_OK', Gtk.ResponseType.OK)
        dialog.set_default_response(Gtk.ResponseType.OK)
        # If user leaves table (ie. closes window), close dialog as well.
        dialog.set_transient_for(self.window)
        dialog.set_destroy_with_parent(True)

        def dialog_response_cb(dialog, response_id):
            dialog.destroy()
            if self.player:
                if response_id == Gtk.ResponseType.OK and self.table.game.isNextGameReady(
                ):
                    d = self.player.callRemote('startNextGame')
                    d.addErrback(self.errback)
                elif response_id == Gtk.ResponseType.CANCEL:
                    self.on_leaveseat_clicked(dialog)

        dialog.connect('response', dialog_response_cb)
        dialog.show()
Exemplo n.º 7
0
 def set_contract(self, game):
     if game.contract:
         text = render_contract(game.contract)
     else:
         text = _('No contract')
     self.contract.set_markup("<span size='x-large'>%s</span>" % text)