Background

Goals

This project is to reinforce the basic concepts of scheme that you have learned over the last week and a half. You will only need to use what you have learned so far in lab. In addition, you will learn about another large idea in computer science: data abstraction.

Data Abstraction

What is data abstraction? Data abstraction is a way of thinking in computer science that allows programmers to not worry about the direct representation of data within the programs that they are writing. One large component of using data abstraction is the concept of "selectors." Selectors are a way to access parts of the data independent of how the internal representation of the data is actually done. In this project, you'll be using selectors to access parts of your poker hand.

Restrictions

In this project, you are forbidden to use the following: recursion, higher-order-functions, as well as anything else not from the first week and a half of lab. Any previous code that you have written is fair game to use, as well as any code that was in the difference between dates case study.

This project is a solo project. No collaboration between students is allowed and any violation of this will be taken as cheating.

Project Overview

In this project, you will be classifying and comparing poker hands. Since we are limited in our tools, we will be working with 3 card poker hands. The following are the types of hands we will be working with (in order of rank):

• Straight flush: 3 consecutive numbers, all with the same suit
• Flush: 3 cards with the same suit
• Straight: 3 consecutively numbered cards (queen, king, ace is not a straight, nor is king, ace, 2).
• 3-of-a-kind: 3 cards all with the same number
• Pair: 2 cards of the same number
• High card: the highest card in your hand
• More information on poker hands can be found at Wikipedia (follow the rules described here, if there is a difference between Wikipedia and here.)
• .

Card representation: In this project, a hand of 3 cards will be represented by a sentence of 3 words. Each word, representing a card will have a number followed by a suit. We will not use 'a', 'k', 'q', 'j' as in the outranks homework, but the numbers themselves. The suits will be d = diamonds, s = spades, h = hearts, and c = clubs. For example: a hand consisting of "3 of clubs, ace of hearts, jack of clubs" will be represented as (1h 3c 11c). You may assume in this project that all hands are sorted by number. The lowest number will be first and the highest will be the last card. If they are the same number, there is no order of the suits.

Part 1: The first part of the project will be to classify the card hand as defined above. We have given you the skeleton code for the "classify-hand" method. Your job is to define the functions in the skeleton code to make it functional. Inside your definitions, we expect you to USE THE SELECTORS that we have provided for you in the code in order to access the cards/numbers/suits. If not, we will deduct points from the project. You will also find it very annoying if you don't use them.

Part 2: The second part of the project will be to compare two poker hands and return the higher hand. You may use any method you want to do this. However we HIGHLY suggest you use the "classify-hand" method that you wrote in part 1 to do this and then assign each type of hand a value (using a helper function). Hand rankings are defined as above in the project overview, with straight flush being highest. Higher numbers are high (ace is lowest and king is highest), while suit ranking (from lowest to highest) is: diamonds, clubs, hearts, spades. Ties between hand types will be settled accordingly:

• Straight Flush: Higher flush wins, otherwise higher straight wins.
• Flush: Higher suit wins. If same suit, highest number in flush wins.
• Straight: Highest number in straight wins. If same straight, return 'tie' as a word.
• 3 Of a Kind: Higher number wins (it's impossible to get 2 three-of-a-kinds of the same number as there are only 4 of a number in a deck)
• Pair: Higher number wins, if both pairs are of the same number, highest suit wins.
• High card: Highest number wins, if same number, higher suit wins.
Once again, if necessary USE THE SELECTORS in your code.

The framework code can be found here. Do NOT change the framework code or selectors that we have given you.

Sample Calls

The following is a set of sample calls and the outputs you should have. Please adhere to these, as the autograder will be following this.

• (classify-hand '(7c 8c 9c)) -> (straight-flush clubs 7-9)
• (classify-hand '(3c 9c 12c)) -> (flush clubs)
• (classify-hand '(7c 8h 9d)) -> (straight 7-9)
• (classify-hand '(4d 4h 4s)) -> (three-of-a-kind 4)
• (classify-hand '(5s 10h 10c)) -> (pair 10)
• (classify-hand '(3s 9h 13s)) -> (13s)
• (compare-hands '(3s 9h 13s) '(7c 8c 9c)) -> (7c 8c 9c)
• (compare-hands '(4s 5c 6d) '(4c 5s 6h)) -> tie

Due Date

This project is due one week from now, on July 7, 11:59 pm. You have 3 slip days but use them wisely. To submit the project type "submit mp1" from unix. The filename should be called mp1.scm. Include in the file all code. Your testing file will be called poker-hand-tests.scm