交替奇数

aka*_*ase 1 c# unity-game-engine

有没有一种方法或公式可以检查奇数是否是替代奇数。

解说员

1  
3 alt  
5  
7 alt  
9  
11 alt  
13  
15 alt...
Run Code Online (Sandbox Code Playgroud)

我尝试过谷歌搜索来寻找答案,但只能找到奇数/偶数的模数或带有要检查的值的数组。

int half = (gridsize) / 2;
int row = 0;

for (int x = 0; x < gridsize; x++)
{
    int tilesThisRow = gridsize - (half - row);
    int drop = gridsize - tilesThisRow;

    int frontDrop;
    int backDrop;

    if(drop % 2 != 0)
    {
        //3 front
        //5 back
        //7 front
        //9 back
        //11 fron
        //13 back
        //15 front
        //17 back

        // it's this i need to alternate depending on the size
        frontDrop = (drop / 2) + 1;
        backDrop = (drop / 2);
    }
    
    for (int y = 0; y < gridsize; y++)
    {
        if (y >= frontDrop && y < gridsize - backDrop)
        {
            AddHexTile(x, y, gridOffsets);
        }
    }

    if (x < half)
    {
        row++;
    }
    else
    {
        row--;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我用来生成六边形六角形瓷砖网格的方法,该网格根据所使用的尺寸而破裂。

图片以供澄清。

7 号
在此输入图像描述

9号
在此输入图像描述

der*_*ugo 6

你可以例如检查

value % 4 == 3
Run Code Online (Sandbox Code Playgroud)

value % 4 == 1同时为他人使用。

小提琴

0
1 normal odd
2
3 alt odd
4
5 normal odd
6
7 alt odd
8
9 normal odd
10
11 alt odd
12
13 normal odd
14
15 alt odd
16
17 normal odd
18
19 alt odd
20
21 normal odd
22
23 alt odd
...
Run Code Online (Sandbox Code Playgroud)