Win conditions for Match 3 game
<p>I have a randomly generated 10x5 array that I want to check when 3 numbers match both horizontally, and vertically. I can't figure out a good way to do the check to see if the numbers match. The way I am currently doing it, it would take me over 70 if statements, and I know there is a better way. I don't think I can use a for loop to check though because I need to know exactly which 3 numbers (and their location) are the same.</p>

<p>Here is the code I have so far, sorry if it is a little long. I only included the check for one row to save space.</p>

<pre>
<code>
#include &ltiostream&gt
#include &lttime.h&gt
#include &ltcstdlib&gt
#include &ltcstdio&gt

using namespace std;
int col = 5;
int row = 0;

int board[9][4];
int i;

int main(int argc, char * argv[])
{
 srand(time(NULL));

 // generate the random board

 cout &lt&lt "==========\n";
 while (row &lt 1)
 {
  for(i = 0; i &lt 5; i++)
  {
   board[row][i] = rand()%5 + 1;
   cout &lt&lt board[row][i] &lt&lt " ";
  }
  cout &lt&lt endl;
  cout &lt&lt "==========\n";
  row++;
 }

 //----check for matches-----

 // row 1
 if (board[0][0] == (board[0][1] && board[0][2]))
 {
  cout &lt&lt "Balls 1,2,3 match\n";
 }
 if (board[0][2] == (board[0][3] && board[0][4]))
 {
  cout &lt&lt "Balls 3,4,5 match\n";
 }
 if (board[0][1] == (board[0][2] && board[0][3]))
 {
  cout &lt&lt "Balls 2,3,4 match\n";
 }
 if (board[0][0] == (board[0][1] && board[0][2] && board[0][3]))
 {
  cout &lt&lt "Balls 1,2,3,4 match\n";
 }
 if (board[0][1] == (board[0][2] && board[0][3] && board[0][4]))
 {
  cout &lt&lt "Balls 2,3,4,5 match\n";
 }
 if (board[0][0] == (board[0][1] && board[0][2] && board[0][3] && board[0][4]))
 {
  cout &lt&lt "Balls 1,2,3,4,5 match\n";
 }
 else
 {
  cout &lt&lt "No balls match\n";
 }

 return 0;
}
</code>
</pre>
