2021-10-28

topOfPile and make_move

We discussed topOfPile first. This function gives the y-coordinate (row) that a piece dropped in a particular column will end up in.

topOfPile :: Board -> Int -> Int
topOfPile board col = undefined

Using the example board b pictured below:

Playing in column 1 would result in a piece in row 2. Playing in column 3 would result in a piece in row 0. Playing in column 2 should give a row of 3, even if the board has only three rows - worry about that being an illegal move in a different place.

pileTests = [ 
    topOfPile b 1 == 2
    ,topOfPile b 3 == 0
    ]

Signature:

is_legal_move :: Board -> Int -> Bool

True if the attempted move is legal. Used to prevent people from playing in full columns or off the board (e.g., column -5). The computer uses this information to decide whether

Your legal move function will have to know how large the board is. I recommend making variables that hold this information. The official sizes are:

board_width = 7
board_height = 6

Make Move

Signature:

make_move :: Board -> Int -> Player -> Board

The second input is the column number. Assumes the move is legal. The output is a new board with the move made on it.

Last modified August 18, 2023: 2022-2023 End State (7352e87)