Skip to content

Instantly share code, notes, and snippets.

@Raagh
Created April 14, 2020 18:50
Show Gist options
  • Save Raagh/41433431aaac709de1aff0d462dbe51c to your computer and use it in GitHub Desktop.
Save Raagh/41433431aaac709de1aff0d462dbe51c to your computer and use it in GitHub Desktop.
Functional snake game - Part 1
module Core where
type Columns = Int
type Rows = Int
type Point = (Rows, Columns)
type Apple = Point
type Snake = [Point]
type Moves = [Move]
data Move = North | South | West | East deriving (Show)
data State = State {
apple :: Apple,
snake :: Snake,
moves :: Moves
} deriving (Show)
initialSnake :: Snake
initialSnake = [(1,1)]
initialApple :: Apple
initialApple = (5,5)
initialState :: State
initialState = State initialApple initialSnake [North]
move :: State -> Move -> State
move s m = State (apple s) (snake s) [North]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment