Exemplo n.º 1
0
def flip():
    print('here')
    key = random.choice(['Heads', 'Tails'])
    print(key)
    value = COIN[key]
    card = make_card(title=key, image=value)
    return card
Exemplo n.º 2
0
 def play(self,Player,card_played):
     """
         Facilitates an individual player's turn
     """
     # Check Round Over
     if len(self.deck) == 0:
         print "Game Over"
     # User Player Turn
     if self.user_player and Player.name == 1:
         if Player.turn_pos == 1:
             self.bundler(Player,card_played)
             first_hand = False
         else:
             self.bundler(Player,card_played)
     # Computer Turn
     else:
         # First Hand must lead 2 of Clubs
         if self.first_hand:
             self.bundler(Player,card.make_card("2","Clubs"))
             self.first_hand = False
         # CPU Player is leading
         elif Player.turn_pos == 1:
             brain.card_to_lead(Player)
             gui.app.p.set("Player " + str(self.turn_order[0].name) + " Led " + self.suit_led);
         # CPU Must follow suit
         else:
             brain.card_to_follow(Player,self.suit_led);
Exemplo n.º 3
0
def generate_translation(*args):
    text = ' '.join(args)
    response = requests.get(f'{TRANSLATE_URL}{text}')
    quote = response.json()['yodish']
    color = 0x00ff00
    card = make_card(title=quote, colour=color, thumbnail=THUMBNAIL)
    return card
Exemplo n.º 4
0
 def play(self, Player, card_played):
     """
         Facilitates an individual player's turn
     """
     # Check Round Over
     if len(self.deck) == 0:
         print "Game Over"
     # User Player Turn
     if self.user_player and Player.name == 1:
         if Player.turn_pos == 1:
             self.bundler(Player, card_played)
             first_hand = False
         else:
             self.bundler(Player, card_played)
     # Computer Turn
     else:
         # First Hand must lead 2 of Clubs
         if self.first_hand:
             self.bundler(Player, card.make_card("2", "Clubs"))
             self.first_hand = False
         # CPU Player is leading
         elif Player.turn_pos == 1:
             brain.card_to_lead(Player)
             gui.app.p.set("Player " + str(self.turn_order[0].name) +
                           " Led " + self.suit_led)
         # CPU Must follow suit
         else:
             brain.card_to_follow(Player, self.suit_led)
Exemplo n.º 5
0
 def __init__(self, parent):
     tk.Tk.__init__(self, parent)
     self.parent = parent
     self.initialize_points()
     self.initialize_cards()
     self.initialize_menu()
     self.card_chosen = card.make_card("2","Clubs")
Exemplo n.º 6
0
 def __init__(self, parent):
     tk.Tk.__init__(self, parent)
     self.parent = parent
     self.initialize_points()
     self.initialize_cards()
     self.initialize_menu()
     self.card_chosen = card.make_card("2", "Clubs")
Exemplo n.º 7
0
def fact():
    global user_input
    user_input = request.form['user_input']

    # To capitalize each word of the string
    user_input = user_input.title()

    # To get the image from Wikipedia
    img_url = factract.find_images(user_input)
    l = len(img_url)

    # Error handling if disambiguation occurs
    if img_url is 'False':
        search_list = wikipedia.search(user_input)
        length = len(search_list)
        return render_template('search.html', user_input=user_input,search_list=search_list)

    # Error handling if any other error occurs
    if img_url is 'Error':
        return render_template('index.html', error='Exception', user_input=user_input)



    # Create the flash Card if exits
    card_text = make_card(user_input)
    flag = True
    if len(card_text) <= 2:
        flag = False

    # Extracts the important text from Wikipedia
    text = factract.factract(user_input).decode('utf-8')
    text = text.split('\n')
    return render_template('profile.html', text=text, length=l, flag=flag, img_url=img_url, user_input=user_input, card_text=card_text)
