title: c++ : 1hh0 puzzle game
body: <p>I'm trying to create a puzzle-like, sudoku-style game called "0hh1", but i seem to keep getting stuck on this one fuction. The game doesn't allow the user to put three consecutive squares of the same color (there are two colors, red and blue) next to each other, but two is fine. This function should check the row for any two consecutive squares of the same color and write the opposite color in the square not yet filled (UNKNOWN squares). It should write the ooposite color on both ends of two consecutive tiles in row, and in the middle between two tiles of the same color in row. mark_square_as() is the function that assigns color to a square and the each board has the same number of rows and columns.</p>
  
  <pre><code>Example: ---- becomes ----
           XX--         XXO-
           -XX-         OXXO
           --X-         --X-
  </code></pre>
  
  <p>in which X represent red and O represents blue, - is unknown</p>
  
  <p>Here is my code:</p>
  
  <pre><code>void solve_three_in_a_row(int board[MAX_SIZE][MAX_SIZE],
  int size,
  int row,
  bool announce) {
  for (int i = 0; i &lt; size; i++) {
      if (board[row][i] == 1 &amp;&amp; board[row][i + 1] == 1) {
          if (i + 1 == size - 1 &amp;&amp; i - 1 &gt;= 0 &amp;&amp; board[row][i - 1] == UNKNOWN) {
              mark_square_as(board, size, row, i - 1, 2, announce);
          }
          else if (i == 0 &amp;&amp; i + 2 &lt;= size &amp;&amp; board[row][i + 2] == UNKNOWN) {
              mark_square_as(board, size, row, i + 2, 2, announce);
          }
          else if (i - 1 &gt;= 0 &amp;&amp; i + 2 &lt;= size &amp;&amp; board[row][i - 1] == UNKNOWN &amp;&amp; board[row][i + 2] == UNKNOWN) {
              mark_square_as(board, size, row, i - 1, 2, announce);
              mark_square_as(board, size, row, i + 2, 2, announce);
          }
      }
      else if (board[row][i] == 1 &amp;&amp; board[row][i + 2] == 1 &amp;&amp; board[row][i + 1] == UNKNOWN) {
          mark_square_as(board, size, row, i + 1, 2, announce);
      }
  }
  for (int i = 0; i &lt; size; i++) {
      if (board[row][i] == 2 &amp;&amp; board[row][i + 1] == 2) {
          if (i + 1 == size - 1 &amp;&amp; i - 1 &gt;= 0 &amp;&amp; board[row][i - 1] == UNKNOWN) {
              mark_square_as(board, size, row, i - 1, 1, announce);
          }
          else if (i == 0 &amp;&amp; i + 2 &lt;= size &amp;&amp; board[row][i + 2] == UNKNOWN) {
              mark_square_as(board, size, row, i + 2, 1, announce);
          }
          else if (i - 1 &gt;= 0 &amp;&amp; i + 2 &lt;= size &amp;&amp; [row][i - 1] == UNKNOWN &amp;&amp; board[row][i + 2] == UNKNOWN) {
              mark_square_as(board, size, row, i - 1, 1, announce);
              mark_square_as(board, size, row, i + 2, 1, announce);
          }
      }
      else if (board[row][i] == 2 &amp;&amp; board[row][i + 2] == 2 &amp;&amp; board[row][i + 1] == UNKNOWN) {
          mark_square_as(board, size, row, i + 1, 1, announce);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>However, when i try running it, the answers weren't correct for a few cases: (the right side is my output, the left side is the correct output)</p>
  
  <pre><code>OXXO 
  XOXO
  OXOX
  XOOX 
  (my output said to mark (2nd row, 5th column) as X, when there is not even a fifth column)
  
  O-
  --
  (my output said to mark (1st row, 2nd column) as X, when it should mark nothing)
  
  OO-X--
  X--X-O
  ------
  X---OX
  ---XOO
  -X-O-O
  (my output said to mark (1st row, 3rd column) and (6th row, 5th column) as X, which is correct. But it didn't say to mark (1st row, 5th column) as O as it should because (1st row, 3rd column) would have also been marked).
  </code></pre>
  
  <p>I'm not sure where my code went wrong, thank you so much.</p>