Как мне подсчитать каждую строку и столбец многомерного массива в симуляции дорожной карты Баккара? - PullRequest
0 голосов
/ 22 мая 2018

У меня есть многомерный массив, который объявлен так:

string[,] table = new string[104,15];

Теперь в нем есть все данные, которые мне нужны, и я получил данные, чтобы поместить их в таблицу, выполнив это

int xIndex = 0;
int yIndex = 0;
string newPreviousValue = "placeholder";

for (int i = 0; i < list.Count; i++)
{
     newString[0] += list[i].r;
     newString[0] += ",";
}

string[] newChars = newString[0].Split(',');

foreach (string previousValue in newChars)
{
     table[xIndex, yIndex] = result;
}

Теперь я пытаюсь сделать следующее: Data A

enter image description here

Все эти значения Data B зависят от того, какое значениеData A имеет

КРАСНЫЙ означает «То же самое по длине»

СИНИЙ означает «Не то же самое по длине»

enter image description here

Так вот как это работает.

КОД ПСЕВДО

//I am talking about Data A
if table[1,1] is equal to null or T then
{

    if table[1,0] and table[0,0] has the same length

    //Display blue circle on Data B
    display a blue circle

}
//I am talking about Data A
else if table[1,1] is not equal to null then
{
    compare table[0,1] and table[0,0] if they have the same length as table[1,1] and table[1,0]

    //Display a red circle
    display a red circle }
 }

Если мне не ясно, вот правило .То, о чем я говорю, - это правила Big Eye Road.

Что я пробовал до сих пор, так это

 //lets check for the 2nd row and 2nd column of the big road table
 if (table[1,1] == null && table[2,0] != null)
 {
     Move = true;
     if (Move)
     {
 //lets move to the 3rd row and compare if they have the same in length (1st row and 1st column)
          if (table[0, 0] != null && table[1, 0] != null)
          {
              //red circle
          }
          else
          {
               //blue circle
          }
     }
 }

Чего я хочу добиться здесь, так это подсчитать каждую строку и столбец в DATA A если количество данных, которые там хранятся, например,

table[0,0] to table[0,6] имеет 1 data

table[1,0] to table[1,6] имеет 1 data

table[2,0] to table[2,6] имеет 2 data

Просто так.Может ли кто-нибудь помочь с этим, пожалуйста.Спасибо.

РЕДАКТИРОВАТЬ

В последней части моего вопроса я поделюсь тем, что я сделал

//COLUMN
for(int col = 0; col < table.GetLength(0); col++)
{
   int sum = 0;
   //ROW
   for (int row = 0; row < table.GetLength(1); row++)
   {
       if (table[col,row] != null)
       {
           sum++;
       }
   }
   Debug.Log("table column: " + col + " has " + sum + " data");
}

Теперь я могу получить это

table[0,0] to table[0,6] имеет1 data

table[1,0] to table[1,6] имеет 1 data

table[2,0] to table[2,6] имеет 2 data

1 Ответ

0 голосов
/ 23 мая 2018
for(int col = 0; col < table.GetLength(0); col++)
    {
        int sum = 0;
        //ROW
        for (int row = 0; row < table.GetLength(1); row++)
        {
            if (table[col,row] != null)
            {
                sum++;
            }
        }
        Debug.Log("table column: " + col + " has " + sum + " data");
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...