Exemplo n.º 8
0
def choose_spell():
    spell = random.choice(SPELLS['sections'][random.choice(SPELLS['section_order'])])
    title = 'Wave your wand!'
    color = 0x2edd17
    fields = {
        'Spell': spell['key'],
        'Explanation': spell['val']
    }
    card = make_card(title=title, colour=color, thumbnail=THUMBNAIL, fields=fields)
    return card
Exemplo n.º 9
0
def setup(game_type):
    """ Initializes the game and sets up decks/players """
    global game
    game = g.Game()

    game.user_player = game_type
    cards = card.deck_build()
    random.shuffle(cards[0])

    game.deck = cards[0]
    game.clubs = cards[1]
    game.spades = cards[2]
    game.diamonds = cards[3]
    game.hearts = cards[4]

    game.player1 = player.make_player(game.deck[0:13], 1,1)
    game.player2 = player.make_player(game.deck[13:26],2,2)
    game.player3 = player.make_player(game.deck[26:39],3,3)
    game.player4 = player.make_player(game.deck[39:52],4,4)
    game.turn_order = [game.player1,game.player2,game.player3,game.player4]

    c = card.make_card("2","Clubs")

    lead = game.find_Card(c)
    if lead == 1:
        pass
    elif lead == 2:
        game.player1.turn_pos = 4
        game.player2.turn_pos = 1
        game.player3.turn_pos = 2
        game.player4.turn_pos = 3
        game.turn_order = [game.player2,game.player3,game.player4,game.player1]
    elif lead == 3:
        game.player1.turn_pos = 3
        game.player2.turn_pos = 4
        game.player3.turn_pos = 1
        game.player4.turn_pos = 2
        game.turn_order = [game.player3,game.player4,game.player1,game.player2]
    else:
        game.player1.turn_pos = 2
        game.player2.turn_pos = 3
        game.player3.turn_pos = 4
        game.player4.turn_pos = 1
        game.turn_order = [game.player4,game.player1,game.player2,game.player3]

    game.player1.print_hand()
    game.player2.print_hand()
    game.player3.print_hand()
    game.player4.print_hand()

    # Edge case of user player has 2 of clubs
    if game.turn_order[0] == game.player1 and game_type:
        #app.set_disabled()
        game.first_hand = False
Exemplo n.º 10
0
def choose_dialog():
    """Return random dialogues from Gangs of Wassepur.
    
    Returns
    -------
        card: discord.Embed
            Card containing random dialogue from Gangs of Wassepur.
    """
    title = random.choice(WASSEPUR_DIALOGUES)
    color = 0xF5C518
    card = make_card(title=title, color=color, thumbnail=THUMBNAIL)
    return card
Exemplo n.º 11
0
 def set_normal(self):
     """
         Allows the user to play once his card is chosen and is valid
     """
     # Always set to normal in a simulation game
     # See if its the users turn
     if  configure.game.turn_order[configure.game.turn].name == 1:
         temp = self.var.get().split(" ")
         self.card_chosen = card.make_card(temp[1],temp[3])
     # Single Player: Check to see if card picked is legal
     if self.fair_play(self.card_chosen):
         self.button.config(state="normal")
Exemplo n.º 12
0
def generate_abuse():
    """Generate random abuses.

    Returns
    --------
        card: discord.Embed
            Card cointaining an abuse.
    """
    title = make_abuse.generate_random_abuse()
    color = 0xd6537a
    card = make_card(title=title, color=color, thumbnail=THUMBNAIL)
    return card
Exemplo n.º 13
0
 def set_normal(self):
     """
         Allows the user to play once his card is chosen and is valid
     """
     # Always set to normal in a simulation game
     # See if its the users turn
     if configure.game.turn_order[configure.game.turn].name == 1:
         temp = self.var.get().split(" ")
         self.card_chosen = card.make_card(temp[1], temp[3])
     # Single Player: Check to see if card picked is legal
     if self.fair_play(self.card_chosen):
         self.button.config(state="normal")
