Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

129 lines (129 sloc) 10.048 kB
//Created by Petros Demetrakopoulos aka PSD
#include "stdio.h"
int main(int argc, char const *argv[])
{
int gamePlay[7][7] = {{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0}};
for (int row = 2; row < 5; ++row)
{
for (int column = 2; column < 5; ++column)
{
int crnPos = gamePlay[row][column];
if (crnPos == 0)
{
//first rule
if ((gamePlay[row+1][column] == 1 && gamePlay[row+2][column]==1) || (gamePlay[row][column+1] == 1 && gamePlay[row][column+2] == 1) ||
(gamePlay[row+1][column+1] == 1 && gamePlay[row+2][column+2] == 1) || (gamePlay[row-1][column] == 1 && gamePlay[row+1][column] == 1)
|| (gamePlay[row][column-1] == 1 && gamePlay[row][column+1] == 1) || (gamePlay[row-1][column] == 1 && gamePlay[row-2][column] == 1) || (gamePlay[row-1][column+1] == 1 && gamePlay[row-2][column+2] == 1)
|| (gamePlay[row][column-1] == 1 && gamePlay[row][column-2] == 1) || (gamePlay[row-1][column-1] == 1 && gamePlay[row+1][column+1] == 1) || (gamePlay[row-1][column-1] == 1 && gamePlay[row-2][column-2] == 1)
|| (gamePlay[row+1][column-1] == 1 && gamePlay[row+2][column-2] == 1))
{
gamePlay[row][column] = 1;
break;
}
//second rule
else if ((gamePlay[row+1][column] == -1 && gamePlay[row+2][column]== -1 && gamePlay[row+1][column+1] != -1 && gamePlay[row+2][column+1] != -1) ||
(gamePlay[row][column+1] == -1 && gamePlay[row][column+2] == -1 && gamePlay[row+1][column] !=0) ||
(gamePlay[row+1][column+1] == -1 && gamePlay[row+2][column+2] == -1) ||
(gamePlay[row-1][column] == -1 && gamePlay[row+1][column] == -1 && gamePlay[row][column+1] != -1 && gamePlay[row-1][column+1] != -1) ||
(gamePlay[row][column-1] == -1 && gamePlay[row][column+1] == -1 && gamePlay[row+1][column] !=0 && gamePlay[row+1][column-1] !=0 && gamePlay[row][column+1] !=0) ||
(gamePlay[row-1][column] == -1 && gamePlay[row-2][column] == -1 ) ||
(gamePlay[row-1][column+1] == -1 && gamePlay[row-2][column+2] == -1) ||
(gamePlay[row][column-1] == -1 && gamePlay[row][column-2] == -1 && gamePlay[row+1][column] != 0) ||
(gamePlay[row-1][column-1] == -1 && gamePlay[row+1][column+1] == -1) ||
(gamePlay[row-1][column-1] == -1 && gamePlay[row-2][column-2] == -1) ||
(gamePlay[row][column-1] == -1 && gamePlay[row][column+1] == -1))
{
gamePlay[row][column] = 1;
break;
}
//third rule
else if (((gamePlay[row][column+2] == 1 && gamePlay[row+1][column+1] == 1 && gamePlay[row+2][column] !=0 && gamePlay[row+2][column+1] !=0) ||
(gamePlay[row-1][column-1] == 1 && gamePlay[row-1][column+1] == 1) ||
(gamePlay[row][column-2] == 1 && gamePlay[row+1][column-1] == 1 && gamePlay[row+2][column] !=0 && gamePlay[row+2][column] != -1 && gamePlay[row+2][column-2] !=1) )||
((gamePlay[row+1][column-1] == 1 && gamePlay[row+1][column+1] == 1) ||
(gamePlay[row-1][column+1] == 1 && gamePlay[row][column+2] == 1) ||
(gamePlay[row][column-2] == 1 && gamePlay[row-1][column-1] == 1)) ||
((gamePlay[row+1][column+1] == 1 && gamePlay[row+2][column] == 1 && gamePlay[row][column+2] !=0 && gamePlay[row+1][column+2] != 0) ||
(gamePlay[row-1][column-1] == 1 && gamePlay[row+1][column-1] == 1) ||
(gamePlay[row-1][column+1] == 1 && gamePlay[row-2][column] == 1)) ||
((gamePlay[row-1][column+1] == 1 && gamePlay[row+1][column+1] == 1) ||
(gamePlay[row+1][column-1] == 1 && gamePlay[row+2][column] == 1 && gamePlay[row+1][column-2] != 0 && gamePlay[row][column-2] == -1 && gamePlay[row+2][column-2] == -1 && gamePlay[row+1][column] != 0) ||
(gamePlay[row-1][column-1] == 1 && gamePlay[row-2][column] == 1)) ||
((gamePlay[row][column+2] == 1 && gamePlay[row+2][column] == 1) ||
(gamePlay[row][column-2] == 1 && gamePlay[row+2][column-2] == 1) ||
(gamePlay[row-2][column] == 1 && gamePlay[row-2][column+2] == 1)) ||
((gamePlay[row][column+2] == 1 && gamePlay[row+2][column+2] == 1) ||
(gamePlay[row][column-2] == 1 && gamePlay[row+2][column] == 1) ||
(gamePlay[row-2][column] == 1 && gamePlay[row-2][column-2] == 1)) ||
((gamePlay[row+2][column] == 1 && gamePlay[row+2][column-2] == 1) ||
(gamePlay[row-2][column] == 1 && gamePlay[row][column-2] == 1) ||
(gamePlay[row][column+2] == 1 && gamePlay[row-2][column] == 1)) ||
((gamePlay[row+2][column] == 1 && gamePlay[row+2][column+2] == 1) ||
(gamePlay[row][column+2] == 1 && gamePlay[row-2][column] == 1) ||
(gamePlay[row][column-2] == 1 && gamePlay[row-2][column-2] == 1)))
{
gamePlay[row][column] = 1;
break;
}
//fourth rule
else if ((gamePlay[row+2][column] == -1 && gamePlay[row+2][column+2] == -1 && gamePlay[row+2][column+1] !=0) ||
(gamePlay[row+2][column] == -1 && gamePlay[row+2][column-2] == -1 && gamePlay[row+2][column-1] !=0) ||
(gamePlay[row-2][column] == -1 && gamePlay[row][column-2] == -1) ||
(gamePlay[row-2][column] == -1 && gamePlay[row-2][column+2] == -1 && gamePlay[row][column+1] !=0) ||
(gamePlay[row-2][column+2] == -1 && gamePlay[row][column+2] == -1) ||
(gamePlay[row][column+2] == -1 && gamePlay[row+2][column] == -1) ||
(gamePlay[row][column-2] == -1 && gamePlay[row+2][column] == -1) ||
(gamePlay[row+2][column-2] == -1 && gamePlay[row+2][column] == -1 && gamePlay[row+2][column-1] != 0) ||
(gamePlay[row][column-2] == -1 && gamePlay[row-2][column-2] == -1) ||
(gamePlay[row+1][column-1] == -1 && gamePlay[row+2][column] == -1 && gamePlay[row+2][column+2] !=0) ||
(gamePlay[row-1][column+1] == -1 && gamePlay[row+1][column+1] == -1 && gamePlay[row+1][column+2] !=0) ||
(gamePlay[row-2][column] == -1 && gamePlay[row-1][column-1] == -1) ||
(gamePlay[row+1][column+1] == -1 && gamePlay[row+2][column] == -1 && gamePlay[row][column+1] !=0 && gamePlay[row+2][column-1] !=0) ||
(gamePlay[row-1][column-1] == -1 && gamePlay[row+1][column-1] == -1) ||
(gamePlay[row-2][column] == -1 && gamePlay[row-1][column+1] == -1) ||
(gamePlay[row+1][column-1] == -1 && gamePlay[row+1][column+1] == -1 && gamePlay[row][column+1] !=0) ||
(gamePlay[row][column+2] && gamePlay[row-1][column+1] == -1 && gamePlay[row+1][column] !=0 && gamePlay[row][column+1] !=0) ||
(gamePlay[row][column-2] == -1 && gamePlay[row-1][column-1] == -1 && gamePlay[row+1][column-2]!=0) ||
(gamePlay[row][column+2] == -1 && gamePlay[row+1][column+1] == -1 && gamePlay[row+1][column] !=0) ||
(gamePlay[row-1][column-1] == -1 && gamePlay[row-1][column+1] == -1) ||
(gamePlay[row][column-2] == -1 && gamePlay[row+1][column-1] == -1) ||
(gamePlay[row][column-1] == -1 && gamePlay[row+2][column] == -1 && gamePlay[row][column+1] != 0))
{
gamePlay[row][column] = 1;
break;
}
//fifth rule
else if (gamePlay [3][3] == 0)
{
gamePlay[3][3] == 1;
break;
}
//sixth rule
else if ((gamePlay[row-2][column-2] == -1 && gamePlay[row][column-2] != -1 && gamePlay[row-2][column] != -1) ||
(gamePlay[row+2][column+2] == -1 && gamePlay[row][column+2] != -1 && gamePlay[row+1][column+2] != -1) ||
(gamePlay[row+2][column-2] == -1 && gamePlay[row][column-2] != -1 && gamePlay[row+2][column-2] != -1)||
(gamePlay[row-2][column+2] == -1 && gamePlay[row-2][column] != -1))
{
gamePlay[row][column] = 1;
break;
}
//seventh rule
else if ((row == 2 && column == 2 && gamePlay[row][column+2] !=0 && gamePlay[row+2][column+2] !=0 && gamePlay[row+1][column+2] !=0 && gamePlay[row+1][column] !=0 && gamePlay[row+2][column] !=0)
|| (row == 2 && column ==4 && gamePlay[row+1][column-2] != 0 && gamePlay[row+1][column] !=0)
|| (row == 4 && column == 4 && gamePlay[row][column-1] != 1 && gamePlay[row][column-2] != 1) || (row == 4 && column == 2 && gamePlay[row][column+1] !=0))
{
gamePlay[row][column] = 1;
}
//eight rule
else if ((gamePlay[row-1][column] == 0 && gamePlay[row+1][column] == 0 && gamePlay[row+2][column-1] !=0 && gamePlay[row+2][column-2] !=0 && gamePlay[row+2][column] != 0 && gamePlay[row+1][column-2] !=0) ||
(gamePlay[row][column-1] == 0 && gamePlay[row][column+1] == 0 && gamePlay[row+2][column-1] !=0 && gamePlay[row+2][column-2] !=0 && gamePlay[row+2][column] != 0 && gamePlay[row+1][column-2] !=0) ||
(gamePlay[row-1][column] == 0 && gamePlay[row+1][column] == 0 && gamePlay[row+2][column-1] !=0 && gamePlay[row+2][column-2] !=0 && gamePlay[row+2][column] != 0 && gamePlay[row+1][column-2] !=0) ||
(gamePlay[row][column-1] == 0 && gamePlay[row][column+1] == 0 && gamePlay[row+2][column-1] !=0 && gamePlay[row+2][column-2] !=0 && gamePlay[row+2][column] != 0 && gamePlay[row+1][column-2] !=0))
{
gamePlay[row][column] = 1;
}
}
}
}
return 0;
}
Jump to Line
Something went wrong with that request. Please try again.