def testGameCreation(self): football = Game() football.title = "The Big football game" football.description = "Blah Blah Blah" football.players = self.players[1] football.save() for player in self.players[1:]: football.players = player football.save()
def create_new_game(players, name): import uuid from models import Game from constants import default_counter from constants import win_types game = Game() game.game_name = name game.game_id = str(uuid.uuid1()) game.players = players game.current_player = random.randint(0, len(players) - 1) game.data = json.dumps(create_world_data()) game.move_counter = default_counter game.major_arcana = [] arcana = get_major_arcana() for i in range(len(players)): num = random.randint(0, len(arcana) - 1) game.major_arcana.append(arcana[num]) del arcana[num] goals = get_goals() game.goals = [] for i in game.major_arcana: for goal in win_types[i]: num = random.randint(0, len(goals[goal]) - 1) game.goals.append(goals[goal][num]) del goals[goal][num] game.put()
def test_blackjack_payout(self): player = Player('cory','password') game = Game('Blackjack') hand = Hand() game.players = [] player.bank = 100 player.hands = [hand] hand.bet = 0 game.deck = Hand() game.dealer = Player('cory','password') game.dealer.hands.append(Hand()) game.hands.append(game.dealer.hands[0]) player.hands.append(hand) game.hands.append(hand) game.deck.cards = piece_maker(suits, card_values, 1) game.players.append(player) cards_app.session.flush() # testing player AND dealer get blackjack hand.cards = [Card(sequence=1), Card(sequence=10)] game.dealer.hands[0].cards = [Card(sequence=1), Card(sequence=10)] bet(hand, 50) count_blackjack(hand) blackjack_dealer(game) assert player.bank == 100 # Player gets 15 and dealer gets 15, dealer hits and breaks because deck is unshuffled and king on top player.bank = 100 hand.cards = [Card(sequence=10), Card(sequence=5)] game.dealer.hands[0].cards = [Card(sequence=10), Card(sequence=5)] bet(hand, 50) hand.is_expired = False count_blackjack(hand) blackjack_dealer(game) assert player.bank == 150 # player gets blackjack, dealer doesn't hand.is_expired = False hand.bet = 0 player.bank = 100 hand.cards = [Card(sequence=10), Card(sequence=1)] game.dealer.hands[0].cards = [Card(sequence=10), Card(sequence=10)] bet(hand, 50) count_blackjack(hand) blackjack_dealer(game) assert player.bank == 175 # player broke, loses bet hand.is_expired = False hand.bet = 0 player.bank = 100 hand.cards = [Card(sequence=10), Card(sequence=10), Card(sequence=10)] game.dealer.hands[0].cards = [Card(sequence=10), Card(sequence=10)] bet(hand, 50) count_blackjack(hand) blackjack_dealer(game) blackjack_payout(game) assert player.bank == 50
def post(self): logging.debug("CreateGame: ") user = auth() if user == None: logging.debug("CreateGame: Entered unauthenticated user!!") self.response.out.write(json.dumps({'error': 'Unauthenticated User'})) return #sendMessage(user, "HELLO"); logging.debug("CreateGame: Before creating Game Object") #Create Game game = Game() game.name = self.request.get("name") game.players = [] game.messages = [] game.creator = user.key().id() game.location = user.location game.range = float(self.request.get('range')) game.startTime = datetime.datetime.now() logging.debug("CreateGame: Before creating Clue Object") clue = MyMessage() clue.text = self.request.get('clue') clue.time = datetime.datetime.now() clue.put() logging.debug("CreateGame: Clue Object Created") game.clue = clue.key().id() game.active = True game.put() logging.debug("Game object created") clue.gameid = game.key().id() clue.user = user clue.put() user.activeGame = game user.put() #Notify users in the location #Return Game ID to UI logging.debug(game.key().id()) self.response.out.write(json.dumps({'gameid': game.key().id()}))
def test_blackjack_dealer(self): player = Player('cory','password') game = Game('Blackjack') hand = Hand() game.players = [] player.bank = 100 game.deck = Hand() game.dealer = Player('cory','password') game.dealer.hands.append(Hand()) game.hands.append(game.dealer.hands[0]) player.hands.append(hand) game.hands.append(hand) game.deck.cards = piece_maker(suits, card_values, 1) game.players.append(player) cards_app.session.flush() player.hands[0].cards = [Card(sequence=10), Card(sequence=8)] game.dealer.hands[0].cards = [Card(sequence=6), Card(sequence=1)] bet(player.hands[0], 50) count_blackjack(player.hands[0]) blackjack_dealer(game) blackjack_payout(game) # blackjack dealer should break after hitting on he soft 17 assert player.bank == 150