Exemplo n.º 1
0
def game (name, t):
    remaining = list(range(1,10))
    flag = True

    time1 = time.time()
    t_remain = t
    while flag & (len(remaining)!=0) & (t_remain>0):
        r = roll(sum(remaining))
        if not box.isvalid(r, remaining):
            flag = False
        else:
            print(f"Numbers left: {remaining}")
            print(f"Roll: {r}")
            time2 = time.time()
            t_remain = round(t+(time1-time2), 2)
            print(f"Seconds left: {t_remain}")
            inp = input("Numbers to eliminate: ")
            choices = box.parse_input(inp,remaining)
            while len(choices)==0 or sum(choices)!=r:
                print("Choice not successful, please try again. ")
                inp = input("Numbers to eliminate: ")
                choices = box.parse_input(inp,remaining)
            remaining = box.kick(remaining, choices)

    if len(remaining)==0:
        print(f"Score for player {name}: 0 points")
        print(f"Time played: {-time1+time2} seconds")
        print("Congratulations!! You shut the box!")
    elif t_remain<=0:
        print("You lose. You're outta time.")
    else:
        print(f"No selection is possible.")
        print(f"Score for player {name}: {sum(remaining)} points")
        print(f"Time played: {-time1+time2} seconds")
def shut_the_box(name, my_time):
    import time
    import random
    import box

    initial_time = time.time()
    numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    die = [1, 2, 3, 4, 5, 6]
    end = False

    while end == False:
        current_time = float(my_time) + (initial_time - time.time())
        current_time = round(current_time, 2)

        if current_time <= 0:
            end = end_score(name, numbers, initial_time, end)
            print("Better luck next time!")
            break

        if sum(numbers) <= 6:
            roll = sum(random.sample(die, 1))
        else:
            roll = sum(random.sample(die, 2))

        print("\nNumbers left: " + str(numbers))
        print("Roll: " + str(roll))

        if box.isvalid(roll, numbers):
            print("Seconds left: " + str(current_time))
            user_input = input("Numbers to eliminate: ")
            choices = box.parse_input(user_input, numbers)

            while isvalid(choices, numbers, roll) == False:
                current_time = float(my_time) + (initial_time - time.time())
                current_time = round(current_time, 2)
                print("Invalid input\n")
                print("Seconds left: " + str(current_time))
                user_input = input("Numbers to eliminate: ")
                choices = box.parse_input(user_input, numbers)

            for i in range(len(choices)):
                numbers.remove(choices[i])

        else:
            end = end_score(name, numbers, initial_time, end)
            print("Better luck next time!")

        if len(numbers) == 0:
            end = end_score(name, numbers, initial_time, end)
            print("Congratulations!! You shut the box!")
Exemplo n.º 3
0
def shut_the_box(name, time_left):

    list_numbers = list(range(1, 10))
    dice_numbers = list(range(1, 6))
    roll_dice = 0
    time_left = int(time_left)
    possible = True

    while (possible):
        start = time.time()
        good = True
        if min(list_numbers) + max(list_numbers) < 7:
            roll = random.choice(dice_numbers)
        else:
            roll = random.choice(dice_numbers) + random.choice(dice_numbers)
        print("Numbers left:", list_numbers)
        print("Roll:", roll)

        if (box.isvalid(roll, list_numbers) == False):
            print("Game over!", "\n")
            print("Score for player", name, ":", sum(list_numbers), " points")
            print("Time played:", round(time_left, 2), " seconds")
            print("Better luck next time!")
            return

        print("Seconds left", round(time_left, 2))
        while (good == True):
            eliminate = input("Numbers to Eliminate: ")
            print("")
            remove_numbers = box.parse_input(eliminate, list_numbers)
            if not remove_numbers:
                print("Invalid input")
            elif not sum(remove_numbers) == roll:
                print("Invalid input")
            else:
                for i in remove_numbers:
                    list_numbers.remove(i)
                good = False
            end = time.time()
            time_left = time_left - (end - start)
            if (time_left <= 0):
                print("Game over!", "\n")
                print("Score for player", name, ":", sum(list_numbers),
                      " points")
                print("Time played:", round(time_left, 2), " seconds")
                print("Better luck next time!")
                possible = False
                return
            if not list_numbers:
                possible = False
                print("Score for player", name, ":", sum(list_numbers),
                      " points")
                print("Time played:", round(time_left, 2), " seconds")
                print("Congratulations! You shut the box :)")
                return
