예제 #1
0
def initialization():
    deck = Deck()
    deck.shuffle()
    player = Player()
    dealer = Player()

    start_game(deck, player, dealer)
예제 #2
0
    def testPopACard(self):
        deck = Deck()
        card = deck.pop()

        self.assertEqual(len(deck), 35)
        self.assertEqual(type(card), tuple)
        self.assertEqual(len(card), 2)
예제 #3
0
 def test_combination_of_cards_in_new_deck(self):
     deck = Deck()
     deck.get_new_deck()
     self.assertIn(' kierJ', deck.combination_of_cards)
     self.assertIn(' karo2', deck.combination_of_cards)
     self.assertIn('  pikA', deck.combination_of_cards)
     self.assertIn('trefl10', deck.combination_of_cards)
예제 #4
0
파일: bot.py 프로젝트: phenmp/atassist-api
class Bot:
    # Constants
    ARENA = 0
    RUMBLE = 1

    def __init__(self):
        self.config = Configuration()
        self.api = GameApi(self.config)

        self.my_hand = None
        self.enemy_hand = None
        self.field = []
        self.style = self.ARENA

    def initializeGame(self, style=0):
        resp = self.api.updateAndGetInitFile()
        # prioritize drunk and craze
        # choose item over character
        # go two wide when opponent opens with precombo
        # resp['active_battle_data']['attack_commander']        #returns 3003 for Tina
        # resp['active_battle_data']['attack_commander_level']  #returns level for hero
        # resp['active_battle_data']['defend_commander']        #returns 3003 for Tina
        # resp['active_battle_data']['defend_commander_level']  #returns level for hero
        # Update my hand and enemy's first card

        self.my_hand = Deck()
        self.my_hand.updateAsMyDeck()
        self.enemy_hand = Deck()
        self.enemy_hand.updateAsEnemyDeck()

    def getSuggestion(self):
        print("NOT IMPLEMENTED")
예제 #5
0
파일: bot.py 프로젝트: phenmp/atassist-api
    def initializeGame(self, style=0):
        resp = self.api.updateAndGetInitFile()
        # prioritize drunk and craze
        # choose item over character
        # go two wide when opponent opens with precombo
        # resp['active_battle_data']['attack_commander']        #returns 3003 for Tina
        # resp['active_battle_data']['attack_commander_level']  #returns level for hero
        # resp['active_battle_data']['defend_commander']        #returns 3003 for Tina
        # resp['active_battle_data']['defend_commander_level']  #returns level for hero
        # Update my hand and enemy's first card

        self.my_hand = Deck()
        self.my_hand.updateAsMyDeck()
        self.enemy_hand = Deck()
        self.enemy_hand.updateAsEnemyDeck()
예제 #6
0
 def load_latest_game(cls, email):
     """Return latest game by a user or a new game if one didn't exist."""
     with connection:
         with connection.cursor() as cursor:
             user = User.get_user_by_email(email)
             cursor.execute(database.GET_LATEST_GAME_TABLE_BY_EMAIL, (email,))
             bulk = cursor.fetchone()
             print (bulk)
             if bulk:
                 (game_table_id, timestamp_created, computer_hand_id,
                  player_hand_id, deck_id, user_id, turn_indicator) = bulk
             else:
                 return cls.new_game(user)
             # Get Hands
             cursor.execute(database.GET_HAND_BY_ID, (player_hand_id, ))
             p_s1, p_v1, p_s2, p_v2, p_s3, p_v3, p_s4, p_v4, p_s5, p_v5,\
                 uid, mtime = cursor.fetchone()
             player = User.get_user_by_id(uid)
             player_hand = Hand(player, Card(p_s1, p_v1),
                                Card(p_s2, p_v2),
                                Card(p_s3, p_v3),
                                Card(p_s4, p_v4),
                                Card(p_s5, p_v5))
             cursor.execute(database.GET_HAND_BY_ID, (computer_hand_id, ))
             c_s1, c_v1, c_s2, c_v2, c_s3, c_v3, c_s4, c_v4, c_s5, c_v5,\
                 cuid, cmtime = cursor.fetchone()
             computer = User.get_user_by_id(COMPUTER_UID)
             computer_hand = Hand(computer, Card(c_s1, c_v1),
                                  Card(c_s2, c_v2),
                                  Card(c_s3, c_v3),
                                  Card(c_s4, c_v4),
                                  Card(c_s5, c_v5))
             deck = Deck(deck_id)
             return cls(deck, user, player_hand, computer_hand, game_table_id, turn_indicator)
