logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

In this lab, you will a program for playing Blackjack with a single player and dealer. You may want to refresh on the basic rules of the game

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

GamblersAnonymous

Overview

In this lab, you will  a program for playing Blackjack with a single player and dealer. (You may want to refresh on the basic rules of the game.) I have given you a starting point in the Clojure/cards/src/cards.core folder of the course notes repository; you will nish the program according to my speci cation, then report

on the results of simulating many games with particular strategies of play.

Starter Code

You should begin by examining the starter code I have provided. Here are some highlights. I have starred (*) the functions that have a TODO note in the source code, representing something that you must write or change:

As in the Immutability lecture, our blackjack game will involve functions that translate from one game state to the next. We need several types to represent the state of a blackjack game:

   a   card   type that encapsulates an integer for the card's   kind , where a 1 is an Ace, 11 is Jack,      12 is Queen, and 13 is King; as well as a suit , an integer where 0 is Spades , 1 is Clubs , 2 is

 Diamonds , 3 is Hearts .

   a game state type that tracks the current state of the game,  including the  deck  of cards to  draw from (a list of card objects) , the player's current hand (also a list of cards), and the dealer's current hand (also a list of cards).

   A utility  game log  type that we'll use to track how many wins are achieved by  the player or   dealer over a set of many games.

•    Several utility functions make the remaining code easier:

   *card-str: given a card object, returns a nice string representation of the card, in the format X of Y , where X is the Kind and Y is the Suit, e.g., King of Spades .

   card-value: calculates the number of points a card is worth in blackjack. An Ace is worth 1, Jack/Queen/King are worth 10, and all other cards are worth their Kind.

   *hand-total: given a list of card objects, calculates the number of points the entire hand is worth, by summing the card value of each card in the hand. If that total exceeds 21, and the card has at least one Ace, then some of the Aces are reduced to 1 point each until the total goes below 21 (if possible).

•    Functions to create and update the game state:

   make-deck: creates a new list of of 52 unshu ed card objects.

   new-game: creates a new game state by shu ing a new deck and dealing two cards to the player and to the dealer (in alternating order).

   *hit: given a game state and either :player or :dealer, returns a new game state after removing one card from the game state's deck and adding it to the hand of the person indicated.

•    Functions for running the game:

   *dealer-turn: given the current game state, takes the dealer's turn by recursively deciding hit  or stay until the dealer busts (goes over 21 points) or stays. Dealers always follow a mandatory algorithm: hit if the dealer's total is less than 17, otherwise stay

   *player-turn: given the current game state and a function called a strategy, takes the player's turn by recursively deciding hit or stay until the player busts or stays. Unlike dealers, players get to make their own decisions on whether to hit; this ability is represented by the parameter player-strategy, which is a function of type game state -> bool . The strategy function is responsible for deciding whether to hit given the current game state. By passing a strategy as a parameter, we will be able to play games automatically following an algorithm that we think might be good at blackjack, and then evaluate the results later vs. other strategies.

   *one-game: given an initial game state and a player strategy, runs one full game using the given player strategy. First the player takes their turn, then the dealer. A game log obeject re ecting the outcome of the game is returned.

   *many-games: recursively plays n games using the given player strategy.  In each iteration of  the recursion, a new game is constructed and passed to one-game. The result of that game is accumulated across the recursion, and in the end a cumulative game log object is returned.

•    Functions for player strategies (detailed next). Player strategies:

player-turn takes a function called a strategy to determine whether the player should hit or stay given the current game state. We will develop several strategies and evaluate them over many games to determine which are superior. Each strategy is a function that takes a game state parameter and returns true if the player should hit, and false otherwise. I have given one strategy already, the interactive-player-strategy, which allows the user to make this decision by typing y into he console to hit. (This might not work if you use repl.it.)

You must write the following other strategy functions:

•    *inactive-player-strategy: this player never hits.

•    *greedy-player-strategy: a greedy player hits unless their total is 21 or higher.

*coin-flip-player-strategy: this player ips a coin each time they need to make a decision about whether to hit. If the coin is heads, they hit. There is a function rand-int that you can use to generate random integers by calling (rand-int i), which returns an integer from 0 to i, excluding i. Do not construct your own random number generator.

•    *basic-player-strategy: a strategy recommended for beginners, based on conditional decisions:

   If the dealer's rst card is a 2 through 6:

∗    Stay if your total is 12 or greater

∗    Hit otherwise

   If the dealer's rst card is 7 through King:

∗    Hit if your total is 16 or less

   If the dealer's rst card is Ace:

∗    Hit if your total is 16 or less, if you have at least one Ace

∗    Otherwise, hit if your total is 11 or less;

∗    Otherwise stay.

Evaluating Strategies

The ultimate goal of this lab is to evaluate the e ectiveness of the four player strategies. To do so, you will write a main for your program that calls many-games to run 1000 games on each of the four strategies. Print the game log for each result; you will turn in that output as part of the lab Deliverables.

Include this strategy in the analysis required by the Deliverables.

Deliverables

Turn in the following when the lab is due:

1.    A printed copy of your code, printed from your IDE when  possible.  If you cannot print from  your editor, copy your code into Notepad or another program with a xed-width (monospace) font and print from there.

2.    The results of running each of the required player strategies (excluding the interactivePlayerStrategy) for 1000 games of blackjack. Capture the output of your program which should look something like

{:player-wins 100, :dealer-wins 500, :draws = 400} (but with di erent numbers and maybe a di erent order) and label it according to which strategy it corresponds to.

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Atharva PatilComputer science

541 Answers

Hire Me
expert
Chrisantus MakokhaComputer science

865 Answers

Hire Me
expert
AyooluwaEducation

705 Answers

Hire Me
expert
RIZWANAMathematics

663 Answers

Hire Me

Get Free Quote!

414 Experts Online