Discover winner Game Cock / Old Game

1

I'm developing the rooster / old game and in this game I have to check every new move or iteration if there is any winner. I started by trying to do this for a static array predefined by myself and also started by doing the check first by deleting the two possible diagonals. The code is as follows

UPDATE

int main()
{

int VEC[3][3] = {
                {1,1,1},
                {0,1,0},
                {1,0,1}
              };
int m = 3;
int n = 3;
int i = 0,j = 0,count = 1,total = 0;

for(i = 0; i < 3; i++)
{
    for(j = 0; j < 3; j++)
    {
        if(VEC[i][j] == VEC[i][j+1])
        {
            count++;
            if(count == 3)
            {
                printf("GANHOU!\n");
                break;
            }
        }
        else
        {
            count = 0;
            break;
        }
    }
    }
}

In this case I've submitted it tells me that there is a winner and there really is a winning key in the last row of the array. But I have some doubts about this code. Firstly because I think in all the lines I left out of the array by being checking the j + 1 position. And I do not know to what extent this is quite wrong or not. Then I tried to control this situation by adding i

asked by anonymous 28.12.2018 / 10:38

1 answer

1

You need to check for a winner for both players. I recommend using functions and then scanning the array. Ex: the first function checks if the top line is filled with only "x", in case player one, if yes, returns the winner if it does not continue the game. If you are still in doubt. I can do the code, but you'd better try.

    
29.12.2018 / 22:25