예제 #7
0
def select(id):
    deck = None
    sql = "SELECT * FROM decks WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        deck = Deck(result['topic'], result['card_limit'], result['id'] )
    return deck
예제 #8
0
def select_all():
    decks = []

    sql = "SELECT * FROM decks"
    results = run_sql(sql)

    for row in results:
        deck = Deck(row['topic'], row['card_limit'], row['id'])
        decks.append(deck)
    return decks
def main():
    deck = Deck()

    active_view = PlayerView()
    passive_views = (active_view, BroadcastView(), InternetStreamingView())
    views = Views(active_view, passive_views)

    checker = CheckerRankAndSuitIndex()

    game = Controller(deck, views, checker)
    game.run()
예제 #10
0
 def new_game(cls, user: User):
     deck = Deck()
     player_hand = Hand(user)
     computer_hand = Hand(User.get_user_by_id(1))  # 1 is the ID of the computer player.
     timestamp = datetime.timestamp(datetime.now())
     with connection:
         with connection.cursor() as cursor:
             # 1 here and at the return statement is turn_indicator. 1 Means player's turn.
             cursor.execute(database.INSERT_NEW_GAME_TABLE, (timestamp, computer_hand.id, player_hand.id,
                                                             constants.PLAYER_TURN_INDICATOR, deck.id, user.id))
             id_ = cursor.fetchone()[0]
     return GameTable(deck, user, player_hand, computer_hand, id_, constants.PLAYER_TURN_INDICATOR)
예제 #11
0
async def engine(websocket, path):
    deck = Deck()
    score = 0
    print("started web server")

    card = deck.deal_card()

    while not deck.is_empty():
        print(card)
        print("Cards Left: {}".format(deck.size()))

        card_json = json.dumps({"card": str(card), "score": score})

        await websocket.send(card_json)
        decision = await websocket.recv()

        prev_card = card
        card = deck.deal_card()

        if decision == 'HIGH':
            score += 1 if card > prev_card else 0
        elif decision == 'LOW':
            score += 1 if card < prev_card else 0

    card_json = json.dumps({
        "card": "DONE",
        "score": score
    })
    await websocket.send(card_json)
    exit()
예제 #12
0
파일: game.py 프로젝트: SNHenderson/plm18
 def __init__(self, game_name, turn_based):
     super().__init__()
     self.game_name = game_name
     self.players = []
     self.win_conditions = []
     self.moves = []
     self.events = []
     self.collections = set()
     self.deck = Deck()
     self.turn_based = turn_based
     if turn_based:
         self.turn = 0
         self.turn_direction = 1
예제 #13
0
def create_deck(owner, **overrides):
    params = {
        "name": "My Awesome Deck",
        "owner": owner,
    }
    params.update(overrides)

    deck = Deck(**params)

    db.session.add(deck)
    db.session.commit()

    return deck
예제 #14
0
    def createImageFromList(self, name="default", card_ids=[], width=5):
        full_list = []

        for i in range(len(card_ids)):
            full_list.extend(card_ids[i])

        deck = Deck(name=name)
        deck.addListOfIds(full_list)
        deck.updateDeckFromXML()
        filepath = deck.createLargeDeckImage(name, width=width)

        return deck, filepath
