runPopulation :: (Int, Population, [Float]) -> Int -> Socket -> IO b
runPopulation (gInnov,p0,gen) n sock = do
  let genomes = concatMap (\(_,_,_,_,gs) -> gs) p0
  genomes' <- run genomes sock
  let p1 = replaceGenomes p0 genomes'
  savePopulation ("./data/" ++ show n ++ ".bin") p1
  let (gInnov',p2,gen') = stepNetwork p0 (gInnov,p1,gen) marioConfig
  savePopulation ("./data/" ++ show (n+1) ++ ".bin") p2
  joydata <- recordMario (fittestGenome p1)
  saveAsFM2 ("./data/" ++ show n ++ ".fm2") joydata
  runPopulation (gInnov',p2,gen') (n+1) sock
runPopulation :: (Int, Population, [Float]) -> Int -> Socket -> IO b
runPopulation (gInnov,p0,gen) n sock = do
  let genomes = concatMap (\(_,_,_,_,gs) -> gs) p0
  genomes' <- run genomes sock
  let p1 = replaceGenomes p0 genomes'
  savePopulation ("./data/" ++ show n ++ ".bin") p1
  let (gInnov',p2,gen') = stepNetwork p0 (gInnov,p1,gen) marioConfig
  savePopulation ("./data/" ++ show (n+1) ++ ".bin") p2
  joydata <- recordMario (fittestGenome p1)
  saveAsFM2 ("./data/" ++ show n ++ ".fm2") joydata
  runPopulation (gInnov',p2,gen') (n+1) sock
runPopulation (gInnov,p0,gen) n sock = do
  let genomes = concatMap (\(_,_,_,_,gs) -> gs) p0
  genomes' <- run genomes sock
  let p1 = replaceGenomes p0 genomes'
  savePopulation ("./data/" ++ show n ++ ".bin") p1
  let (gInnov',p2,gen') = stepNetwork p0 (gInnov,p1,gen) marioConfig
  savePopulation ("./data/" ++ show (n+1) ++ ".bin") p2
  joydata <- recordMario (fittestGenome p1)
  saveAsFM2 ("./data/" ++ show n ++ ".fm2") joydata
  runPopulation (gInnov',p2,gen') (n+1) sock