Exemplo n.º 14
0
def card_to_throwaway(Player):
    """
    Each CPU plays very defensively:
        1. Throw away the queen of spades
        2. Throw away Highest Heart
        3. Throw card with highest prob of winning the next hand
    """
    queen_of_spades = card.make_card("Queen", "Spades")
    if queen_of_spades in Player.Spades:
        return queen_of_spades
    elif len(Player.Hearts) > 0:
        return Player.max_card("Hearts")
    else:
        return probabilities_of_winning_trick(Player.Hand)[-1][0]
Exemplo n.º 15
0
def generate_quote():
    """Generate random quotes from Star Wars.

    Returns
    --------
        card: discord.Embed
            Card cointaining random quote from Star Wars.
    """
    headers = {
        'accept': 'text/plain'
    }
    response = requests.get(QUOTE_URL, headers=headers)
    quote = response.json()['starWarsQuote']
    card = make_card(title=quote, colour=0xF5C518, thumbnail=THUMBNAIL)
    return card
Exemplo n.º 16
0
def fact():
    global user_input
    user_input = request.form['user_input']
    img_url = factract.get_image(user_input)
    card_text = make_card(user_input)
    # print card_text
    # text = sat_extract.fact_extract(user_input)
    text = factract.factract(user_input).decode('utf-8')
    if text == '':
        return "Working	"
    text = text.split('\n')
    return render_template('profile.html',
                           text=text,
                           img_url=img_url,
                           user_input=user_input,
                           card_text=card_text)
Exemplo n.º 17
0
def meme_builder(name, *args):
    text = ' '.join(args).split(',')

    headers = {
        'API-KEY': API_KEY
    }
    body = {
        "topText": text[0],
        "bottomText": text[1],
        "imgUrl": IMAGES.get(name)
    }
    response = requests.post(GENERATE_MEME, data=json.dumps(body), headers=headers)
    image = response.text.split(',', 1)[1].encode('utf-8')

    file = build_image(image)
    card = make_card(title='Here you go...', colour=0xF5C518, image=MEME_GENERATED_PATH)
    return file, card
Exemplo n.º 18
0
def covid_stats(*args):
    country = ' '.join(args[0:])

    response = requests.get(
        f'{BASE_URL}/{country}{QUERY}')
    result = response.json()

    title = f'Covid-19 Details - {result["country"]}'
    color = 0xF5C518
    thumbnail = result['countryInfo']['flag']
    fields = {
        'Total Cases': result['cases'],
        'Total Recovered': result['recovered'],
        'Total Deaths': result['deaths'],
        'Today Cases': result['todayCases'],
        'Today Recovered': result['todayRecovered'],
        'Today Deaths': result['todayDeaths']
    }
    card = make_card(title=title, color=color, thumbnail=thumbnail, fields=fields)
    return card
Exemplo n.º 19
0
def generate_insult(name):
    response = requests.get(f'{INSULT_URL}{name}')
    card = make_card(title=response.text, colour=0xF5C518)
    return card
Exemplo n.º 20
0
import start
import card
import hand

balanced_cards = [
    "AS", "KS", "QS", "AH", "KH", "QH", "AD", "KD", "QD", "JD", "QC", "KC",
    "AC"
]

balanced_hand = hand.Hand([card.make_card(c) for c in balanced_cards])

unbalanced_cards = [
    "AS", "KS", "QS", "JS", "10S", "9S", "8S", "7S", "6S", "5S", "4S", "3S",
    "2S"
]

unbalanced_hand = hand.Hand([card.make_card(c) for c in unbalanced_cards])


def test_calculate_points():

    hand = card.cards
    pts = start.calculate_points(hand)

    assert pts == 11


def test_is_balanced_hand():
    is_balanced = start.is_balanced_hand(balanced_hand)
    assert is_balanced == True
Exemplo n.º 21
0
def test_card():
    c = card.make_card("10D")
    assert c.suit == "D"
    assert c.rank == "10"