Skip to content

Instantly share code, notes, and snippets.

@adammw
Created May 2, 2015 02:48
Show Gist options
  • Save adammw/e7da9e95a46012c118de to your computer and use it in GitHub Desktop.
Save adammw/e7da9e95a46012c118de to your computer and use it in GitHub Desktop.
public int GameOver(int f, int value[])
{
int comp = board[f];
int rival;
int i;
int u, d, l, r, ul, ur, dl, dr;
int cnt0, cnt1, cnt2, cnt3;
int cnt0b, cnt1b, cnt2b, cnt3b;
int f0a, f0b, f1a, f1b, f2a, f2b, f3a, f3b;
int f0c, f0d, f1c, f1d, f2c, f2d, f3c, f3d;
int tmp;
cnt0 = cnt1 = cnt2 = cnt3 = 1;
cnt0b = cnt1b = cnt2b = cnt3b = 0;
u = d = l = r = ul = ur = dl = dr = f;
f0a = f0b = f0c = f0d = f1a = f1b = f1c = f1d = f2a = f2b = f2c = f2d = f3a = f3b = f3c = f3d = 1;
if(comp!=EMPTY && comp!=BORDER) // 2
{
rival = board[f] == HUMAN ? COMP : HUMAN;; // 4a ? 4b : 4c
for(i=1 ; i<4 ; i++) // 5
{
// horizontal
if(f0c!=0) //6
{
if((tmp = board[++r]) != BORDER) // 8
if(f0a!=0) // 10
if(tmp==comp) { // 11
cnt0++; // 12
}
else
{
f0a = 0; //13
if(tmp==EMPTY) cnt0b++; //15
else f0c = 0; //16
}
else
if(tmp!=rival) cnt0b++; // 18
else f0c = 0; // 19
else
f0c = 0; // 9
}
if(f0d!=0) // 7
{
if((tmp = board[--l]) != BORDER) // 21
if(f0b!=0) // 22
if(tmp==comp) { // 23
cnt0++; // 24
}
else
{
f0b = 0; // 25
if(tmp==EMPTY) cnt0b++; // 26, 27
else f0d = 0; // 28
}
else
if(tmp!=rival) cnt0b++;
else f0d = 0;
else // 23
f0d = 0;
}
// links unten -> rechts oben
if(f1c!=0) // 20
{
if((tmp = board[ur+=14]) != BORDER)
if(f1a!=0)
if(tmp==comp) cnt1++;
else
{
f1a = 0;
if(tmp==EMPTY) cnt1b++;
else f1c = 0;
}
else
if(tmp!=rival) cnt1b++;
else f1c = 0;
else
f1c = 0;
}
if(f1d!=0)
{
if((tmp = board[dl-=14]) != BORDER)
if(f1b!=0)
if(tmp==comp) cnt1++;
else
{
f1b = 0;
if(tmp==EMPTY) cnt1b++;
else f1d = 0;
}
else
if(tmp!=rival) cnt1b++;
else f1d = 0;
else
f1d = 0;
}
// links oben -> rechts unten
if(f2c!=0)
{
if((tmp = board[ul+=12]) != BORDER)
if(f2a!=0)
if(tmp==comp) cnt2++;
else
{
f2a = 0;
if(tmp==EMPTY) cnt2b++;
else f2c = 0;
}
else
if(tmp!=rival) cnt2b++;
else f2c = 0;
else
f2c = 0;
}
if(f2d!=0)
{
if((tmp = board[dr-=12]) != BORDER)
if(f2b!=0)
if(tmp==comp) cnt2++;
else
{
f2b = 0;
if(tmp==EMPTY) cnt2b++;
else f2d = 0;
}
else
if(tmp!=rival) cnt2b++;
else f2d = 0;
else
f2d = 0;
}
// vertikal
if(f3c!=0)
{
if((tmp = board[u+=13]) != BORDER)
if(f3a!=0)
if(tmp==comp) cnt3++;
else
{
f3a = 0;
if(tmp==EMPTY) cnt3b++;
else f3c = 0;
}
else
if(tmp!=rival) cnt3b++;
else f3c = 0;
else
f3c = 0;
}
if(f3d!=0)
{
if((tmp = board[d-=13]) != BORDER)
if(f3b!=0)
if(tmp==comp) cnt3++;
else
{
f3b = 0;
if(tmp==EMPTY) cnt3b++;
else f3d = 0;
}
else
if(tmp!=rival) cnt3b++;
else f3d = 0;
else
f3d = 0;
}
}
// Wertigkeit des Zuges bestimmen
value[0] = 0;
if((cnt0b + cnt0)>3)
value[0] = (cnt0-1)*6 + cnt0b;
if((cnt1b + cnt1)>3)
value[0] += (cnt1-1)*6 + cnt1b;
if((cnt2b + cnt2)>3)
value[0] += (cnt2-1)*6 + cnt2b;
if((cnt3b + cnt3)>3)
value[0] += (cnt3-1)*6 + cnt3b;
if(cnt0>3 || cnt1>3 ||cnt2>3 ||cnt3>3)
return ONE_HAS_WON;
for(i=3 ; i<10 ; i++)
if(field[i]<156)
return GAME_NOT_OVER;
return BOARD_FULL;
}
return GAME_NOT_OVER;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment