def TotalIncomeForeignInvestor(phase): """Calculates total income for the foreign investor, including the bonus $5. Args: phase: the phase object. Returns: The total income. """ ids = phase.foreign_investor.companies return base.BaseIncome(ids) - CostOfOwnership(ids, phase) + 5
def TotalIncomePlayer(i, phase): """Calculates total income for a player. Args: i: 0-based position of the player in the players list in phase. phase: the Phase named-tuple. Returns: The total income. """ player = phase.players[i] ids = player.companies return base.BaseIncome(ids) - CostOfOwnership(ids, phase)
def TotalIncomeCorporation(i, phase): """Calculates total income for a corporation. Args: i: 0-based position of the corporation in the corporations list in phase. phase: the Phase named-tuple. Returns: The total income. """ corp = phase.corporations[i] ids = corp.companies | corp.companies_in_flight return (base.BaseIncome(ids) - CostOfOwnership(ids, phase) + base.SynergyIncome(ids))
def _CorporationDetails(i): corp = phase.corporations[i] cash = '$%s' % corp.money i_price = corp.price share_price = util.SharePrice(i, phase) n_prices = len(base.PRICES) required_bv_down = ( base.PRICES[i_price-1] * corp.shares if i_price > 1 else 0) required_bv_up = ( share_price * corp.shares if i_price < n_prices-1 else 0) required_bv_double_up = ( base.PRICES[i_price+1] * corp.shares if i_price < n_prices-2 else 0) bv = util.BookValueCorporation(i, phase) president = util.President(i, phase.players) all_companies = corp.companies | corp.companies_in_flight if corp.money_in_flight: cash += ' <span title="%s">(+$%d)</span>' % ( MONEY_IN_FLIGHT_EXPLANATION, corp.money_in_flight) lines = [ '<div class="tooltip-corp">', '<table class="tooltip-corp">', '<tr><th>President</th><th>Cash</th><th>Shares</th></tr>', '<tr><td>%s</td>' % (html.escape(phase.params.players[president]) if president > -1 else 'NONE'), '<td>%s</td>' % cash, '<td>%d</td></tr></table>' % corp.shares, '<table class="tooltip-corp">', '<tr><th>↞</th><th>←</th>' '<th>Share Price</th><th>→</th>' '<th>↠</th></tr>', '<tr><td class="%s">%s</td>' % ( 'red-shareprice' if i_price==2 else 'small-shareprice', '$%d' % base.PRICES[i_price-2] if i_price > 1 else '–'), '<td class="%s">$%d</td>' % ( 'red-shareprice' if i_price==1 else 'small-shareprice', base.PRICES[i_price-1]), '<td class="shareprice">$%d</td>' % share_price, '<td class="small-shareprice">%s</td>' % ( '$%d' % base.PRICES[i_price+1] if i_price < n_prices-1 else '–'), '<td class="small-shareprice">%s</td></tr>' % ( '$%d' % base.PRICES[i_price+2] if i_price < n_prices-2 else '–'), '<tr><th colspan="2">(required)</th><th>Book Value</th>' '<th colspan="2">(required)</th></tr>', '<tr><td>–</td><td>%s</td>' % ( '≥$%d' % required_bv_down if required_bv_down else '–'), '<td>$%d</td>' % bv, '<td>%s</td>' % ( '≥$%d' % required_bv_up if required_bv_up else '–'), '<td>%s</td></tr>' % ( '≥$%d' % required_bv_double_up if required_bv_double_up else '–'), '<tr><th title="%s" colspan="2">(+/-)</th>' % DELTA_EXPLANATION, '<th>Max Payout</th>' '<th title="%s" colspan="2">(+/-)</th></tr>' % DELTA_EXPLANATION, '<tr><td>–</td><td title="%s">%s</td>' % ( DELTA_EXPLANATION, _FormatDelta(bv-required_bv_down) if required_bv_down else '–'), '<td>$%d per share</td>' % util.MaxPayout(i, phase), '<td title="%s">%s</td>' % ( DELTA_EXPLANATION, _FormatDelta(bv-required_bv_up) if required_bv_up else '–'), '<td title="%s">%s</td></tr></table>' % ( DELTA_EXPLANATION, _FormatDelta(bv-required_bv_double_up) if required_bv_double_up else '–'), '<table class="tooltip-corp">', '<tr><th colspan="4">Income</th></tr>', '<tr><th>Base</th><th>Synergy</th><th>Cost</th>' '<th class="sum">Total</th></tr>', '<tr><td>%s</td>' % _FormatDelta(base.BaseIncome(all_companies)), '<td>%s</td>' % _FormatDelta(base.SynergyIncome(all_companies)), '<td>%s</td>' % _FormatDelta(-base.CostOfOwnership( all_companies, util.TierOnTop(phase), phase.params.type)), '<td class="sum">%s</td>' % _FormatDelta(util.TotalIncomeCorporation(i, phase)), '</tr></table>', '<table class="tooltip-corp">', '<tr><th>Companies</th></tr>', '<tr><td>%s</td></tr>' % _FormatCompanies(corp.companies, corp), '</table>', ] if corp.companies_in_flight: lines += [ '<table class="tooltip-corp">', '<tr><th title="%s">Companies “in flight”</th></tr>' % COMPANIES_IN_FLIGHT_EXPLANATION, '<tr><td>%s</td></tr>' % _FormatCompanies(corp.companies_in_flight, corp), '</table>', ] lines += [ '</div>', ] return "\n".join(lines + [''])
def testBaseIncome(self): self.assertEqual(base.BaseIncome({}), 0) self.assertEqual(base.BaseIncome({ 1, }), 1) self.assertEqual(base.BaseIncome({ 8, }), 2) self.assertEqual(base.BaseIncome({1, 8}), 3) self.assertEqual(base.BaseIncome({ 11, }), 3) self.assertEqual(base.BaseIncome({ 19, }), 3) self.assertEqual(base.BaseIncome({2, 11}), 4) self.assertEqual(base.BaseIncome({7, 11}), 5) self.assertEqual(base.BaseIncome({ 20, }), 6) self.assertEqual(base.BaseIncome({ 30, }), 12) self.assertEqual(base.BaseIncome({ 43, }), 10) self.assertEqual(base.BaseIncome({ 56, }), 15) self.assertEqual(base.BaseIncome({ 100, }), 25) self.assertEqual(base.BaseIncome({1, 8, 14, 22}), 12) self.assertEqual(base.BaseIncome({45, 47, 70}), 55) self.assertEqual(base.BaseIncome({43, 45, 60, 70}), 65) self.assertEqual(base.BaseIncome({33, 12, 90}), 40) self.assertEqual(base.BaseIncome({1, 2, 5, 6, 7, 11, 12, 19, 20}), 23)