0
About a check algorithm
So basically I’m trying to make a game caro in c++. It’s basically like tic tac toe except the size is n x n not 3 x 3, and to win you have to have 5 on row, column or diagonal. I want to know is there any way to check if the player win the game or not. I tried scanning the entire array and check like a[i][j] == a[i][j+1], and so on, but it’s quite insufficient. I appreciate all algorithm suggest. Note: I’m not familiar with <vector> and <array>
2 ответов
+ 3
Based on what has been provided, you can write a diag_check_right2left with relative ease. To move from top right to bottom left, you can start from the fifth column, first row and for each move, increment row count and decrement column count. You can give it a try first, and if you meet with any problems, just drop us a ping here and we'll try to help.
+ 2
This is what I've come up with so far.
https://code.sololearn.com/c51OLG23n9es/#cpp
Code checks vertical, horizontal and diagonally (top left to bottom right). I haven't had the time to do diagonal checking for top right to bottom left, so I'll just leave this here in the meantime. You can try editing the board contents to see if any test cases fail.
You don't really need a vector since the board size doesn't change during runtime, or at least when the game has began. A fixed size array would suffice.