Project 2 for MA132
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.4 KiB

// Timing
#include <math.h>
/*
Timing of months in years
Month Days Days (Cumulative)
0 * trough = 0, assumed
Jan 31 31
Feb 28 59
Mar 31 90
Apr 30 120
May 31 151
Jun 30 181
Jul 31 212 * peak = 212, assumed
Aug 31 243
Sep 30 273
Oct 31 304
Nov 30 334
Dec 31 365 * trough again
*/
#define YEAR_DAYS 365
#define MATING_PROB_ULIMIT 0.2
#define MATING_PROB_LLIMIT 0.0
#define MATING_TIME_PEAK 212
#define DEATH_PROB_LLIMIT 0.1
#define DEATH_PROB_ULIMIT 0.5
#define DEATH_TIME_TROUGH 212
double mating_chance(int day)
{
int doy = day % 365;
return (doy % 365) < MATING_TIME_PEAK?
MATING_PROB_LLIMIT + 0.5 * (MATING_PROB_ULIMIT - MATING_PROB_LLIMIT) * (2 - cos(doy / MATING_TIME_PEAK * M_PI)):
MATING_PROB_LLIMIT + 0.5 * (MATING_PROB_ULIMIT - MATING_PROB_LLIMIT) * ((doy - MATING_TIME_PEAK) / (YEAR_DAYS - MATING_TIME_PEAK) * M_PI);
}
double death_chance(int day)
{
int doy = day % 365;
return (doy % 365) < DEATH_TIME_TROUGH?
DEATH_PROB_ULIMIT + 0.5 * (DEATH_PROB_LLIMIT - DEATH_PROB_ULIMIT) * (2 - cos(doy / DEATH_TIME_TROUGH * M_PI)):
DEATH_PROB_ULIMIT + 0.5 * (DEATH_PROB_LLIMIT - DEATH_PROB_ULIMIT) * ((doy - DEATH_TIME_TROUGH) / (YEAR_DAYS - DEATH_TIME_TROUGH) * M_PI);
}