def test_w_doubles(self): self.assertEquals(('1Cd', 0), bridge.get_contract_and_declearer(['1C', 'pass', 'pass', 'dbl' \ , 'pass', 'pass', 'pass'])) self.assertEquals(('2Sr', 1), bridge.get_contract_and_declearer(['1C', '1S', 'pass', '2S'\ , 'dbl', 'rdbl', 'pass' \ , 'pass', 'pass']))
def do_bid(prof, toput, key, player, bid, alert=None) : user = prof.user table = repo.Table.get(key) protocol = table.protocol cur_side = table.side_idx(user) if cur_side is None or not bid_allowed(map(bridge.remove_alert, protocol.bidding), bridge.remove_alert(bid), protocol.contract) \ or bridge.SIDES[cur_side] != table.whosmove : logging.warn('bad bid: %s %s %s %s %s %s %s %s', protocol.key(), bid , protocol.contract, user, player, table.key(), table.whosmove, cur_side) return toput.append(protocol) toput.append(table) if alert is not None : fullbid = bid + ':' + alert else : fullbid = bid protocol.bidding.append(fullbid) bid_cnt = len(protocol.bidding) umap = table.usermap() part = umap.pop(bridge.SIDES[(cur_side + 2) % 4], None) if bid_cnt > 3 and all([b.startswith(bridge.BID_PASS) for b in protocol.bidding[-3:]]) : contract, rel_declearer = bridge.get_contract_and_declearer(protocol.bidding) deal = protocol.deal if contract == bridge.BID_PASS : protocol.contract = contract protocol.result = 0 protocol.tricks = 0 table.broadcast([m('bid', side = cur_side, bid = bid, dbl_mode = 'none') , m('end.play', contract = contract , declearer = 'N/A' , points = protocol.result , tricks = protocol.tricks , protocol_url = 'protocol.html?%s' % deal.key().id())]) start_new_deal(table, toput) return declearer = (rel_declearer + protocol.deal.dealer) % 4 leadmaker = (declearer + 1) % 4 contract = contract + bridge.SIDES[declearer] protocol.contract = contract table.whosmove = bridge.SIDES[leadmaker] logging.debug('contract %s by %s', contract, bridge.SIDES[declearer]) start = m('start.play', contract = contract.replace('d', 'x').replace('r','xx') , lead = leadmaker) if alert is None : table.broadcast([m('bid', side = cur_side, bid = bid, dbl_mode = 'none'), start]) else : repo.UserProfile.uenqueue( umap.values(), [m('bid', side = cur_side, bid = bid , alert = process_chat_message(alert), dbl_mode = 'none'), start]) repo.UserProfile.uenqueue( part, [m('bid', side = cur_side, bid = bid, dbl_mode = 'none'), start]) dummy = (declearer + 2) % 4 dummy_side = bridge.SIDES[dummy] decl_side = bridge.SIDES[declearer] dummy_hand = deal.hand_by_side(dummy_side) mes = m('hand', cards = dummy_hand, side = dummy_side) repo.UserProfile.uenqueue(table.user_by_side(decl_side), mes) mes = m('hand', cards = deal.hand_by_side(decl_side), side = decl_side) repo.UserProfile.uenqueue(table.user_by_side(dummy_side), mes) return table.nextmove() dbl_mode = get_dbl_mode(protocol.bidding) if alert is None : table.broadcast(m('bid', side = cur_side, bid = bid, dbl_mode = dbl_mode)) else : alerted_mes = m('bid', side = cur_side, bid = bid , alert = process_chat_message(alert), dbl_mode = dbl_mode) repo.UserProfile.uenqueue(umap.values(), alerted_mes) table.kib_broadcast(alerted_mes) repo.UserProfile.uenqueue(part, m('bid', side = cur_side, bid = bid, dbl_mode = dbl_mode))
def test_simple(self): self.assertEquals(('1C', 0), bridge.get_contract_and_declearer(['1C', 'pass', 'pass', 'pass'])) self.assertEquals(('2S', 3), bridge.get_contract_and_declearer(['pass', 'pass', 'pass', '2S'\ , 'pass', 'pass', 'pass'])) self.assertEquals(('3Z', 0), bridge.get_contract_and_declearer(['1Z', 'pass', '3Z', 'pass'\ , 'pass', 'pass']))