(5/5)

Hire Me
(5/5)

Hire Me
(5/5)

Hire Me
(5/5)

Hire Me

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

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:

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.

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

337 Experts Online