Exemplo n.º 4
0
def shut_the_box():
    print("Numbers left:", s)
    roll = real_dice() + real_dice() if sum(s) > 6 else real_dice()
    print("Roll:", roll)
    print_time()
    if not box.isvalid(roll, s):
        print("Ha ha, you lose sucker :P")
        return False
    res = input("Numbers to eliminate:")
    nums = box.parse_input(res, s)
    while sum(nums) != roll:
        print("Invalid input!")
        res = input("Numbers to eliminate:")
        nums = box.parse_input(res, s)
    for i in nums:
        s.remove(i)
    if not len(s):
        print("Wow! How'd someone like you manage to win this game")
        return False
    return True
Exemplo n.º 5
0
def shut_the_box():
    """Play a single game of shut the box."""

    # Get the player's name.
    if len(sys.argv) != 2:
        player = raw_input("Player name: ")
    else:
        player = sys.argv[1]

    # Initialize the box.
    numbers = range(1,10)

    # Take a turn until either the player wins or gets a game over.
    while len(numbers) > 0:
        if sum(numbers) <= 6:       # Roll a single die.
            roll = randint(1,6)
        else:                       # Roll two dice.
            roll = randint(1,6) + randint(1,6)

        # Print the game information.
        print "\nNumbers left:", numbers
        print "Roll:", roll
        if not isvalid(roll, numbers):
            print "Game over!"
            break

        # Choose a valid integer or integers to eliminate.
        choices = []
        while len(choices) == 0:
            # Parse the player's input.
            choices = parse_input(raw_input("Numbers to eliminate: "), numbers)
            # Make sure the player's choices actually sum up to the roll.
            if sum(choices) == roll:
                # Remove the player's choices from the remaining numbers.
                for number in choices:
                    numbers.remove(number)
            # Report invalid input and go back to the top of the inner loop.
            else:
                print "Invalid input"
                choices = []

    # Report the player's final score.
    score = sum(numbers)
    print("\nScore for player " + player + ": " + str(score) + " points")
    # or print("\nScore for player {}: {} points".format(player, score))
    if score == 0:
        print("Congratulations!! You shut the box!")
    print("")
Exemplo n.º 6
0
def shut_the_box():
    """Play a single game of shut the box."""

    # Get the player's name.
    if len(sys.argv) != 2:
        player = raw_input("Player name: ")
    else:
        player = sys.argv[1]

    # Initialize the box.
    numbers = range(1, 10)

    # Take a turn until either the player wins or gets a game over.
    while len(numbers) > 0:
        if sum(numbers) <= 6:  # Roll a single die.
            roll = randint(1, 6)
        else:  # Roll two dice.
            roll = randint(1, 6) + randint(1, 6)

        # Print the game information.
        print "\nNumbers left:", numbers
        print "Roll:", roll
        if not isvalid(roll, numbers):
            print "Game over!"
            break

        # Choose a valid integer or integers to eliminate.
        choices = []
        while len(choices) == 0:
            # Parse the player's input.
            choices = parse_input(raw_input("Numbers to eliminate: "), numbers)
            # Make sure the player's choices actually sum up to the roll.
            if sum(choices) == roll:
                # Remove the player's choices from the remaining numbers.
                for number in choices:
                    numbers.remove(number)
            # Report invalid input and go back to the top of the inner loop.
            else:
                print "Invalid input"
                choices = []

    # Report the player's final score.
    score = sum(numbers)
    print("\nScore for player " + player + ": " + str(score) + " points")
    # or print("\nScore for player {}: {} points".format(player, score))
    if score == 0:
        print("Congratulations!! You shut the box!")
    print("")
