Python Forum
Need help with my assignment please - game of Solitaire
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with my assignment please - game of Solitaire
#1
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.

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 game
The 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.
Reply
#2
I would think the deal_cards function would just take game as a parameter:

def deal_cards(game):
    stacks = []
    for stack_name, suit, num_cards, option in game:
        # deal the cards for that stack.
    return stacks
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
That was helpful thanks
Reply
#4
Did it go well with the assigment?
Reply
#5
I am about to make a card game myself, and i want to use your code as an example and a lead for my own code if that is ok?
Reply
#6
(Nov-19-2020, 11:52 PM)Piotrr10 Wrote: I am about to make a card game myself, and i want to use your code as an example and a lead for my own code if that is ok?

Aired lol
Reply
#7
I think it would be easier if u use classes
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Assignment to make a multiple choice game blacklight 1 2,160 Aug-14-2020, 02:37 AM
Last Post: Larz60+
  How to hold a program in the turtle (Tic-Tac-Toe game assignment) kmchap 1 4,570 May-17-2018, 05:39 PM
Last Post: j.crater
  School Work Assignment: Snake Game DarksideMoses 6 5,166 Apr-29-2018, 10:56 PM
Last Post: DarksideMoses
  Implementation Pyramid Solitaire qwerty 2 5,064 Feb-27-2017, 11:57 AM
Last Post: qwerty

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020