简体   繁体   English

我如何检查宾果游戏?

[英]How do I check for a Bingo?

I'm creating a bingo-like game.我正在创建一个类似宾果游戏的游戏。 And in my case, the 'Bingo-card' contains 25 numbers.就我而言,“宾果卡”包含 25 个数字。 How do I check if there is a 'chance' and a 'bingo' on one of the 3 (horizontal, vertical or diagonal) ways?我如何检查在 3 种(水平、垂直或对角线)方式之一上是否有“机会”和“宾果游戏”?

Bingo array宾果阵列

int[,] lost_numbers = { { 1, 0, 1,  0 , 1 },
                        { 1, 1, 0,  0 , 1 },
                        { 1, 0, 1,  0 , 1 },
                        { 0, 0, 0, [1], 1 },
                        { 0, 1, 1,  0 , 0 }
 };

Vertical look垂直外观

        int sumV = 0;
        for (int colnr = 0; colnr < 4; colnr++)
        {
            for (int rownr = 0; rownr < numRows; rownr++)
            {
                sumV += lost_numbers[rownr, colnr];

                if (sumV == 1) // sum of the column
                {
                    for (int y = 0; y < numRows; y++)
                    {
                        if (lost_numbers[colnr, y] == 1)
                        {
                            // here change ??
                        }
                    }
                }
            }
            sumV = 0;
        }

The problem is that you have to have a look if the Sum = 4 when the loop is finished, otherwise every 1 is a change.问题是当循环结束时你必须看看 Sum = 4 ,否则每 1 都是一个变化。 How do I solve this?我该如何解决这个问题?

Quite simple.非常简单。 You could do it in two steps.你可以分两步完成。

In step 1 you just check IF there is bingo or a chance in some of the lines.在步骤 1 中,您只需检查某些行中是否有宾果游戏或机会。 You suggesting calculation the sum, that should work just fine.您建议计算总和,那应该可以正常工作。

Only if step 1 found something then you would visit that line(s) again and find out where exactly your chance is.只有在第 1 步找到一些东西后,您才会再次访问该行并找出您的机会在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM