EECS 111 Project

Language: Intermediate Student with lambda
Due: 11:59 PM Friday, Mar. 18

Your goal is to implement a variation of the game Snake.

In this game, you control a snake that wanders around a square board, eating food. Each time the snake eats a morsel of food, it gets a little bit longer. If the snake ever runs into itself or runs into the edge of the board, the game is over. The snake never stops moving; the player can control only the direction that the snake moves.

To begin, save the files snake-lib.rkt and provide.rkt in the folder where you will save the the code you write. Start your code with the line
  (require "snake-lib.rkt")

For this project, we will use the following data definitions.
  ; a game is
  ; (make-game snake food nat)
  ; (define-struct game (snake food ticks))
  
  ; a direction is either
  ; - 'up
  ; - 'down
  ; - 'left
  ; - 'right
  
  ; a snake is
  ; (make-snake direction body)
  ; (define-struct snake (heading segments))
  
  ; a body is either
  ; - (cons posn empty)
  ; - (cons posn body)
  ; x-coordinates increase from 1 to 50 (inclusive) toward the right
  ; y-coordinates increase from 1 to 50 (inclusive) toward the top
  
  ; a food is either
  ; - empty
  ; - (cons posn food)
Do not uncomment the define-struct lines; those structure definitions are included via the require line (they’re listed above just for reference).

This require line also provides two other definitions:
  • board-length, the length of one side of the board (measured in terms of snake body segments), and

  • play-game, a function described below.

Develop the following functions (and any necessary helper functions), which will serve as argument to the play-game function:

After you have written and thoroughly tested these functions, define an initial game value game-start and make the following call to play the game.
  (play-game game-start
             advance-game
             add-food
             change-direction
             game-score
             game-over?)