<commit_before><<<<<<< HEAD
module World (World, getWorld, buildWorld, getNeighbors, lookupCell) where

import Cell
import Position
=======
module World (World, getWorld, deadWorld, buildWorld, getNeighbors, lookupCell, iterateWorld) where

import Cell
import Game
>>>>>>> iterateWorld

newtype World = W {getWorld :: [[Cell]]}

instance Show World where
  show (W cells) = cells >>= (\row -> show row ++ "\n")
instance Eq World where
  a == b = (getWorld a) == (getWorld b)

buildWorld :: Int -> Int -> [Position] -> World
buildWorld col row liveCells = W [
  [ if mkPosition r c `elem` liveCells then Live else Dead
    | r <- [0..(row-1)]]
    | c <- [0..(col-1)]]

iterateWorld :: World -> World
iterateWorld world =
  let w = (flip fmap) (getWorld world `zip` [(0 :: Int)..]) (\x -> fmap (zipWith (\y -> \z -> ((snd x,y), z)) [(0 :: Int)..]) fst x)
  in W (fmap (fmap (\x -> newState (snd x) (getNeighbors world ((uncurry mkPosition) fst x)))) w)

getNeighbors :: World -> Position -> [Cell]
getNeighbors world position = let
  (row, col) = getPosition position
  neighborPositions = [
                         mkPosition (row + 1) (col + 1)
                        ,mkPosition (row + 1) col
                        ,mkPosition (row + 1) (col - 1)
                        ,mkPosition row (col + 1)
                        ,mkPosition row (col - 1)
                        ,mkPosition (row - 1) (col + 1)
                        ,mkPosition (row - 1) col
                        ,mkPosition (row - 1) (col - 1)
                      ]
  in map (lookupCell world) neighborPositions

lookupCell :: World -> Position -> Cell
lookupCell (W cells) position = let
  (row, col) = getPosition position
  colMax = length $ cells !! 0
  rowMax = length cells
  in cells !! (row `mod` rowMax) !! (col `mod` colMax)<commit_msg>fix broken build from merge<commit_after>module World (World, getWorld, buildWorld, getNeighbors, lookupCell, iterateWorld) where

import Cell
import Position
import Game

newtype World = W {getWorld :: [[Cell]]}

instance Show World where
  show (W cells) = cells >>= (\row -> show row ++ "\n")
instance Eq World where
  a == b = (getWorld a) == (getWorld b)

buildWorld :: Int -> Int -> [Position] -> World
buildWorld col row liveCells = W [
  [ if mkPosition r c `elem` liveCells then Live else Dead
    | r <- [0..(row-1)]]
    | c <- [0..(col-1)]]

iterateWorld :: World -> World
iterateWorld world =
  let w = (flip fmap) (getWorld world `zip` [(0 :: Int)..]) (\x -> fmap (zipWith (\y -> \z -> ((snd x,y), z)) [(0 :: Int)..]) fst x)
  in W (fmap (fmap (\x -> newState (snd x) (getNeighbors world ((uncurry mkPosition) $ fst x)))) w)

getNeighbors :: World -> Position -> [Cell]
getNeighbors world position = let
  (row, col) = getPosition position
  neighborPositions = [
                         mkPosition (row + 1) (col + 1)
                        ,mkPosition (row + 1) col
                        ,mkPosition (row + 1) (col - 1)
                        ,mkPosition row (col + 1)
                        ,mkPosition row (col - 1)
                        ,mkPosition (row - 1) (col + 1)
                        ,mkPosition (row - 1) col
                        ,mkPosition (row - 1) (col - 1)
                      ]
  in map (lookupCell world) neighborPositions

lookupCell :: World -> Position -> Cell
lookupCell (W cells) position = let
  (row, col) = getPosition position
  colMax = length $ cells !! 0
  rowMax = length cells
  in cells !! (row `mod` rowMax) !! (col `mod` colMax)
{'fraction_non_alphanumeric': 0.14375177910617706, 'fraction_numerical': 0.010816965556504412, 'mean_word_length': 2.185856754306437, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '449475', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1066, 'n_words': 395}