Programming

Programming

# This problem involves a solitaire card game invented just

Customer Question
for this question. You will...
This problem involves a solitaire card game invented just for this question. You will write a program that tracks the progress of a game; writing a game player is a challenge problem. You can do parts (a)–(e) before understanding the game if you wish.
A game is played with a card-list and a goal. The player has a list of held-cards, initially empty. The player makes a move by either drawing, which means removing the first card in the card-list from the card-list and adding it to the held-cards, or discarding, which means choosing one of the held-cards to remove. The game ends either when the player chooses to make no more moves or when the sum of the values of the held-cards is greater than the goal.
The objective is to end the game with a low score (0 is best). Scoring works as follows: Let sum be the sum of the values of the held-cards. If sum is greater than goal, the preliminary score is five times (sum − goal), else the preliminary score is (goal − sum). The score is the preliminary score unless all the held-cards are the same color, in which case the score is the preliminary score divided by 2 (and rounded down as usual with integer division; use ML’s div operator).
a) Write a function card_color, which takes a card and returns its color (spades and clubs are black, diamonds and hearts are red). Note: One case-expression is enough.
b) Write a function card_value, which takes a card and returns its value (numbered cards have their number as the value, aces are 11, everything else is 10). Note: One case-expression is enough.
c) Write a function remove_card, which takes a list of cards cs, a card c, and an exception e. It returns a list that has all the elements of cs except c. If c is in the list more than once, remove only the first one. If c is not in the list, raise the exception e. You can compare cards with =.
d) Write a function all_same_color, which takes a list of cards and returns true if all the cards in the list are the same color. Hint: An elegant solution uses nested pattern-matching.
e) Write a function sum_cards, which takes a list of cards and returns the sum of their values.
• For bonus points, write a function sum_cards_tr, which takes a list of cards and returns the sume of their values; however, it should make use of a locally defined helper function that is tail recursive.
f) Write a function score, which takes a card list (the held-cards) and an int (the goal) and computes the score as described above.
g) Write a function officiate, which “runs a game.” It takes a card list (the card-list) a move list (what the player “does” at each point), and an int (the goal) and returns the score at the end of the game after processing (some or all of) the moves in the move list in order. Use a locally defined recursive helper function that takes several arguments that together represent the current state of the game. As described above:
• The game starts with the held-cards being the empty list.
• The game ends if there are no more moves. (The player chose to stop since the move list is empty.)
• If the player discards some card c, play continues (i.e., make a recursive call) with the held-cards not having c and the card-list unchanged. If c is not in the held-cards, raise the IllegalMove exception.
• If the player draws and the card-list is (already) empty, the game is over. Else if drawing causes the sum of the held-cards to exceed the goal, the game is over (after drawing). Else play continues with a larger held-cards and a smaller card-list.
Sample solution for (g) is under 25 lines.
Suggestions
• A source file is provided for you to begin with. It defines a variety of datatypes that your response should utilize. The solution to problem A is also provided.
• I suggest that you download and install OCaml on your own computer so that you can more rapidly test as you go. Instructions for installing OCaml on a variety of platforms are available at: http://ocaml.org/docs/install.html. You can then use the OCaml REPL (Read-Eval-Print Loop) to experiment with OCaml and run your program as you are developing.
• I recommend using an editor such as Notepad++ or Sublime Edit to write your source code in and then running the REPL from the command-line
• A good OCaml reference is available at https://realworldocaml.org/.
• When you write your code in a file, you can load that file into the REPL using #use. For example to load the functions in assignment3.ml, you would type
“#use “assignment3.ml”;;
into the REPL.
Submitted: 1 year ago.Category: Programming
Show More
Show Less
10/5/2016
Programmer: Steve, Consultant replied 1 year ago
Steve, Consultant
Category: Programming
Satisfied Customers: 290
Experience: Steve is a consultant in the areas of computer software and programming, information management and networking.
Verified

Hi, my name is Steve.

What language does this have to be programmed in? Can you post the source file you were provided as a head start?

ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7,677
7,677 Satisfied Customers
Experience: MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML

ATLPROG is online now

A new question is answered every 9 seconds

• Ask an ExpertExperts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
• Get a Professional AnswerVia email, text message, or notification as you wait on our site. Ask follow up questions if you need to.

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

## What Customers are Saying:

My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed.

One Happy CustomerNew York

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Mary C.Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

AlexLos Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

GPHesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

JustinKernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

EstherWoodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

RobinElkton, Maryland

< Previous | Next >

## Meet the Experts:

ATLPROG

Computer Software Engineer

7,677 satisfied customers

MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML

LogicPro

Computer Software Engineer

7,109 satisfied customers

Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.

Computer Software Engineer

1,168 satisfied customers

Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.

