Introduction to Functional Programming – Lab 2: "BlackJack"TDA555 / DIT440, LP1, HT2013
Home | Schedule | Labs | Exercises | Exam | AboutFire | Forum | TimeEdit | Links | 2012
Some notes:

  • Remember that you have to work in pairs. Only groups of size 2 are allowed to submit! Submissions by only 1 person or 3 or more persons will not be accepted by the Fire system.

  • When you are done, please submit your solution using the Fire system.
  • Good luck!


    In this lab assignment, you will implement a Haskell program for playing BlackJack.

    Two Parts

    The lab assignment is divided up into 2 parts. The description of the full lab assignment is here: Lab 2 (BlackJack) (PDF document). The full Task is described in Section 3 of the document.

    The separate parts of this lab assignment are:

    Part I: Task 1 (reading the document), Task 2 (writing out what happens to the size function), and parts of Task 3 (implement the functions "empty", "value", "gameOver", and "winner").

    The tasks are found in the beginning of section 3 of the PDF.

    Part II: Consists of the rest of the document describing the lab assignment.

    Extra: Some extra assignments are mentioned in Section 4 of the document. These are not obligatory, but you will learn more when you do them!

    Hints

    A general hint for Part I: It is a good idea to make two definitions:

      aCard1 :: Card
      aCard1 = ... -- define your favorite card here
    
      aCard2 :: Card
      aCard2 = ... -- define another card here
    
    So that you can use these cards to test your functions. Then, make a definition:
      aHand :: Hand
      aHand = ... -- a Hand with two Cards, aCard1 and aCard2
    
    Again, aHand can be used to test your functions that work on hands.

    A hint for writing the value function in Part I: Start with writing a function valueRank :: Rank -> Integer, that calculates the value of a Rank (think about what to do for an Ace!), and perhaps also a function valueCard :: Card -> Integer, that calculates the value of a Card. Furthermore, it is a good idea to define and use a function numberOfAces :: Hand -> Integer, that calculates the number of aces in a given hand. Write these three functions first before you start defining the function value.

    Files

    You need the following files:

  • Cards.hs

  • Wrapper.hs
  • Deadlines

    This lab assignment has 3 deadlines.

  • First deadline (Monday, Sept. 16 at 9:00): You need to have made a serious effort on completing Part I as stated above.

  • Second deadline (Monday, Sept. 23 at 9:00): You need to have made a serious effort on completing the complete lab assignment.

  • Final deadline (Wednesday, October 2 at 9:00): You need to have gotten a pass on the lab.

  • Submission

    The exact instructions on what to submit are stated in the document above.

    Write your answers in one file, called BlackJack.hs. For each assignment, use Haskell comments to indicate what part of the file contains the answer to the assignment. For answers in natural language, you can use Swedish or English; write your answers also in Haskell comments. Remove irrelevant things from the file.

    Before you submit your code, Clean It Up! Remember, submitting clean code is Really Important, and simply the polite thing to do. After you feel you are done, spend some time on cleaning your code; make it simpler, remove unneccessary things, etc. We will reject your solution if it is not clean. Clean code:

  • Does not have long lines (< 78 characters)

  • Has a consistent layout (do not use TAB characters in your code)

  • Has type signatures for all top-level functions

  • Has good comments

  • Has no junk (junk is unused code, commented code, unneccessary comments)

  • Has no overly complicated function definitions

  • Does not contain any repetitive code (copy-and-paste programming)
  • Please do not submit the modules Cards.hs and Wrapper.hs (unless an extra assignment required you to make changes to them).

    When you are done, please submit it using the Fire system.

    Good luck!