forked from fbrusch/lezioni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game_v2.c
76 lines (62 loc) · 1.15 KB
/
Game_v2.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
int vincente(int n)
{
int i;
if (n<3) return 1;
if (n<6) return 0;
for(i=0;i<=n;i++)
if (vincente(i)==0 && vincente(n-i)==0)
return 1;
return 0;
}
int codifica(int numero1, int numero2)
{
return numero1*1000+numero2;
}
int decodifica1(int numero)
{
return numero/1000;
}
int decodifica2(int numero)
{
return numero%1000;
}
int decodifica(int numero, int param)
{
if(param==1)
return numero/1000;
return numero%1000;
}
int p1a(int numero1, int numero2)
{
return numero1;
}
int p1b(int numero)
{
return codifica(numero-3,3);
}
int p2a(int numero1, int numero2)
{
return numero1;
}
int p2b(int numero)
{
return codifica(numero-4,4);
}
int mossa(int numero1, int numero2, int giocatore)
{
int risultato;
if(giocatore==1)
{
risultato = p1a(numero1, numero2);
risultato = p1b(risultato);
}
else
{
risultato = p2a(numero1, numero2);
risultato = p2b(risultato);
}
giocatore=3-giocatore;
if(decodifica1(risultato)<3 || decodifica2(risultato)<3)
return giocatore;
return mossa(decodifica1(risultato), decodifica2(risultato), giocatore);
}