Visual Basic

时间:2018-01-03 18:31:03

标签: vb.net game-physics flood-fill

我已经在线查看了visual basic中的泛洪填充算法,但我找不到对我有意义的算法。我是vb的初学者,这可能就是原因。

我试图在洪水填充上使用维基百科的算法,我理解它是如何工作的逻辑,但我只是不知道如何在Visual Basic中编程。

 Flood-fill (node, target-color, replacement-color):
 1. If target-color is equal to replacement-color, return.
 2. If the color of node is not equal to target-color, return.
 3. Set the color of node to replacement-color.
 4. Perform Flood-fill (one step to the south of node, target-color, replacement-color).
    Perform Flood-fill (one step to the north of node, target-color, replacement-color).
    Perform Flood-fill (one step to the west of node, target-color, replacement-color).
    Perform Flood-fill (one step to the east of node, target-color, replacement-color).
 5. Return.

我目前正在重建Go的棋盘游戏,这需要填充洪水以搜索捕获的石头。捕获的石头被定义为在所有侧面,水平和垂直,但不是对角线完全包围的碎片。当一块或一块石头被放置在对手石块被完全包围的特定位置时,被包围的块从板上移除。所以洪水填充不是从你刚刚放置的石头开始的,而是从你刚刚包围的对手的石头开始。洪水填充需要是每次玩家在棋盘上放置石头时发生的递归。

我在Windows窗体中执行此操作,并尝试过此操作,但它似乎很长时间(不完整):

Dim northsouth As Integer
Dim eastwest As Integer

northsouth = gridPosition.X + 1
If placed_stone(northsouth, gridPosition.Y) = 2 Then
    eastwest = gridPosition.Y + 1
    If placed_stone(northsouth, eastwest) = 1 Then
        eastwest = gridPosition.Y - 1
        If placed_stone(northsouth, eastwest) = 1 Then
            northsouth = gridPosition.X + 2
            If placed_stone(northsouth, gridPosition.Y) = 1 Then
                northsouth = gridPosition.X + 1
                Grid(gridPosition.X)(gridPosition.Y) = True 'Place a black stone at Grid(x,y)
                Grid(northsouth)(gridPosition.Y) = Nothing
                placed_stone(northsouth, gridPosition.Y) = 0
                pass = False
                cp = False
                passbtn.BackColor = Color.White 'The passbutton changes colour to white
                passbtn.ForeColor = Color.Black 'The passbutton font changes colour to black
            End If
        End If
    End If
End If

Placed_stone是电路板的二维数组表示。我用“0”,“1”和“2”分别表示这个2d数组中的空白,黑色和白色。

请告诉我如何编码并实施洪水填充到这种情况?如果有人想查看整个代码,请告诉我。我很感激任何建议!

0 个答案:

没有答案