Created
October 13, 2014 20:41
-
-
Save lmarburger/b11987f8dfc93c064ba5 to your computer and use it in GitHub Desktop.
Game of Life in Idris
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GoL | |
%default total | |
data Cell = Alive | Dead | |
Board : Type | |
Board = Vect 3 (Vect 3 Cell) | |
nextCellState : Cell -> Nat -> Cell | |
nextCellState Alive (S (S Z)) = Alive | |
nextCellState _ (S (S (S Z))) = Alive | |
nextCellState _ _ = Dead | |
nextBoardState : Board -> Board | |
nextBoardState b = b | |
-- 0,0 : 0,1 | |
-- 1,0 1,1 | |
-- | |
-- 1,0 : 0,0 2,0 | |
-- 0,1 1,1 2,1 | |
-- | |
-- 0,1 : 0,0 1,0 | |
-- 1,1 | |
-- 0,2 1,2 | |
-- | |
-- 1,1 : 0,0 1,0 2,0 | |
-- 0,1 2,1 | |
-- 0,2 1,2 2,2 | |
proximateNeighbors : Nat -> Nat -> List (Nat, Nat) | |
proximateNeighbors Z Z = [ (1, 0), | |
(1, 0), (1, 1)] | |
proximateNeighbors (S x) Z = [(x , 0 ), (x + 2, 0 ), | |
(x , 1 ), (x + 1, 1 ), (x + 2, 1)] | |
proximateNeighbors Z (S y) = [(0 , y ), (1 , y ), | |
(1 , y + 1), | |
(0 , y + 2), (1 , y + 2)] | |
proximateNeighbors (S x) (S y) = [(x , y ), (x + 1, y ), (x + 2, y ), | |
(x , y + 1), (x + 2, y + 1), | |
(x , y + 2), (x + 1, y + 2), (x + 2, y + 2)] | |
myBoard : Board | |
myBoard = [[Dead, Alive, Dead], | |
[Dead, Alive, Dead], | |
[Dead, Alive, Dead]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment