だから私は、時々無限ループを生成し続けるこのコード行を持っています。私の論理はどこか間違っていますか?「if (randomNumbersForSelectionArray.Count > 0)」内の if ステートメントは常に true を返す必要がありますが、そうではありません。次に、else ステートメントを実行して、無限ループに入ったときにコードが true になるかどうかを確認すると、ロジックが正しいことが確認されます。これがどこで間違っているのか理解できないようです。ありがとう!!
ここに私が得ているいくつかのサンプル出力があります。
12| 2 =should= 2
なぜ壊れるの!?!?!?
12| 2 =should= 2
なぜ壊れるの!?!?!?
...無限に
int countLoop = 0;
if (trackFitnessRankArray.Length >= 1) {
while (randomNumbersForSelectionArray.Count > 0)
{
countLoop++;
for (int j = trackFitnessRankArray.Length - 1; j >= 0; j--)
{
if (randomNumbersForSelectionArray.Count > 0)
{
if (randomNumbersForSelectionArray[0] >= (trackFitnessRankArray[j].CutoffPointForReproduction - trackFitnessRankArray[j].ChanceOfReproduction) && randomNumbersForSelectionArray[0] < trackFitnessRankArray[j].CutoffPointForReproduction)
{
//take the selected AIs and put them in an array
selectedToBreed.Add(trackFitnessRankArray[j]);
//remove the number from the randomNumber array
randomNumbersForSelectionArray.RemoveAt(0);
}
else
{
//if we're in an infinite loop
if (countLoop > AI_IN_EACH_GENERATION)
{
if (randomNumbersForSelectionArray[0] == trackFitnessRankArray[j].CutoffPointForReproduction)
{
if (j != 0)
Debug.WriteLine(j + "| " + randomNumbersForSelectionArray[0] + " =should= " + (trackFitnessRankArray[j - 1].CutoffPointForReproduction + trackFitnessRankArray[j - 1].ChanceOfReproduction));
if (randomNumbersForSelectionArray[0] != (trackFitnessRankArray[j - 1].CutoffPointForReproduction + trackFitnessRankArray[j - 1].ChanceOfReproduction))
Debug.WriteLine("Why is this breaking!?!?!?");
}
}
}
}
}
}
}