/* experiment.c Pea Soup - Pea Experiment CGI by Bill Kendrick bill@newbreedsoftware.com http://www.newbreedsoftware.com/bill/ November 26, 1996 - November 26, 1996 Dominant/Recessive errors fixed (oops!) - March 30, 1999 */ #include #include #include "cgi-util.h" #include "dump.h" #include "randnum.h" void displaypea(int color1, int color2, int shape1, int shape2, int child); int main(int argc, char * argv[]) { int pea, gene, pea2, parent1, parent2; int color[2][2], shape[2][2]; int child_color[4][2], child_shape[4][2]; char temp[50]; cgiinit(); printf("Content-type: text/html\n\n"); if (getentryyesno("begin", 0)) { randinit(); for (pea = 0; pea < 2; pea++) for (gene = 0; gene < 2; gene++) { color[pea][gene] = randnum(2); shape[pea][gene] = randnum(2); } } else { for (pea = 0; pea < 4; pea++) for (gene = 0; gene < 2; gene++) { sprintf(temp, "child_color_%d_%d", pea, gene); child_color[pea][gene] = getentryasint(temp); sprintf(temp, "child_shape_%d_%d", pea, gene); child_shape[pea][gene] = getentryasint(temp); } parent1 = getentryasint("parent1"); parent2 = getentryasint("parent2"); for (gene = 0; gene < 2; gene++) { color[0][gene] = child_color[parent1][gene]; shape[0][gene] = child_shape[parent1][gene]; color[1][gene] = child_color[parent2][gene]; shape[1][gene] = child_shape[parent2][gene]; } } dump("top.html"); printf("
\n"); printf("\n"); /* PARENTS: */ printf("\n"); printf("\n"); printf("\n"); /* CHILDREN: */ printf("\n"); printf("\n"); for (pea = 0; pea < 2; pea++) for (pea2 = 0; pea2 < 2; pea2++) { printf("\n"); } printf("\n"); printf("

PARENTS:


\n"); displaypea(color[0][0], color[0][1], shape[0][0], shape[0][1], -1); printf("\n"); displaypea(color[1][0], color[1][1], shape[1][0], shape[1][1], -1); printf("

CHILDREN:

\n"); displaypea(color[0][pea], color[1][pea2], shape[0][pea], shape[1][pea2], (pea * 2) + pea2); printf("

\n"); printf("

\n"); printf("
\n"); dump("bottom.html"); } void displaypea(int color1, int color2, int shape1, int shape2, int child) { int color, shape; char temp[50]; /* Determine if recessive shows or not for each trait: */ color = 0; if (color1 == 1 && color2 == 1) color = 1; shape = 0; if (shape1 == 1 && shape2 == 1) shape = 1; /* Create name for color and shape of pea to show image: */ if (color == 0) strcpy(temp, "yellow"); else strcpy(temp, "green"); strcat(temp, "-"); if (shape == 0) strcat(temp, "round"); else strcat(temp, "wrinkled"); printf("\"%s\"
\n", temp, temp); /* Show genes: */ if (color1 == 0) printf("Y"); else printf("y"); if (color2 == 0) printf("Y"); else printf("y"); printf("
"); if (shape1 == 0) printf("R"); else printf("r"); if (shape2 == 0) printf("R"); else printf("r"); /* Store values in form: */ if (child != -1) { printf("\n", color1); printf("\n", color2); printf("\n", shape1); printf("\n", shape2); printf("
\n"); printf("
\n", child); printf("
\n", child); } }