예제 #15
0
    def findCombos(self, chars, threshold, search="ITEMS"):
        if search == "ITEMS":
            card1, card2, check, against = 'card1', 'card2', "items", "characters"
        else:  # search characters based on items
            card1, card2, check, against = 'card2', 'card1', "characters", "items"

        combos = self.api.getCombos()
        cards = self.api.getCards()

        mix_tot = 0
        items = []

        # use first character to create list of items
        for combo in combos.findall('combo'):
            the_card = combo.find('cards')
            if the_card.get(card2) == "" or the_card.get(card1) == "":
                continue
            item = int(the_card.get(card2))
            if int(the_card.get(card1)) == chars[0].id:
                items.append(the_card.get(card2))

        # print("Items to test")
        # print(items)

        # check if list of items is compatible with other characters, if no, delete
        for i in range(1, len(chars)):
            # print('Looking for {0} that mix with your {1}... {2}%'.format(check, against, float(
            #     int(float(i) / float(len(chars)) * 10000)) / 100))
            j = 0
            while j < len(items):
                success = 0

                for combo in combos.findall('combo'):
                    the_card = combo.find('cards')
                    if the_card.get(card2) == "" or the_card.get(card1) == "":
                        continue

                    if int(
                            the_card.get(card1)
                    ) == chars[i].id and the_card.get(card2) == items[j]:
                        success = 1
                        break

                if not success:
                    del items[j]
                else:
                    j += 1

        if len(items):
            item_deck = Deck()
            item_deck.addListOfIds(items)
            item_deck.updateDeckFromXML()
        else:
            item_deck = None

        return item_deck
예제 #16
0
async def hindu_shuffle(times: int = 1, history: bool = False):
    deck = Deck()
    deck.shuffle_hindu(times)

    if (times >= 25 and history):
        raise HTTPException(
            status_code=403,
            detail=
            "Preventing too many shuffles, for your own safety. You can shuffle this many times but please turn of history"
        )
    if (history):
        return {
            "deck": deck.getMappedDeck(),
            "shuffleHistory": deck.get_shuffle_history()
        }
    else:
        return {"deck": deck.getMappedDeck()}
예제 #17
0
 def generate_deck(self, n, m):
     event = self.generate_event()
     main_deck_input = []
     for x in range(0, n):
         main_deck_input.append({
             "name": "card" + str(x),
             "quantity": x + 1
         })
     sideboard_input = []
     for x in range(0, m):
         sideboard_input.append({
             "name": "card" + str(x),
             "quantity": x + 1
         })
     new_deck = Deck.create_deck(deck_id=567,
                                 name="test" + str(x),
                                 event_placing=x,
                                 event=event,
                                 main_deck=main_deck_input,
                                 sideboard=sideboard_input)
     return new_deck
예제 #18
0
def start():
    deck = Deck()
    dealer = Dealer(deck)
    dealer.deal()
    dealer_cards = dealer.cards
    player_cards = dealer.player.cards

    print "Dealer: %s" % str(dealer_cards[0])
    print "Player: %s" % str(player_cards)

    player_sum = sum([p[0] for p in player_cards])

    while player_sum < 21:
        choice = raw_input("H)it or S)tay:")
        if choice.upper() == 'H':
            dealer.hit_player()
            player_sum = sum([p[0] for p in player_cards])
        elif choice.upper() == 'S':
            break
        print "Player: %s" % str(player_cards)

    dealer.hit_until()

    dealer_sum = sum([d[0] for d in dealer_cards])

    print "Dealer: %s" % str(dealer_cards)
    print "Player: %s" % str(player_cards)

    if player_sum > 21 or dealer_sum > player_sum:
        print "You Lose! :("

    elif player_sum == dealer_sum:
        print "You Tie..."

    else:
        print "You Win! :)"
예제 #19
0
 def __init__(self, *, table: Table, croupier: Croupier, game_players: list,
              money_min_to_connect: float):
     self.deck = Deck()
     self.table = table
     self.croupier = croupier
     self.croupier.actual_table = self.table
     self.game_players = game_players
     self.money_min_to_connect = money_min_to_connect
     self.cards_on_table = []
     self.rate_of_the_game = 0
     self.step = 0
     self.amount_cards_on_table = 5
     self.hierarchy = {
         'Royal flush': 1,
         'Straight flush': 2,
         'Quads': 3,
         'Full': 4,
         'Flush': 5,
         'Straight': 6,
         'Three': 7,
         'Two Pairs': 8,
         'A Pair': 9,
         'None': 20
     }
예제 #20
0
 def testPlayerCards(self):
     deck = Deck()
     dealer = Dealer(deck)
     dealer.deal()
     self.assertEqual(len(dealer.player.cards), 2)
예제 #21
0
def update_deck(id):
    topic = request.form['topic']
    card_limit = request.form['card_limit']
    deck = Deck(topic, card_limit, id)
    deck_repository.update(deck)
    return redirect('/decks')
