Friday, June 18, 2010

First Code Jam

Made our first meet-up, at Cafe 103. we did a challenge to make an "AceyDuecy" game in CLI, did pretty good.


#aceyduecyh code jam
#30 minute

import random

firstCard = 0
secondCard = 0
thirdCard = 0
playerBet = 0
playerCash = 1000
cycle = True

def winCheck(first,second,third):
    if third < first and third > second:
        return True
    elif first < third and second > third:
        return True
    else:
        return False

def drawNum():
    return random.randint(1,14)

def cycleCheck():
    flow = input("Continue? (y/n) :").lower()
    if flow == 'y':
        return True
    elif flow == 'n':
        return False
    else:
        print("I'm Sorry, that is not a valid entry...\n")
        ret = cycleCheck()
        return ret
    

while cycle == True:
    print("In this game, two numbers are randomly generated.\n")
    print("You then bet on weither the third number generated will be between the first two\n")
    print("You currently have ",playerCash,"$")
    cycle = cycleCheck()
    firstCard = drawNum()
    secondCard = drawNum()
    thirdCard = drawNum()
    print("First and Second numbers: \n")
    print(firstCard, "\n")
    print(secondCard, "\n")
    playerBet = int(input("Player Bets?: "))
    if playerBet >> playerCash:
        print("invalid bet...")
        continue
    elif playerBet == 0:
        print("Chicken\n")
    print("Third Number :", thirdCard,"\n")
    if winCheck(firstCard,secondCard,thirdCard) == True:
        playerCash = playerCash + playerBet
        print("YOU WIN!!!")
    elif winCheck(firstCard,secondCard,thirdCard) == False:
        playerCash = playerCash - playerBet
        print("Better luck next time")

that was mine, here's Critter's:

#!/usr/bin/python

import random

print "Welcome to the best acey ducey game EVER CREATED (by a person named Critter sitting on a couch in 103) \n"

cash = 100
while True:
    print "\ncash: " + str(cash)
    card1 = random.randint(1,13)
    card2 = random.randint(1,13)
    print "Cards dealt: " + str(card1) + ", " + str(card2)
    answer = raw_input("Pass or Bet? ").lower()
    if "p" in answer:
        pass
    elif "b" in answer:
        bet = int(raw_input("How much you want to bet? "))
        card3 = random.randint(1,13)
        deck = [card1, card2, card3]
        deck.sort()
        print "The dealer drew: " + str(card3) 
        if card3 > card1 and card3 < card2:
            print "Awesome! You win (a gambling addiction)!"
            cash += bet
        else:
            print "Bwahahahaha! Ahhahahah.... Oh geeze...\n*wipes tears of laughter from face*\nYou SUCK!"
            cash -= bet

and jacobs, aka Phear:


import random

deck = {11:'jack', 12:'queen', 13:'king', 14:'ace'}
for num in xrange(1, 11):
    deck[num] = num
money = 100
while True:
    print 'You now have', money, 'dollars.'
    if money < 1:
        print 'You are out of moneys!'
        break
    for _ in xrange(2):
        first_card = random.randint(2, 14)
        second_card = random.randint(2, 14)

    new_card = random.randint(2, 14)
    
    critterDeck = sorted([first_card, second_card, new_card])
    
    print('here are your next two cards:')
    print(deck[first_card])
    print(deck[second_card])
    
    try:
        bet = int(raw_input('\nWhat is your bet? '))
    except ValueError:
        bet = 0
        
    if new_card == critterDeck[1]:
        money += bet
        print(new_card)
        print 'Congrats, you win!'
    elif bet < 1:
        print 'CHICKEN!' 
    else:
        money -= bet
        print(new_card)
        print 'Sorry! You lose!'


Over all, i makes for a good excersice and later we'll work on collaboration. a good success. Next is OOP programming so we can do real collaborations.

Monday, June 7, 2010

Math Drill is done for now....

I just added a loop option to math drill and committed, then posted the .PY in the downloads section so it's good to go. I made sure to show proper respect to the Brain Bacon Clan and insert the Blog URL in the closing credits. Apparently i did it right before everything shifted to read-only on server maintenance day so yay me!

King Critter has made some head way in his effort to log on the school wi-fi today so kudos to him. I have no clue what Jake is up to so screw him, :P