Как посчитать конкретное значение в многомерном массиве c # (Unity) - PullRequest
0 голосов
/ 21 мая 2018

У меня проблемы с подсчетом числа моего TIE значения в моем списке

вот мой код:

string[,] table = new string[104, 15];
int xIndex = 0;
int yIndex = 0;

for (int i = 0; i < list.Count; i++)
{
    newString[0] += list[i].r;
    newString[0] += ",";
}
string[] newChars = newString[0].Split(',');
string result = ""; // variable for the substring
string previousValue_ = ""; // store here the newprevious value without the T
int counterForTie = 0;
int counterForRow = 1;
int justMoveToY = 1;

foreach (string previousValue in newChars)
{
    //check the length so that it wont throw an error
    if (previousValue.Length > 1)
    {
          //get only the first letter of value P,B,T
          result = previousValue.Substring(0, 1);
    }
    else
    {

           result = "";
    }

 if (table.GetLength(0) < xIndex)
            {
                break;
            }

            if (result.Equals(newPreviousValue) || result.Equals("T") && yIndex < table.GetLength(1))
            {

                if (counterForRow == 1)
                {
                    yIndex = 0;
                    table[xIndex, yIndex] = result;
                    counterForRow++;

                    if (firstDragonTail)
                    {
                        counterForTieSecondTime++;
                    }
                    else if (secondDragonTail)
                    {
                        counterForTieThirdTime++;
                    }
                    else
                    {
                        counterForTie++;
                    }

                }
                else
                {
                    yIndex += 1;
                    table[xIndex, yIndex] = result;
                    if (firstDragonTail)
                    {
                        counterForTieSecondTime++;
                    }
                    else if (secondDragonTail)
                    {
                        counterForTieThirdTime++;
                    }
                    else
                    {
                        counterForTie++;
                    }
                }

            }
            else if (result.Equals(newPreviousValue) && previousValue.Equals("T") && yIndex < table.GetLength(1))
            {
                yIndex += 1;
                table[xIndex, yIndex] = result;

                if (firstDragonTail)
                {
                    counterForTieSecondTime++;
                }
                else if (secondDragonTail)
                {
                    counterForTieThirdTime++;
                }
                else
                {
                    counterForTie++;
                }

            }
            else
            {
                if (justMoveToY == 1 && counterForRow == 1)
                {
                    xIndex = 0;
                    yIndex = 0;
                    table[xIndex, yIndex] = result;
                    justMoveToY++;
                    counterForRow++;
                }
                else if (justMoveToY == 1)
                {
                    xIndex = 0;
                    yIndex += 1;
                    table[xIndex, yIndex] = result;
                    justMoveToY++;
                }
                else {

                    if (firstDragonTail)
                    {
                        xIndex += 1;
                        yIndex = 0;
                        table[xIndex, yIndex] = result;
                        counterForTieSecondTime = 0;
                        if (counterForTieSecondTime == 0)
                        {
                            secondDragonTail = true;
                            firstDragonTail = false;

                        }
                        else
                        {
                            secondDragonTail = false;
                        }
                    }
                    else if (secondDragonTail)
                    {
                        xIndex += 1;
                        yIndex = 0;
                        table[xIndex, yIndex] = result;
                        counterForTieThirdTime = 0;
                        if (counterForTieThirdTime == 0)
                        {
                            thirdDragonTail = true;
                            secondDragonTail = false;
                        }
                        else
                        {
                            thirdDragonTail = false;
                        }
                    }
                    else
                    { 
                        xIndex += 1;
                        yIndex = 0;
                        table[xIndex, yIndex] = result;
                        counterForTie = 0;
                    }
                }
            }

            previousValue_ = result;

            if (!result.Equals("T"))
            {
                newPreviousValue = previousValue_;
            }

}

Моя проблема в том, что я не смогсчитать отдельно все TIE значение.Все, что я хочу просто посчитать значение TIE в каждом столбце.

Например, как это изображение

enter image description here

Как вы можете видеть на изображении выше, я хочу знать, если значение TIEна значение PLAYER (синий) / BANKER (красный) и подсчитать значение TIE, если его количество в столбце Player и наоборот.

Я пробовал это

//count tie in a row
if (result.Equals("T") && result.Equals("P"))
{
      tieCounterPlayer++;
      Debug.Log("TIE FOR PLAYER :" + tieCounterPlayer);
}
else if(result.Equals("T") && result.Equals("B"))
{
      tieCounterBanker++;
      Debug.Log("TIE FOR BANKER :" + tieCounterBanker);
}

Но, к сожалению, это не сработало.

1 Ответ

0 голосов
/ 21 мая 2018

Извините за вопрос

Это то, что я сделал.

if (newPreviousValue.Contains("B"))
{
     if (result.Equals("T"))
     {
           tieCounterBanker++;
           Debug.Log("TIE FOR BANKER : " + tieCounterBanker);
     }
     else
     {
           tieCounterBanker = 0;
     }
}
else if(newPreviousValue.Contains("P"))
{
      if (result.Equals("T"))
      {
            tieCounterPlayer++;
            Debug.Log("TIE FOR PLAYER : " + tieCounterPlayer);
      }
      else
      {
            tieCounterPlayer = 0;
      }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...