讲解CSE240
CSE240 – Assignment 4
Points 50
Introduction
The aim of this assignment is to get you to create a simple linked-structure data
structure with C/C++ structs.
Objectives
Build a Grab-Bag Data Structure using Linked-Nodes
Build a linked-node structure that has some basic link-list style
functionality
Use this Grab-Bag to create and play Hi-Low-Guess game
Create one or more Stucts
Use and manage several pointers
Outcomes:
Linked-Data Data Structure creation and application
User interaction
Creation and use of structs
Pointer use, management and manipulation
Description:
One of the keys to winning card games is to understand probability. Card
Counting is a much vaunted skill amongst Black Jack players and Casinos are
always on the look out to prevent such a skill tipping the odds in favor of a
player.
This assignment is going to create a very basic game to show how card counting
works. We will make a Hi-Lo-Guess game. The player will be presented a card and
guess if the next card will be higher or lower. The player will be given a point
for each time they guess correctly.
Each round the game will calculate the probability of the next card being higher
or lower and the probability of drawing any specific number.
This will be accomplished by simulating a deck of cards with a Grab-Bag data
structure.
Grab Bag
The Grab-Bag is a simple data structure that can be created either with an array
or a linked structure (We are going to opt for the linked structure). The GrabBag
has two major functions:
add things to the bag
remove things RANDOMLY from the bag
Specifications
Bag (65% specification)
You are to implement a Grab-Bag data structure in C/C++. You may choose to use
either language as your code base.
You will create several structs to accomplish this:
Card Struct
o Suit
o Value
BagNode
o Card* card
o BagNode* next
You will maintain any and all necessary pointers to create and maintain the bag.
This should be similar to a linked-list in approach. A head pointer and possibly
a tail pointer are good ideas.
You will also implement several functions to create the functionality of the bag:
getCurrentSize():int – item count of bag
isEmpty():bool/int – is the bag empty or not
add(
o Hint – think about which add function you want to use from the linked
list
o Hint – Remember we remove randomly … so … do we need any fancy
insertion?
grab():Card – get a card out of the bag!
o Remember this is random
Hint – arbitrary remove
Hint – don’t forget your cases
getFrequencyOf(
bag
empty() – empty the bag
fillWithCards() – fill the bag with a new deck of 52!
I have not outlined perfectly every function that you may need or write. The
above functions are REQUIRED though. You may implement any needed functions to
help or perform other tasks.
Also note that I don’t have the parameters perfectly laid out for you.
You will have to pass pointers around to make these functions work.
If you are using C – remember you don’t have Pass-By-Reference, so make sure you
return that Head pointer or otherwise deal with that problem.
If you are using C++ - remember you DO have Pass-By-Reference, use that to your
advantage.
Hi-Low-Guess Game
Your goal is to create a simple “Hi-Low-Guess” game for the player to play. The
computer will act as the dealer and the player will be given 3 options: the next
card will be higher, the next card will be lower, guess the next card.
If the player guesses higher or lower and they are correct they get a point. If
they guess a specific card, they get 5 points!
If the card is equal value, the player neither wins or loses and is awarded 0
points and is prompted to guess again.
Each time the player is offered a guess they should be shown:
All the cards that have been drawn so far
The last card drawn that you’re guessing against
The probability the next card will be higher
The probability the next card will be lower
The probability of drawing a specific value
Other requirements:
The player will keep guessing until they get their guess wrong
You should re-populate the deck after the deck has been 2/3rds used
o Leave the last card drawn out though
o Make sure you tell the player that the deck was re-filled
Count Aces as low (value 1)
Notes:
The bag is the deck. Since you pick stuff out of the bag randomly, you
don’t have to shuffle it
You should use H, D, S and C for Hearts, Diamonds, Spades and Clubs
You should use numerical values 1 – 13 for card values
Make a printCard function that “pretty prints” your card for you
While there are explicitly required functions for the high-low game – YOU
ARE EXPECTED TO WRITE APPROPRIATE FUNCTIONS
The player can play as long as they keep guessing correctly. Don’t forget
to refill the bag after 34 cards have been drawn. Don’t forget to tell your
user that you are doing so.
Sample output:
Cards drawn:
[K-H] [4-S] [7-D]
Cards left in deck: 49
Probability of next card being higher: 46.94%
Probability of next card being lower: 46.94%%
Probability of next card being the same: 6.12%
Probability of next card being:
A 8.16%
2 8.16%
3 8.16%
4 6.12%
5 8.16%
6 8.16%
7 6.12%
8 8.16%
9 8.16%
10 8.16%
J 8.16%
Q 8.16%
K 6.12%
Last card: [7-D]
Points: 2
Choose option:
1 – Next card will be higher
2 – Next card will be lower
3 – Guess exact value
Use cases:
If the user selects 1 or 2, draw the next card.
o Award a point if the user guessed right and prompt them for their next
guess showing all the above information.
o If the user guesses wrong. It’s game over. Tell them “GAME OVER” and
show them their score. Exit the game.
o If the card is the same value as the previous card, then tell the user
“Same card” and give them 0 points and prompt them for their next
guess showing all the above information.
If the user uses option 3:
o Prompt the user for the value they want to guess.
o Draw the next card.
o If the value matches, then give the user 5 points and prompt them for
their next guess showing all the above information.
o If the value doesn’t match, it’s game over. Tell them “GAME OVER” and
show them their score. Exit the game.
Extra Credit +5
Implement the Bag entirely in its own library
Create a Makefile to compile the code.
Recommended reading:
https://www.geeksforgeeks.org/write-header-file-c/
https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_2.html
Grading of Programming Assignment
The TA will grade your program following these steps:
(1) Compile the code. If it does not compile a U or F will be given in the
Specifications section. This will probably also affect the
Efficiency/Stability section.
(2) The TA will read your program and give points based on the points allocated
to each component, the readability of your code (organization of the code and
comments), logic, inclusion of the required functions, and correctness of the
implementations of each function.
Rubric:
What to Submit?
You are required to submit your solutions in a compressed format (.zip). Zip all
files into a single zip file. Make sure your compressed file is labeled correctly
【讲解CSE240】WX:codehelp
The compressed file MUST contain the following:
If you do the extra credit also include:
Makefile
No other files should be in the compressed folder.
If multiple submissions are made, the most recent submission will be graded, even
if the assignment is submitted late.
Where to Submit?
All submissions must be electronically submitted to the respected homework link in
the course web page where you downloaded the assignment.
Academic Integrity and Honor Code.
You are encouraged to cooperate in study group on learning the course materials. However, you may not
cooperate on preparing the individual assignments. Anything that you turn in must be your own work: You must
write up your own solution with your own understanding. If you use an idea that is found in a book or from other
sources, or that was developed by someone else or jointly with some group, make sure you acknowledge the
source and/or the names of the persons in the write-up for each problem. When you help your peers, you should
never show your work to them. All assignment questions must be asked in the course discussion board. Asking
assignment questions or making your assignment available in the public websites before the assignment due will
be considered cheating.
The instructor and the TA will CAREFULLY check any possible proliferation or plagiarism. We will use the
document/program comparison tools like MOSS (Measure Of Software Similarity: http://moss.stanford.edu/) to
check any assignment that you submitted for grading. The Ira A. Fulton Schools of Engineering expect all
students to adhere to ASU's policy on Academic Dishonesty. These policies can be found in the Code of Student
Conduct:
http://www.asu.edu/studentaffairs/studentlife/judicial/academic_integrity.h
tm
ALL cases of cheating or plagiarism will be handed to the Dean's office. Penalties include a failing grade in the
class, a note on your official transcript that shows you were punished for cheating, suspension, expulsion and
revocation of already awarded degrees.
推荐阅读
- 演讲手势
- 青椒板书--足球
- 金刚经第1品讲解
- 有趣的oython|python疲劳驾驶实时检测项目讲解(附代码)
- 听老师讲解电影课(5):听电影讲解,看生命样本(福斯特医生)
- #学习|#学习 #高考 #高中 #政治#高中讲解 #学习 #高考 高考政治大题(7)
- Mixed|Mixed Supervised Object Detection with Robust Objectness Transfer讲解
- 民航总医院10月25日下午三点名医直播讲解三叉神经痛的科学治疗
- 【最棒的讲解】细说element分页
- GoWeb开发_Iris框架讲解(二)(Get、Post、Put等请求及数据返回格式)