Apr-09-2019, 01:23 AM
Hi everyone,
I need some help with my assignment, im not looking for anyone to do the code for me or even tell me what I need to do step by step. I just need push in the right direction to understand what I need to do. Any help is appreciated.
Im working on a python assignment. The end result of the assignment is to produce a program of the game Solitaire that randomly generates a random amount of cards with a random suit between A and D and a random stack location between 1-6 and another value that I dont need to worry about right now.
The code that comes given to me , produces a board and stack locations of where the cards must be displayed and their x and y locations for convenience.
Im required to draw a card with 4 unique graphics to make each suit unique.
Ive made my cards, and defined them as functions.
The important part of the assignment however is to define a function called deal_cards that when run will deal the cards in accordance with the output of another function random_game. random_game is a function that has multiple variable lists that produce an output that my deal_cards function needs.
Ill be hanging around if anyone can lend a hand. Thanks.
To clarify, the function random_game, is used to assess my program and is provided to me in the instructions. I did not code it.
I need some help with my assignment, im not looking for anyone to do the code for me or even tell me what I need to do step by step. I just need push in the right direction to understand what I need to do. Any help is appreciated.
Im working on a python assignment. The end result of the assignment is to produce a program of the game Solitaire that randomly generates a random amount of cards with a random suit between A and D and a random stack location between 1-6 and another value that I dont need to worry about right now.
The code that comes given to me , produces a board and stack locations of where the cards must be displayed and their x and y locations for convenience.
Im required to draw a card with 4 unique graphics to make each suit unique.
Ive made my cards, and defined them as functions.
The important part of the assignment however is to define a function called deal_cards that when run will deal the cards in accordance with the output of another function random_game. random_game is a function that has multiple variable lists that produce an output that my deal_cards function needs.
def random_game(print_game = True): # Percent chance of the extra value being non-zero extra_probability = 20 # Generate all the stack and suit names playable game_stacks = ['Stack ' + str(stack_num+1) for stack_num in range(num_stacks)] game_suits = ['Suit ' + chr(ord('A')+suit_num) for suit_num in range(4)] # Create a list of stack specifications game = [] # Randomly order the stacks shuffle(game_stacks) # Create the individual stack specifications for stack in game_stacks: # Choose the suit and number of cards suit = choice(game_suits) num_cards = randint(0, max_cards) # Choose the extra value if num_cards > 0 and randint(1, 100) <= extra_probability: option = randint(1,num_cards) else: option = 0 # Add the stack to the game, but if the number of cards # is zero we will usually choose to omit it entirely if num_cards != 0 or randint(1, 4) == 4: game.append([stack, suit, num_cards, option]) # Optionally print the result to the shell window if print_game: print('\nCards to draw ' + '(stack, suit, no. cards, option):\n\n', str(game).replace('],', '],\n ')) # Return the result to the student's deal_cards function return gameThe random_game function also displays the output in the shell window to show what is required of the deal_cards function, this is random every time its generated:
Cards to draw (stack, suit, no. cards, option): [['Stack 6', 'Suit C', 2, 0], ['Stack 2', 'Suit A', 1, 0], ['Stack 1', 'Suit A', 6, 0], ['Stack 3', 'Suit B', 10, 0], ['Stack 4', 'Suit D', 3, 1]]Ran again for example,
Cards to draw (stack, suit, no. cards, option): [['Stack 3', 'Suit A', 3, 0], ['Stack 6', 'Suit A', 9, 0], ['Stack 4', 'Suit A', 1, 0], ['Stack 2', 'Suit A', 6, 0], ['Stack 1', 'Suit C', 0, 0]]Anyone here who is experienced can probably see that this is basic coding but im just have a bit of trouble understanding how to put the output of the random_game into the deal_cards function and have it work. Im sure its something simple but im just not getting it and ive gotten to the point where I want to ask for help.
Ill be hanging around if anyone can lend a hand. Thanks.
To clarify, the function random_game, is used to assess my program and is provided to me in the instructions. I did not code it.