Example #1
0
def should_dealer_draw(game_id):
    moves = database.get_moves(game_id)[0]

    if get_hand_value(moves.dealer_cards) < 16:
        return True
    else:
        return False
Example #2
0
def did_dealer_bust(game_id):
	moves = database.get_moves(game_id)[0]
	
	if get_hand_value(moves.dealer_cards) > 21:
		return True
	else:
		return False
Example #3
0
def stay_logic(page, game_id, user_id, bet_amount):
    game = db.GqlQuery("SELECT * FROM Game WHERE game_id = :1", game_id)[0]
    #print page.request
    this_user = db.GqlQuery("SELECT * From User WHERE user_id = " +
                            str(user_id))[0]
    moves = database.get_moves(game_id)[0]

    if should_dealer_draw(game_id):
        draw_dealer_card(game_id)
        if did_dealer_bust(game_id):
            end_game(game_id, user_id)
            this_user.cash += long(bet_amount)
            this_user.put()
            page.redirect("/game/win")
        else:
            page.redirect("/game/")
    else:
        if get_hand_value(moves.dealer_cards) > get_hand_value(
                moves.cards_one):
            end_game(game_id, user_id)
            page.redirect("/game/lose")
        else:
            end_game(game_id, user_id)
            this_user.cash += long(bet_amount)
            this_user.put()
            page.redirect("/game/win")
Example #4
0
def should_dealer_draw(game_id):
	moves = database.get_moves(game_id)[0]
	
	if get_hand_value(moves.dealer_cards) < 16:
		return True
	else:
		return False
Example #5
0
def did_dealer_bust(game_id):
    moves = database.get_moves(game_id)[0]

    if get_hand_value(moves.dealer_cards) > 21:
        return True
    else:
        return False
Example #6
0
def did_player_bust(game_id, user_id):
    game = database.get_game(game_id)
    moves = database.get_moves(game_id)[0]

    this_user = database.get_user_by_id(user_id).user
    if get_hand_value(moves.cards_one) > 21:
        return True
    return False
Example #7
0
def did_player_bust(game_id, user_id):
	game = database.get_game(game_id)
	moves = database.get_moves(game_id)[0]
	
	this_user = database.get_user_by_id(user_id).user
	if get_hand_value(moves.cards_one) > 21:
			return True
	return False
Example #8
0
def draw_hidden_dealer_card(game_id):
    moves = database.get_moves(game_id)[0]
    deck_one = moves.deck_one
    deck_two = moves.deck_two

    #card, d_one, d_two = get_card(deck_one, deck_two)
    game = db.GqlQuery("SELECT * FROM Game WHERE game_id = :1", game_id)

    card = '<img src="' + back_location + '" />'

    moves.dealer_cards.append(card)
    moves.put()

    return card
Example #9
0
def draw_hidden_dealer_card(game_id):
	moves = database.get_moves(game_id)[0]
	deck_one = moves.deck_one
	deck_two = moves.deck_two
	
	#card, d_one, d_two = get_card(deck_one, deck_two)
	game = db.GqlQuery("SELECT * FROM Game WHERE game_id = :1",game_id)
	
	card = '<img src="'+back_location+'" />'
	
	moves.dealer_cards.append(card)
	moves.put()
	
	return card
Example #10
0
def draw_player_card(game_id, user):
    moves = database.get_moves(game_id)[0]
    deck_one = moves.deck_one
    deck_two = moves.deck_two

    card, d_one, d_two = get_card(deck_one, deck_two)

    game = db.GqlQuery("SELECT * FROM Game WHERE game_id = :1", game_id)[0]

    moves.cards_one.append(card)

    moves.deck_one = d_one
    moves.deck_two = d_two
    moves.put()

    return card
Example #11
0
def draw_player_card(game_id, user):
	moves = database.get_moves(game_id)[0]
	deck_one = moves.deck_one
	deck_two = moves.deck_two
	
	card, d_one, d_two = get_card(deck_one, deck_two)
	
	game = db.GqlQuery("SELECT * FROM Game WHERE game_id = :1",game_id)[0]
	
	moves.cards_one.append(card)
	
	moves.deck_one = d_one
	moves.deck_two = d_two
	moves.put()
	
	return card
