return;
}
}
}
public int check (int i, int alpha, int beta)
{
int co, score, t, g, j = 0, p;
i – ;
if (i == -1) {score = position (); return score;}
if (i % 2 == 0)
{
int max = 0, k;
j = 0; co = 0;
for (t = 0; t <7; t++)
{
g = add (t, cpu);
if (g == 0)
{
if (checkwin () == cpu)
{
sub (t);
if (i == rec – 1)
return t;
else return 9000;
}
k = check (i, alpha, 999999);
if (k> alpha) alpha = k;
sub (t);
if (k> beta) return k;
if (co == 0) {max = k; co = 1; j = t;}
if (k == max)
{
p = (random.Next (6)) +1;
if (p> 4) j = t;
}
if (k> max) {max = k; j = t;}
}
}
score = max;
}
else
{
int min = 0, k = 0;
co = 0;
for (t = 0; t <7; t++)
{
g = add (t, plr);
if (g == 0)
{
if (checkwin () == plr)
{
sub (t);
/*if (i==rec-1) return t; else*/
return -10000;
}
k = check (i, -99999, beta);
if (k <beta) beta = k;
sub (t);
if (k <alpha) return k;
if (co == 0) {min = k; co = 1; j = t;}
if (k <min) {min = k; j = t;}
}
}
score = min;
}
if (i == rec – 1) return j;
return score;
}
public int add (int c, int coin)
{
if (tops [c] <6)
{
arr [c, tops [c]] = coin;
tops [c] ++; return 0;
}
return 1;
}
public int sub (int c)
{
tops [c] – ;
arr [c, tops [c]] = 0;
return 0;
}
public int position ()
{
int u, o, x, y, j, score;
int gh = 0, hg = 0;
score = 0;
//Empty the think array
for (x = 0; x <7; x++)
{
for (y = 0; y <6; y++)
{
thn [x, y] = 0;
}
}
//Sum the score of every opportunity to the score
for (y = 0; y <6; y++)
{
for (x = 0; x <7; x++)
{
if (arr [x, y] == 0)
score = score + checkhole (x, y);
if (y> 0)
{
if ((thn [x, y] == cpu) &&
(arr [x, y – 1]!= 0)) gh++;
if ((thn [x, y] == plr) &&
(arr [x, y – 1]!= 0))
{hg++; score = score – 4000;}
}
else
{
if (thn [x, y] == cpu) gh++;
if (thn [x, y] == plr)
{hg++; score = score – 4000;}
}
}
}
if (gh> 1) score = score + (gh – 1) * 500;
if (gh == 1) score = score – 100;
if (hg> 1) score = score – (hg – 1) * 500;
for (x = 0; x <7; x++)
{
gh = 0;
for (y = 1; y <6; y++)
{
/*if (gh==0)
if ((thn [x,y]> 0) && (arr [x,y-1] ==0)) {
gh=1;
} */
if ((thn [x, y] == cpu) &&
(thn [x, y – 1] == cpu))
{
u = 0; j = 0;
for (o = y – 1; o> -1; o – )
{
if (thn [x, o] == plr) u = 1;
if (arr [x, o] == 0) j++;
}
if (u == 0) score = score +1300 – j * 7;
if (u == 1) score = score +300;
}
if ((thn [x, y] == plr) &&
(thn [x, y – 1] == plr))
{
u = 0; j = 0;
for (o = y – 1; o> -1; o – )
{
if (thn [x, o] == cpu) u = 1;
if (arr [x, o] == 0) j++;
}
if (u == 0) score = score – 1500 + j * 7;
if (u == 1) score = score – 300;
}
if (thn [x, y] == plr)
{
u = 0;
for (o = y – 1; o> -1; o – )
{
if (thn [x, o] == cpu) u = 1;
}
if