Exemplo n.º 7
0
def shutTheBox(name, seconds):
    if seconds <= 0:
        print("Number of seconds must be greater than zero")
        return
    rem = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    roll = 0
    total_time = 0
    if sum(rem) > 6:
        roll = random.randint(2, 12)
    else:
        roll = random.randint(1, 6)
    print("Numbers left:", rem)
    print("Roll:", roll)
    while total_time < seconds and box.isvalid(roll, rem) and rem != []:
        print("Seconds left:", round(seconds - total_time, 2))
        start = time.time()
        elim = input("Numbers to eliminate: ")
        end = time.time()
        total_time += end - start
        elim = box.parse_input(elim, rem)
        if sum(elim) != roll:
            print("Invalid input\n")
            continue
        for i in range(len(elim)):
            rem.remove(elim[i])
        if sum(rem) > 6:
            roll = random.randint(2, 12)
        else:
            roll = random.randint(1, 6)
        print()
        if total_time < seconds:
            print("Numbers left:", rem)
            print("Roll:", roll)
    if rem != []:
        print("Game over!")
    print("\nScore for player", name, "=", sum(rem))
    print("Time played:", round(total_time, 2), "seconds")
    if rem == []:
        print("Congratulations! You shut the box!")
    else:
        print("Better luck next time! >:)")
def shut_the_box(name, total_time):

    """
    if len(sys.argv) != 3:
	     raise ValueError("You need at least three Arguements")

    name = sys.argv[1]
    total_time = float(sys.argv[2]
    """

    number_left = list(range(1,10))
    dice_1 = list(range(1,7))
    dice_2 = list(range(1,7))
    first_roll = int(random.choice(dice_1)) + int(random.choice(dice_2))
    start_time = time.time()

    time_left = round(total_time, 2)

    number_picked = ""

    success = True

    while success == True:
    #box.isvalid(random.choice(dice_1) + random.choice(dice_1), number_left):
        print("Number left: ", number_left)
        if max(number_left) > 6:
            roll = int(random.choice(dice_1)) + int(random.choice(dice_1))
        else:
            roll = int(random.choice(dice_1))
        print("Roll: ", roll)

        if success != box.isvalid(roll, number_left):
            print("Game over!")
            print("Score for player ", name, ": ", sum(number_left), "points")
            end_time = time.time()
            time_spent = round((end_time - start_time),2)
            print("Time played: ", time_spent, "seconds")
            print("Better luck next time >:)")
            success = False
        else:
            end_time = time.time()
            time_spent = (end_time - start_time)
            time_left = round(total_time - time_spent,2)
            if time_left <= 0:
                print("Game over!")
                print("Score for player ", name, ": ", sum(number_left), "points")
                end_time = time.time()
                time_spent = round((end_time - start_time),2)
                print("Time played: ", time_spent, "seconds")
                print("Better luck next time >:)")
                success = False
            else:
                print("Second left: ", time_left)
                number_picked = input("Number to eliminate: ")
                print("\n")


                if sum(box.parse_input(number_picked, number_left )) == roll:
                    for x in box.parse_input(number_picked, number_left ):
                        number_left.remove(x)

                else:
                    print("invalid input")
                    success = True
        if len(number_left) == 0:
            print("Score for player ", name,": ", sum(number_left), "points")
            end_time = time.time()
            time_spent = round((end_time - start_time),2)
            print("Time played: ", time_spent, "seconds")
            print("Congratulations! You shut the box!")
            success = False
Exemplo n.º 9
0
def shut_the_box():
    """Plays a game of shut the box
    A player name and time limit in seconds must be entered in the command
    line when this file is executed to play this game."""
    #Only output if exactly three command line arguments are entered.
    if len(sys.argv) != 3:
        return
