I have just initialized an array of random values but I would like that in the case where 3 values are aligned, my array is regenerated in such a way that, as of its initialization my array never comprises 3 consecutive similar values. I am a beginner in C ++, and I don't know what it is the best way to go about it, is it better to create functions that will check if my previous box in my array is similar? or do it directly in my array set up function? Below here is the creation of my table. Many thks for your help
void CPlateau::CreatePlateau()
{
m_arrPlateau = newint*[m_iLignes];
for (int ligne = 0; ligne < m_iLignes; ligne++)
{
m_arrPlateau[ligne] = newint[m_iColonnes];
for (int col = 0; col < m_iColonnes; col++)
m_arrPlateau[ligne][col] = 0;
}
}
void CPlateau::SetupPlateau()
{
if (m_arrPlateau == NULL)
CreatePlateau();
for (int ligne = 0; ligne < m_iLignes; ligne++)
for (int col = 0; col < m_iColonnes; col++)
m_arrPlateau[ligne][col] = (rand() % 7);
}
Unclear what you mean by "aligned". Do you mean adjacent in the same column?
What about adjacent in the same row?
Also what do you mean by "similar"? Do you mean identical values?
You really have to wait until you've populated the entire array before you can check for adjacent values. i.e. You can't check what will be in the next cell until that cell has been populated.
Thank you AbstractionAnon for your answer.
Yes that's exactly what I mean: adjacent in the same column and adjacent in the same row. Also it's identical values.
To contextualize my problem, I'm trying to create a match-3 game like bejeweled, so it's necessary for me to prohibit that 3 consecutive values, horizontal or vertical are equal during initialization.