예제 #22
0
async def performance_check(times: int = 1):
    """ The closer to -1 indcates the "maximum" difference, +1 is exactly the same """
    fresh_deck = Deck()
    riffle_deck = Deck()
    overhand_deck = Deck()
    hindu_deck = Deck()

    riffle_deck.shuffle_riffle(times)
    overhand_deck.shuffle_overhand(times)
    hindu_deck.shuffle_hindu(times)

    return {
        "riffle_shuffle":
        riffle_deck.calculate_difference(fresh_deck.getUnMappedDeck()),
        "over_hand_shuffle":
        overhand_deck.calculate_difference(fresh_deck.getUnMappedDeck()),
        "hindu_shufle":
        hindu_deck.calculate_difference(fresh_deck.getUnMappedDeck()),
        "fresh_deck_sanity_check":
        fresh_deck.calculate_difference(fresh_deck.getUnMappedDeck())
    }
예제 #23
0
 def testDealCardsInDeck(self):
     deck = Deck()
     dealer = Dealer(deck)
     dealer.deal()
     self.assertEqual(len(deck), 32)
예제 #24
0
 def test52Cards(self):
     deck = Deck()
     self.assertEqual(len(deck), 36)
예제 #25
0
 def testDealerHitUntil17(self):
     deck = Deck()
     dealer = Dealer(deck)
     dealer.hit_until()
     sum_dealer = sum([d[0] for d in dealer.cards])
     self.assertGreaterEqual(sum_dealer, 17)
예제 #26
0
 def testDealerHitForHim(self):
     deck = Deck()
     dealer = Dealer(deck)
     dealer.hit()
     self.assertEqual(len(dealer.cards), 1)
예제 #27
0
 def testDeallerHitPlayer(self):
     deck = Deck()
     dealer = Dealer(deck)
     dealer.hit_player()
     self.assertEqual(len(dealer.player.cards), 1)
예제 #28
0
import pdb

from models.deck import Deck
from models.flashcard import Flashcard

import repositories.deck_repository as deck_repository
import repositories.flashcard_repository as flashcard_repository

flashcard_repository.delete_all()
deck_repository.delete_all()


deck_1 = Deck("Capitals", 8)
deck_repository.save(deck_1)

card_1 = Flashcard("Paris", "What is the capital of France?", deck_1)
flashcard_repository.save(card_1)
card_2 = Flashcard("Rome", "what is the capital of Italy?", deck_1)
flashcard_repository.save(card_2)
card_3 = Flashcard("London", "What is the capital of England?", deck_1)
flashcard_repository.save(card_3)
card_4 = Flashcard("Athens", "what is the capital of Greece?", deck_1)
flashcard_repository.save(card_4)
card_5 = Flashcard("Dublin", "What is the capital of Ireland?", deck_1)
flashcard_repository.save(card_5)
card_6 = Flashcard("Berlin", "what is the capital of Germany?", deck_1)
flashcard_repository.save(card_6)
card_7 = Flashcard("Cairo", "What is the capital of Egypt?", deck_1)
flashcard_repository.save(card_7)
card_8 = Flashcard("Marakesh", "what is the capital of Moroco?", deck_1)
flashcard_repository.save(card_8)
예제 #29
0
import tensorflow as tf

from models.cards import Card
from models.data_transformer import DataTransformer
from models.deck import Deck
from models.game import Game
from models.neural_network import KerasNetwork
from models.ranks import Rank
from models.simulator import KerasSimulator
from models.suits import Suit
from models.agent import *

HEARTSDECK = Deck.gen_default()
QUEENOFSPADES = Card(Suit.SPADES, Rank.QUEEN)
TWOOFCLUBS = Card(Suit.CLUBS, Rank.TWO)
HEARTSDATATRANSFORMER = DataTransformer(number_of_suits=4,
                                        number_of_cards=52,
                                        deck=HEARTSDECK)


class Hearts(Game):
    def __init__(self):
        super(Hearts, self).__init__()


if __name__ == "__main__":
    load_previously_saved_models = True

    with tf.Session() as tensorflow_session:
        if not load_previously_saved_models:
            hearts_networks = [
예제 #30
0
 def testDeallerWith2Cards(self):
     deck = Deck()
     dealer = Dealer(deck)
     dealer.deal()
     self.assertEqual(len(dealer.cards), 2)