#Get the time limit and player name
    time_limit = float(sys.argv[2])
    name = sys.argv[1]
    #Print instructions, wait for them to be read
    print("Objective:\nGet the lowest score possible in the alloted time.")
    print("Instructioms:")
    print(
        "Two dice are rolled each round. You must eliminate numbers from the box whose sum is equal to the numbers rolled on the dice. Enter the numbers to be eliminated with only one space of separation between each number. Your score is the sum of the remaining numbers in the box."
    )
    print("You only have", time_limit, "seconds to play.")
    input_ready = input("Are you ready? ")
    if input_ready.lower() == "no" or input_ready.lower() == "n":
        input_sure = input("Are you sure? ")
        if input_sure.lower() == "yes" or input_sure.lower() == "y":
            print("Awww...")
            print("Game over before it even begins.")
            return
#Make the list of numbers to remove
    num_left = list(range(1, 10))
    #Get start time
    start_time = time.time()
    current_time = start_time
    end_time = start_time + time_limit
    #Keep going until time runs out or the player wins
    while current_time < end_time:
        #Print remaining numbers
        print("\nNumbers left: ", num_left)
        #Get and print rolls
        if sum(num_left) <= 6:
            roll = random.randint(1, 6)
        else:
            roll = random.randint(1, 6) + random.randint(1, 6)
        print("Roll:", roll)
        #Check possibility of matching roll
        if not box.isvalid(roll, num_left):
            print("\nImpossible roll. So sorry!")
            print("Game over!")
            print("Score for player", name + ":", sum(num_left), "points")
            print("Time played: ", round(current_time - start_time, 2),
                  "seconds")
            print("Better luck next time ;)")
            return
#Get and print the time
        current_time = time.time()
        print("Seconds left", round(end_time - current_time, 2))
        #Get the numbers to eliminate, responding to input appropriately
        while True:
            input_str = input("Numbers to eliminate: ")
            num_elim = box.parse_input(input_str, num_left)
            if sum(num_elim) != roll:
                print("\nInvalid input")
                current_time = time.time()
                print("Seconds left:", round(end_time - current_time, 2))
                continue
            else:
                break
#Get rid of numbers to eliminate
        for number in num_elim:
            num_left.remove(number)
        current_time = time.time()
        #Success or failure?
        if num_left == []:
            print("Score for player", name + ": 0 points")
            print("Time played:", round(current_time - start_time, 2),
                  "seconds")
            print("Hooray! You shut the box!")
            return
    print("\nTime's up! Game over!")
    print("Score for player", name + ":", sum(num_left), "points")
    print("Time played: ", round(current_time - start_time, 2), "seconds")
    print("Better luck next time ;)")
    return
Exemplo n.º 10
0
       
        isvalidRoll = box.isvalid(sum_rolls, remaining)

        if not isvalidRoll:
            print("\nScore for player " + name + ": 0 points")
            print("Time played: " + str(round((time_lim - remaining_time), 2)) + " seconds.")
            print('You lost, ' + name + ".")
            break

        true_input = False
        while not true_input:

            start_time = time.time()

            input_values = input("Numbers to eliminate: ")
            choices = box.parse_input(input_values, remaining)
            if choices != []:
                if sum(choices) == sum_rolls:
                    true_input = True
                    break
            print("Invalid input. Try again.")

            end_time = time.time()
            loop_time = end_time - start_time
            remaining_time -= loop_time

            print("\nSeconds left " + str(round(remaining_time, 2)))

        for x in choices:
            remaining.remove(x)
Exemplo n.º 11
0
 else:
     dice = random.randint(1, 6) + random.randint(1, 6)
 print("Roll: ", dice)
 if not box.isvalid(dice, remaining):
     print("Game Over")
     summ = sum(remaining)
     print("Score for player ", name, ":", summ ," points")
     print("Time played: ", timediff, "seconds")
     print("Better luck next time >:")
     quit()
 timediff = time.time() - begintime
 print("Seconds left: ", timelimsec - timediff)
 inputs = False
 while inputs == False:
     name_input = input("Numbers to eliminate: ")
     parsed_input = box.parse_input(name_input, remaining)
     if parsed_input:
         if sum(parsed_input) == dice:
             for i in range(1, len(parsed_input) + 1):
                 remaining.remove(parsed_input[i-1])
             inputs = True
         else:
             print("Invalid input")
     else:
         print("Invalid input")
 print("")
 if not remaining:
     print("Score for player ", name, ": 0 points")
     print("Time played: ", timediff, "seconds")
     print("Congratulations!! You shut the box!")
     quit()
