Пример #1
0
def nth_highest_remaining_trump(hand, board, n=1):

	played_trump_powers = {call.card_power(c) for c in board.all_cards_played if c.istrump}
	trump_powers = [35, 31, 30, 25, 20, 15, 12]
	
	# need to time this to see which is faster
	# The Problem: Want to compare the played powers with the possible powers of trump cards
	#	       Want to find the nth power that has not been played so far
	#	       Want to transform that into a card, then return that card
	
	# Method 1:
	# Look at all the powers, then turn the power into a card by making use of call's power_trump dictionary
	# I would need to loop through the power_trump dictionary to find the right name
	
	# As I'm writing this out, I can see that Method 1 is just clearly the best, so I won't even write out Method 2.
	
	for p in trump_powers:
		if p in played_trump_powers:	n -= 1
		if n == 0:
			for key in call.power_trump:
				if call.power_trump[key] == p:
					if key == 'right':		c = b.card('jack', board.trump_suit, istrump = True, isright = True)
					elif key == 'left':		c = b.card('jack', board.trump_suit, istrump = True, isleft = True)
					else:				c = b.card(key,    board.trump_suit, istrump = True)
					return(c, c in hand)
			
	c = b.card('nine', board.trump_suit, istrump = True)
	return(c, False)
Пример #2
0
def current_winner(pos, board):

    # the leader is winning, and it's up to everyone else to beat them
    winning_pos = board.leader_pos
    winning_card = board.cards_played[0]
    if board.cards_played[0].suit == 'null':
        board.cards_played[0] = b.card('nine', 'clubs')
        board.cards_played[0].set_trump(board.trump_suit)
#		print('you had to fix something')

# look at the rest of the cards
    for i in range(1, len(board.cards_played)):
        c = board.cards_played[i]
        # a card that (isn't trump) and (isn't the same suit as the winning card) can win
        if not c.istrump and c.suit != winning_card.suit:
            continue

        # get this card's position
        p = all_pos[(all_pos.index(board.leader_pos) + i) % 4]

        # compare the power of the two cards, knowing now that
        # the two cards are actually comparable (both of the same suit,
        # or the non-winning card trumps the winning card)
        cpower = call.card_power(c)
        wpower = call.card_power(winning_card)
        if cpower > wpower:
            winning_card = c
            winning_pos = p

    return (winning_card, winning_pos)
Пример #3
0
def partner_going_alone(board):

    led_card = board.cards_played[0]
    if led_card.istrump: suit = board.trump_suit
    else: suit = led_card.suit
    trash_card = b.card('nine', suit)
    trash_card.set_trump(board.trump_suit)
    return (trash_card)
Пример #4
0
 def done_with_hand(self):
     #	self.o1hand, self.phand, self.o2hand, self.dhand = [[], [], [], []]
     self.cards_played_and_stats, self.all_cards_played_and_stats = [[], []]
     self.cards_played, self.all_cards_played = [[], []]
     self.trump_suit = 'null'
     self.caller_pos = 'null'
     self.called_first_round = False
     self.turn_card = b.card('null', 'null', True)
     self.pos_hand_dict = {}
     self.ntricks_ns, self.ntricks_ew = [0, 0]
     self.leader_pos, self.winner_pos = ['o1', 'o1']
     self.winners = []
     self.reneg = [False, None]
Пример #5
0
 def __init__(self):
     self.all_pos, self.allpos = [['o1', 'p', 'o2', 'd'],
                                  ['o1', 'p', 'o2', 'd']]
     self.cards_played_and_stats, self.all_cards_played_and_stats = [[], []]
     self.cards_played, self.all_cards_played = [[], []]
     self.trump_suit = 'null'
     self.caller_pos = 'null'
     self.ns_score, self.ew_score = [0, 0]
     self.called_first_round = False
     self.turn_card = b.card('null', 'null', True)
     self.pos_hand_dict = {}
     self.pos_hand_dict_copy = {}
     self.ntricks_ns, self.ntricks_ew = [0, 0]
     self.leader_pos, self.winner_pos = ['o1', 'o1']
     self.winners = []
     self.all_pos = ['o1', 'p', 'o2', 'd']
     self.first_round_threshold = 70
     self.second_round_threshold = self.first_round_threshold
     self.going_alone_threshold = 120
     self.going_alone = False
     self.show_each_turn = True
     self.hand_result = 'null'
     self.alert_no_call = True
     self.reneg = [False, None]
Пример #6
0
import basicprogs as b
import numpy as np
import time
import call

n = int(1e5)
c = b.card('nine', 'hearts')
c1 = b.card('nine', 'hearts')
c2 = b.card('jack', 'clubs')
cn = b.card('null', 'null')

# this is 5x longer than the other way
# uses numpy arrays to allow null cards to have -99 value
t1 = time.time()
for i in range(n):
    powers = np.array([call.card_power(c) for c in hand])
    testcard = np.array(hand)[powers == min(abs(powers))][0]
t2 = time.time()
print('Took %.2f seconds using abs method' % (t2 - t1))

# this is the better way
# creates a sub_hand that specifically ignores null cards
t3 = time.time()
for i in range(n):
    sub_hand = [c for c in hand if c.suit != 'null']
    powers = [call.card_power(c) for c in sub_hand]
    idx = powers.index(min(powers))
    testcard = sub_hand[idx]
t4 = time.time()
print('Took %.2f seconds using sub_hand method' % (t4 - t3))
Пример #7
0
t0 = time.time()
while board.ns_score+board.ew_score == 0:
	i += 1
	print(i, board.ns_score, board.ew_score)
	t.play_a_hand(board, only_accept_alone = True)

print(i, board.going_alone, board.ns_score, board.ew_score)
exit(10)







c1 = b.card('jack', 'clubs')
c2 = b.card('jack', 'spades')
c3 = b.card('ace', 'clubs')
c4 = b.card('king', 'clubs')
c5 = b.card('ace', 'hearts')
hand = [c1, c2, c3, c4, c5]
pos = 'o1'
board = bsc.boardstate()
t.play_a_hand(board, forced_hands = [hand], forced_hand_positions = [pos], prevent_firstround_callers = ['o1', 'p', 'o2', 'd'])
exit(10)





Пример #8
0
def adjust_partner_hand(board):

	partner_pos = b.partner(board.caller_pos)
	dead_card = b.card('null', 'null')
	board.pos_hand_dict[partner_pos] = [dead_card.copy() for i in range(5)]