performance - Efficient way to validate a Connect Four game -


I'm scanning four games connected with opencv as in a data structure. Originally, it uses 7 x 7 (with only zero in the top row) for each player, so that the winner is not checked by using most bitsoft operators and any loops.

There are very good algorithms to check a winner, but I did not know whether the board represents a valid position.

These are the criteria for a valid status, which are written in this way:

  1. "If the total number of classes occupied in a situation is odd, then white The number of men is more than the number of black men. If the total occupied intersections are even, then these numbers are the same. " >
  2. "Also, if there is a blank square in any column, then all the squares are also empty than this class."
  3. "If there are four connected men in one situation, then the situation ends in one game. The game is over in the last move, at least one of the group connected to the group has the highest If this is not the case, or both players have been linked.
  4. "If a player has more than one group connected then this situation can only be legal if these groups are such a Make a part of the square The last man is played. "

In addition to this, there are posts that are impossible to achieve while strictly implementing all the rules. Here is a simple example:

     

Html>