lifesaver

Computer Software Engineer

950 satisfied customers

Several years of intensive programming and application development experience in various platforms.

ehabtutor

Computer Software Engineer

936 satisfied customers

Bachelor of computer science, 5+ years experience in software development, software company owner

TheDoctor

Software Engineer

893 satisfied customers

M.S. in Internet Information Systems

The-PC-Guy

Software Engineer

789 satisfied customers

Extensive Knowledge in PHP, MYSQL, CSS & Javascript

< Previous | Next >

Related Programming Questions
OKPR923211 Expert in VB code editing? I have a short VB code
OKPR923211 Expert in VB code editing? I have a short VB code that does indenting of source code. I need help in revising it.… read more
Bhavik Joshi
Computer Science and Engineering
589 satisfied customers
A program that considers a class that keeps track of the
a program that considers a class that keeps track of the sales of an item. An object of this class will have the following attributes: •Number sold •Total sales •Total discounts •Cost per item •Bulk q… read more
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I received this error message when creating a program for a
Hello. I received this error message when creating a program for a clock in netbeans. Can you help? … read more
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I need STM32Cube_FW based example source C code to program
I need STM32Cube_FW based example source C code to program STM32F411 MCU as USB HID host to access (communicate with) customized HID device (not keyboard nor mouse)… read more
Kris R
IT Manager
Computing
2,311 satisfied customers
I am programming for years mostly in vbScript having the
I am programming for years mostly in vbScript having the vbScript-Editor, but codes get very long and I seek one Editor, which can have classes on different pages and procedures be closed, that only t… read more
Steve
Consultant
290 satisfied customers
I have an assignment I need done today and I don't have time
I have an assignment I need done today and I don't have time to work on it. Can you help please? … read more
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I have a couple remaining Java codes/modifications, which
Hi George, I have a couple remaining Java codes/modifications, which are detailed in the attached word document. As well, all of the required codes are in the Zip file. Let me know if you are missing … read more
George Sibiya
PhD
194 satisfied customers
Trying to write a java program comparing the salary and
Trying to write a java program comparing the salary and commission of twp sales employees...I have never programmed before … read more
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
I have a legacy program written in VB 6.0 running under
I have a legacy program written in VB 6.0 running under Windows Xp Pro (offline). Last successful update was in 2015. When I try to modif the source code of my program, I can no longer create a new .e… read more
Michael Hannigan
Bachelor\u0027s Program
239 satisfied customers
You wrote a code for me to help me calculate custom pricing
You wrote a code for me to help me calculate custom pricing for products for my business. The little calculator has helped us tremendously. I have adapted the code (I don't know the code itself but ha… read more
The-PC-Guy
Software Engineer
Bachelor's Degree
789 satisfied customers
Sorry for the delay - someone came in. I have developed our
Hi. Sorry for the delay - someone came in. I have developed our business software using dbase PLUS which does not run with Windows 10, so we have been trying to keep our XP machines running. We now ne… read more
Kris R
IT Manager
Computing
2,311 satisfied customers
I have an html 5 video question. I want to add a video to my
Hello, I have an html 5 video question. I want to add a video to my site. I was able to play the video once, then tried to center the layout and managed to mess up my video function. If you're able to… read more
Pete
Engineer
Bachelor\u0027s Degree
1,109 satisfied customers
Assignment 3 Please start with this source code.Write a program that opens the following text file and processes it contents. The program should display the following per store: The total sales for ea… read more
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
To C expert: How to convert my C source code to standard C
To C expert: How to convert my C source code to standard C source code so that it includes only standard C header files? My C source coding includes "CB.h", which is not an ANSI C standard C header fi… read more
Steve
Consultant
290 satisfied customers
ON the new site for my book, I want to include a link near
ON the new site for my book, I want to include a link near the top of every page which will go to a site where they can purchase the book. How do I add that link. … read more
Associate Degree
102 satisfied customers
I'm working in NetBeans 8.2 and re-assembling/referencing a
I'm working in NetBeans 8.2 and re-assembling/referencing a desktop app package sent to me in pieces, the working app and source files. I have references to 8 libraries which are in the original insta… read more
Lorenz Vauck
Computer Expert
Electrical Engineering
71 satisfied customers
Need to create c++ program that read tests files and
Need to create c++ program that read tests files and reformats the input to desired length with desired spaces… read more
LogicPro
Computer Software Engineer
Bachelor of Technology
7,109 satisfied customers
Automate unit tests for the services package using JUnit
Automate unit tests for the services package using JUnit Test each service, AccountService and PurchaseService, in isolation. Inject any stubbed dependencies as necessary. Modify the existing code bas… read more
Bruce Wilner
Master of Engineering
27 satisfied customers
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Show MoreShow Less