Esempio n. 1
0
 def hand(game, player):
     '''
     Calculate a player's hand from the move history stored in the game instance.
    '''
     cards_played=[cardpair[player.color.value-1] for cardpair in game.all_fights]
     hand = [card for card in cards.initial_hand() if card not in cards_played]
     return hand
Esempio n. 2
0
 def __init__(self, color, brain_fn):
     '''
     :param color: a Color enum value indicating which color this player is playing for
     :param game: a GameStatus object
     :param brain_fn: The brains of the operation. See example_ai.py for an example.
         Should be a function which takes two required inputs:
         player: a Player instance used for accessing the player's hand
         game: a GameStatus instance for accessing game details
          and one optional input:
         spied_card: if player successfully played a spy the previous turn, this will be the card that the other
             player has revealed to play.
         Should return a card from its hand to play. Can harbor hidden powers; should be expected to be called
             exactly once per round.
     '''
     self.hand = cards.initial_hand()
     self.color = color
     self.card_choosing_fn = brain_fn
Esempio n. 3
0
from components.cards import Card, Color, initial_hand

# Game ends when players have played all of their cards, so the max number of rounds
# in the game is the size of the players' initial hand.
MAX_ROUNDS_IN_GAME = len(initial_hand())
POINTS_TO_WIN = 4


class GameStatus(object):
    def __init__(self):
        self.red_points, self.blue_points = 0, 0

        # List of tuples of (red_card, blue_card)
        self.resolved_fights = []  # Doesn't include on hold fights; use all_fights for full list
        self.on_hold_fights = []

    @property
    def on_hold_points(self):
        two_pointers = [
            (red_card, blue_card)
            for red_card, blue_card in self.on_hold_fights
            if red_card == Card.ambassador and blue_card == Card.ambassador
        ]
        return len(self.on_hold_fights) + len(two_pointers)

    @property
    def winner(self):
        if self.red_points >= POINTS_TO_WIN:
            return Color.red
        if self.blue_points >= POINTS_TO_WIN:
            return Color.blue
Esempio n. 4
0
        if red_has_power and red_card == Card.ambassador:
            return FightResult.red_wins_2
        return FightResult.red_wins
    elif modifier * red_value < modifier * blue_value:
        #4. Ambassador - win with this counts as 2 victories
        if blue_has_power and blue_card == Card.ambassador:
            return FightResult.blue_wins_2
        return FightResult.blue_wins
    else:
        return FightResult.on_hold


# Cache off all possible values of fight_result for a fetch-speed gain
QUICK_FIGHT_RESULT = {
    cards_: fight_result(*cards_)
    for cards_ in itertools.product(*[initial_hand()]*2 + [initial_hand() + [None]] * 2)
}


def print_results_table(red_general_played=False):
    ''' Prints a results table similar to that provided with the Brave Rats card game.
    :param red_general_played: if True,
    :return: None; output is printed to stdout
    '''
    format_cell = '{}'.format
    previous_red = Card.general if red_general_played else None

    # Table header
    print ' ', '\t', '\t'.join('b=' + format_cell(card.value) for card in Card)

    for red_card in Card: