forked from stengel/ecta2002
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprior.c
97 lines (88 loc) · 2.25 KB
/
prior.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* prior.c
* 12 July 2000
* prior generation
*/
#include <stdio.h>
/* printf, sprintf */
#include <stdlib.h>
/* rand(), RAND_MAX */
#include <math.h>
/* floor() */
#include <limits.h>
/* INT_MAX, INT_MIN */
#include "prior.h"
#include "rat.h"
#include "rataux.h" /* contfract() */
#include "treedef.h"
#include "sfnf.h"
/* realplan[PLAYERS], behavtorealplan() */
#include "seqform.h"
/* outbehavstrat */
/* generate the prior, stored in moves[]->behavprob,
* where each move has equal probability
*/
static void gencentroid(void)
{
Move c;
int pl;
for (pl=1; pl < PLAYERS; pl++)
for (c = firstmove[pl]+1; c < firstmove [pl+1]; c++)
{
c->behavprob.num = 1;
c->behavprob.den = c->atiset->nmoves;
}
}
void genprior(Flagsprior flags)
{
int pl;
Iset h;
if (0 == flags.seed)
{
gencentroid();
return ;
}
/* generate random priors for all information sets */
srand(FIRSTPRIORSEED + flags.seed);
for (pl=1; pl < PLAYERS; pl++)
for (h = firstiset[pl]; h < firstiset [pl+1]; h++)
if ( h->nmoves > 2)
{
fprintf(stderr, "Sorry, only binary info sets so far.\n") ;
exit(1) ;
}
else
{
Rat a;
double x;
x = rand() / (double) RAND_MAX;
a = contfract( x, flags.accuracy) ;
/* make sure to get a properly mixed prior,
* unless flags.accuracy == 1,
* in which case we have a random pure strategy
* because this statement flips 0 to 1 and vice versa
*/
if (a.num == 0)
{
a.num = 1 ;
a.den = flags.accuracy;
}
else if (a.den == 1) /* "else" for pure strategy */
{
a.num = flags.accuracy - 1 ;
a.den = flags.accuracy;
}
h->move0->behavprob = a ;
((h->move0)+1)->behavprob = ratadd(ratfromi(1), ratneg(a)) ;
}
}
void outprior(void)
{
int pl;
printf("------Prior behavior strategies player 1, 2:\n");
for ( pl = 1; pl < PLAYERS; pl++ )
{
behavtorealprob(pl) ;
realplanfromprob(pl, realplan[pl]);
outbehavstrat(pl, realplan[pl], 1);
}
}