Exemplo n.º 12
0
            roll = roll1 + roll2

        end = time.time()
        loop_time = end - timer
        remain -= loop_time

        if remain < 0:
            print("Lost")
            break

        if b.isvalid(roll, nums):
            print("Left: ", str(nums))
            print("Roll: ", str(roll))
            e = input("Nums to elminate?")

            while b.parse_input(e, nums) == []:
                print("Invalid!")
                e = input("Nums to elminate?")
            while sum(b.parse_input(e, nums)) != roll:
                print("Inavlid!")
                e = input("Nums to elminate?")

            rem = b.parse_input(e, nums)
            nums = [n for n in nums if n not in rem]

        else:
            over = 1
            print("Game Over")
pts = sum(numbers)
print(name, ": ", score)
if pts == 0:
Exemplo n.º 13
0
        while tot_time - elapsed > 0:
            roll = gen_roll(remaining)

            print("Numbers left: ", remaining)
            print("Roll: ", roll)

            if not box.isvalid(roll, remaining):
                print("Game over!")
                print()
                break

            print("Seconds left: ", round(tot_time - elapsed))
            to_elim_input = input("Numbers to eliminate: ")

            to_elim = box.parse_input(to_elim_input, remaining)
            while not to_elim:
                print("Invalid input")
                print()
                elapsed = time.time() - start
                print("Seconds left: ", round(tot_time - elapsed))
                to_elim_input = input("Numbers to eliminate: ")
                to_elim = box.parse_input(to_elim_input, remaining)

            print()

            remaining = [x for x in remaining if x not in to_elim]

            if len(remaining) == 0:
                win = True
                break
Exemplo n.º 14
0
name = sys.argv[1]

while len(remaining) > 0 and tim1 <= tt:
    tim1 = time.time() - tim0
    if sum(remaining) <= 6:
        roll = random.choice(numbers)
    else:
        roll = random.choice(numbers) + random.choice(numbers)
    print("Numbers left: ", remaining)
    print("Roll: ", roll)
    print("Seconds left", tt - tim1)

    if box.isvalid(roll, remaining) == 1:
        print(remaining)
        x = input("Numbers to eliminate: ")
        choice = box.parse_input(x, remaining)
        if sum(choice) != roll:
            x = input("Numbers to eliminate: ")
        print("Numbers to eliminate: ", choice)
        remaining = [x for x in remaining if (x not in choice)]

    else:
        print("Score for player " + name, sum(remaining), "points")
        print("Time played: ", tt - tim1)
        sys.exit('you lost')

    if tim1 >= tt:
        print("Score for player " + name, sum(remaining), "points")
        print("Time played: ", tt - tim1)
        sys.exit('you lost')
while (time.time() < end_time):
    #while we have time remaining
    print("Numbers left: ", numbers_left)
    roll = get_roll(numbers_left)
    print("Roll: ", roll)

    #check if there exists choices to eliminate
    if box.isvalid(roll, numbers_left) == False:
        #the user loses
        no_choice = True
        break

    print("Seconds left: ", round(end_time - time.time(), 2))

    list_of_int = box.parse_input(input("Numbers to eliminate: "),
                                  numbers_left)
    #remove user's selection from the number list
    for i in list_of_int:
        numbers_left.remove(i)
    #if every element has been removed:
    if len(numbers_left) == 0:
        zero_left = True
        break

if no_choice:
    print("Game over!", "\n")
    print("Score for player ", username, ": ", sum(numbers_left), " points")
    print("Time played: ", round(time.time() - start_time, 2), " seconds")
    print('Better luck next time >:)')
elif zero_left:
    print("Score for player ", username, ": ", "0 points")