Example #12
0
def draw_dealer_card(game_id):
	moves = database.get_moves(game_id)[0]
	deck_one = moves.deck_one
	deck_two = moves.deck_two
	
	card, d_one, d_two = get_card(deck_one, deck_two)
	
	if '<img src="'+back_location+'" />' in moves.dealer_cards:
		moves.dealer_cards[moves.dealer_cards.index('<img src="'+back_location+'" />')] = card
	else:
		moves.dealer_cards.append(card)
	moves.deck_one = d_one
	moves.deck_two = d_two
	moves.put()
	
	return card
Example #13
0
def draw_dealer_card(game_id):
    moves = database.get_moves(game_id)[0]
    deck_one = moves.deck_one
    deck_two = moves.deck_two

    card, d_one, d_two = get_card(deck_one, deck_two)

    if '<img src="' + back_location + '" />' in moves.dealer_cards:
        moves.dealer_cards[moves.dealer_cards.index('<img src="' +
                                                    back_location +
                                                    '" />')] = card
    else:
        moves.dealer_cards.append(card)
    moves.deck_one = d_one
    moves.deck_two = d_two
    moves.put()

    return card
Example #14
0
def end_game(game_id, user_id):
	game = database.get_game(game_id)
	moves = database.get_moves(game_id)[0]
	dealer_value = get_hand_value(moves.dealer_cards)
	user_one = get_hand_value(moves.cards_one)
	#user_two = get_hand_value(game.cards_two)
	user_two = 0
	
	oldGame = database.OldGames()
	oldGame.users = game.users
	oldGame.game_id = game_id
	if dealer_value > user_two and dealer_value < 21 :
		oldGame.winner = "dealer"
	else:
		oldGame.winner = "player"
	oldGame.put()
		
	user = database.get_user_by_id(user_id)
	user.current_games.remove(game_id)
	user.put()
	
	game.delete()
Example #15
0
def end_game(game_id, user_id):
    game = database.get_game(game_id)
    moves = database.get_moves(game_id)[0]
    dealer_value = get_hand_value(moves.dealer_cards)
    user_one = get_hand_value(moves.cards_one)
    #user_two = get_hand_value(game.cards_two)
    user_two = 0

    oldGame = database.OldGames()
    oldGame.users = game.users
    oldGame.game_id = game_id
    if dealer_value > user_two and dealer_value < 21:
        oldGame.winner = "dealer"
    else:
        oldGame.winner = "player"
    oldGame.put()

    user = database.get_user_by_id(user_id)
    user.current_games.remove(game_id)
    user.put()

    game.delete()
Example #16
0
	def get(self):
		g_user = users.get_current_user()
		if not g_user:
			self.redirect(users.create_login_url(self.request.uri))
		user = logic.get_player(users.get_current_user())
		#user = logic.get_player(users.User("*****@*****.**"))
		if logic.get_game_for_user(user.user_id):
			game = logic.get_game_for_user(user.user_id)
		else:
			game = logic.make_game(user)
		
		# ---- These should really live in logic.make_game() but being able to comment then out here is so convinent ----
		#logic.draw_dealer_card(game.game_id)
		#logic.draw_player_card(game.game_id)
		
		moves = database.get_moves(game.game_id)[0]
		
		dealer_value = logic.get_hand_value(moves.dealer_cards)
			
		template_values = ({ 'dealer_cards': moves.dealer_cards, 'dealer_value': dealer_value, 'player_cards': moves.cards_one,
							'player_cash': user.cash, 'game_id': game.game_id, 'user_id': user.user_id })
		path = os.path.join(os.path.dirname(__file__), 'game.html')
		self.response.out.write(template.render(path, template_values))
Example #17
0
def stay_logic(page, game_id, user_id, bet_amount):
	game = db.GqlQuery("SELECT * FROM Game WHERE game_id = :1", game_id)[0]
	#print page.request
	this_user = db.GqlQuery("SELECT * From User WHERE user_id = "+str(user_id))[0]
	moves = database.get_moves(game_id)[0]
	
	if should_dealer_draw(game_id):
		draw_dealer_card(game_id)
		if did_dealer_bust(game_id):
			end_game(game_id, user_id)
			this_user.cash += long(bet_amount)
			this_user.put()
			page.redirect("/game/win")
		else:
			page.redirect("/game/")
	else:
		if get_hand_value(moves.dealer_cards) > get_hand_value(moves.cards_one):
			end_game(game_id, user_id)
			page.redirect("/game/lose")
		else:
			end_game(game_id, user_id)
			this_user.cash += long(bet_amount)
			this_user.put()
			page.redirect("/game/win")