Connect Four Overview

Functions to write

This is a minimum set of functions to write:

Advanced functions

When you are done with the minimum set of functions, consider writing functions that make better and better moves.

The last function is the most interesting, but will require doing some outside reading on the minimax algorithm, perhaps looking at an implementation for Connect Four.

Design process

Make a plan before you start writing code! I recommend the top-down design that we discussed last year.

Please have each step of the design process visible for each function. It will speed your work and made it easier to understand!

  1. Purpose for the function
  2. Signature for the function
  3. Example(s) showing how the function will work.
  4. Write the function.
  5. Testing: put the examples for the function called work into a function called test_work.

Technical details

  1. Question: How do you print on more than one line?

    Answer: Put “\n” in your string. For example: “One line\nSecond line”.

    Example:

    drawBoard xs = "__XX\n_OOO"
    main = do putStrLn $ drawBoard [[0,0,1,1],[0,2,2,2]]
  1. Question: What is the difference between ‘X’ and “X”?

    Answer: ‘x’ is a character (Char), and “X” is a String, which is a list of characters.

  2. Question: How do you define a type shortcut?

    Answer: type Board = [[Int]]

  3. Question: How do you define a struct?

    Answer: it will be easier if you do not do this, but Chapter 8 in LYaH has all of the information you need.