Exemplo n.º 16
0
        if sum(remaining) > 6:
            #roll two dice
            roll = dice_roll()+dice_roll()
        else:
            #roll only one die
            roll = dice_roll()

        print "Roll: ",roll
        if not box.isvalid(roll, remaining):
            print ("Game over!")
            break

        choices = []

        while not len(choices):
            raw_nums = prompt("Numbers to eliminate")
            choices = box.parse_input(raw_nums, remaining)
            if sum(choices) != roll:
                choices = []
            if not len(choices):
                print ("Invalid input")

        remaining = remove_list(remaining, choices)
        if sum(remaining) == 0:
            break

    print "Score for Player %s: %d points" % (name, sum(remaining))
    if sum(remaining) == 0:
        print ("Congratulations! You emptied the box!")
Exemplo n.º 17
0
if len(sys.argv) < 3:
    print("Not enough arguments (needs 3)")
if len(sys.argv) > 3:
    print("Too many arguments (needs 3)")
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
start_time = time.time()
while len(numbers) != 0 and (time.time()- start_time)< float(sys.argv[2]) :
    droll1 = random.randint(1,6)
    droll2 = random.randint(1,6)
    
    if not box.isvalid(droll1+ droll2, numbers):
        break
    print("Roll: {}".format(droll1 + droll2))
    print("Time Remaining: {}".format(float(sys.argv[2]) - (time.time()-start_time)))
    player_input = input("Numbers to eliminate: ")
    ints = box.parse_input(player_input, numbers)
    if len(ints) == 0:
        break
    for x in ints:
        numbers.remove(x)
    print(numbers)
print("Score for player {}: {} points".format(sys.argv[1], sum(numbers)))
print("Time played: {}".format(time.time()-start_time))

if (time.time()- start_time) > float(sys.argv[2]):
    print("You ran out of time, nitwit.")
elif len(ints) == 0:
    print('Invalid input. Game over')
elif len(numbers) == 0:
    print("Winner, winner!!!!")
else: print("Number's can't match roll! Game over.")
Exemplo n.º 18
0
             roll = random.randint(2, 12)
         # if the sum of the list is less than 6, roll one dice
         else:
             roll = random.randint(1, 6)
     # use box.py to check if there are possible combinations of the user's list that sum up to the roll
     if b.isvalid(roll, lst):
         print("Numbers left: " + str(lst))
         print("Roll: %i" % roll)
         x = True
         # while loop that promps the user for valid numbers to eliminate
         while x:
             print("Seconds left: %f seconds " %
                   round(t - (time.time() - start)))
             el = input("Numbers to eliminate: ")
             # use box.py to check if the user's input is in the list
             ints_to_el = b.parse_input(el, lst)
             # if the user's input isn't in the list, continue through the while loop
             if ints_to_el == []:
                 print("Invalid input")
             # if the user's input is in the list, check if the sum is equal to the roll
             else:
                 # if the sum is equal to the roll, remove the numbers from the list and exit the loop
                 if sum(ints_to_el) == roll:
                     for i in range(len(ints_to_el)):
                         lst.remove(ints_to_el[i])
                     x = False
     # if the user can't shut the box, exit the loop
     else:
         break
 # game won message
 if lst == []:
Exemplo n.º 19
0
while secs - timediff > 0:
    print("Numbers left = ", remaining)
    if sum(remaining) <= 6:
        roll = rnd.randint(1, 6)
    else:
        roll = rnd.randint(1, 6) + rnd.randint(1, 6)
    print("Roll = ", roll)
    if not box.isvalid(roll, remaining):
        print("Game over!")
        quit()
    timediff = time.time() - time0
    print("Seconds left = ", secs - timediff )
    inputs = False
    while inputs == False:
        player_input = input("Numbers to eliminate = ")
        parsed_input = box.parse_input(player_input, remaining)
        if parsed_input:
            if sum(parsed_input) == roll:
                for i in range(1, len(parsed_input) + 1):
                    remaining.remove(parsed_input[i-1])
                inputs = True
            else:
                print("invalid input")
        else:
            print("invalid input")
    print("")
    if not remaining:
        print("Score for player ", player, ": 0 points")
        print("Time played = ", timediff," seconds")
        print("Congratulations!! You shut the box!")
        quit()