samedi 3 décembre 2016

Making my code shorter in C

for (c = 0; c < SIZE-4; ++c)
    for (r = 0; r < SIZE; ++r)
        if (board[r][c] == cross && board[r][c+1] == cross && board[r][c+2] == cross && board[r][c+3] == cross && board[r][c+4] == cross)
            return true;

I am working on my Tic-Tac-Toe in C (with custom size board, 5 needed in a row to win). I have this really-really long 'if', which I want to make shorter. I also have this code 4 times becuase of the row, column, diag, antidiag, so it needs some fix.

Aucun commentaire:

Enregistrer un commentaire