Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Submit your hw1.go file via Canvas Learning objectives: After this assignment, you should be able to write a basic Go program using the imperative approach.

Submit your hw1.go file via Canvas

Learning objectives: After this assignment, you should be able to write a basic Go program using the imperative approach.

Your code should generate output like the following: (text in bold is user input)

PS C:\Users\villa\Downloads\311\spr23\assts\cs311spr23hw1> go run .\hw1.go

One pile Solitaire

Top of pile: 2

Card to match: 3

Play from pile

Draw from deck

Choose a move: 1

Top of pile: 3

Card to match: 2

Play from pile

Draw from deck

Choose a move: 1

Top of pile: 0

Card to match: 3

Play from pile

Draw from deck

Choose a move: 1

Top of pile: 2

Card to match: 0

Play from pile

Draw from deck

Choose a move: 1 italicized to highlight that nothing happens on illegal move

Top of pile: 2

Card to match: 0

Play from pile

Draw from deck

Choose a move: 2

Top of pile: 2

Card to match: 3

Play from pile

Draw from deck

Choose a move: 1

Top of pile: 0

Card to match: 2

Play from pile

Draw from deck

Choose a move: 2

Top of pile: 0

Card to match: 2

Play from pile

Draw from deck

Choose a move: 2

Top of pile: 0

Card to match: 1

Play from pile

Draw from deck

Choose a move: 1

Congratulations, you win!

Some details:

This is a version of solitaire with a smaller deck of cards

Cards can have values 0, 1, 2 or 3

There are four of each of these cards, so 16 cards in total

Define names in all-uppercase for these and later constants that you can use in your code

The cards initially go into an int array for the deck, which is shuffled see the sample code at: https://pkg.go.dev/math/rand#ShuffleLinks to an external site.

Deal 5 cards to an int array for the pile

Deal 1 card as the Card to match

The goal is to remove all cards from the pile.

You can only see remove the top card of the pile, which is also the only card you can see on the pile.

You can only remove this card if it matches the Card to match.

Cards match if they are adjacent, with wrap-around. A 0 matches either a 1 or a 3

The italicized lines in the output show that if the player attempts to remove a non-matching card, you just leave everything the same

You do need functions for

dealing cards from the deck to the pile you are just moving the cards from one array to another

playing the game

Comment each function to explain what the function does, as well as the overall program. Short comments are welcome, but do not simply repeat what the syntax already tells us (this is a function called play that takes 2 parameters would be a useless comment, to be blunt)

Choose good variable and function names

Again, name any constants you use, and use those names (like for the choice numbers)

Grading:

Correctness 80%

Style 20% -- 10% for comments, 10% for choosing good names for both variables and any extra functions or constants you define

Overall, you want to make sure what you turn in compiles and runs correctly, so if you do not manage to finish everything, its better to submit something that runs, leaving out changes that cause the code to not compile or crash.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

Discuss how the IF statements are handled in vector loop .

Answered: 1 week ago

Question

2. Identify conflict triggers in yourself and others

Answered: 1 week ago