#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int pv();  // Spiel gegen Vater, Gewinnchance 1/3
int pm();  // Spiel gegen Mutter, Gewinnchance 1/2

int pv() {
  double tmp;
  tmp= ((double) rand()) / ((double) RAND_MAX);
  if (tmp<1.0f/3) return 1;
  else return 0;
}

int pm() {
  double tmp;
  tmp= ((double) rand()) / ((double) RAND_MAX);
  if (tmp<1.0f/2) return 1;
  else return 0;
}

int main(void) {
unsigned long i;
unsigned long N=1000000;
unsigned long count=0;
int s1,s2,s3;
double tmp1, tmp2;

srand(clock());
for (i=1; i<N; i++) {
  s1=pv(); s2=pm(); s3=pv();
  if (s1==1 && s2==1 || s2==1 && s3==1) count++; 
  }
printf(  "Simulation von 1 Mio Vater-Mutter-Vater-Spielen\n\nGewinnchance       = %f", tmp1=(double)count/(double)N); 
printf("\nTheoretischer Wert = %f", tmp2=1.0f/3 * 0.5 * (2-1.0f/3));  
printf("\nAbweichung         = %f %", (tmp1/tmp2-1)*100);  
return 0;	
}
		