0

I've been trying to make a board game of GO, in python with pygame and a numpy array for storing the board locations and stone colors (0, 1, 2). My issue is that I've been using a for loop to examine each index at a time, and examining the adjacent indexes by adding or taking away an int:

columns = 5
rows = 5

def create_board():
    board = np.zeros((row,col))
    return board

board = create_board()

def libertyCheck():
    for c in range(columns):
        for r in range(rows):
            if board[c][r+1] == 0:
                x = 1
            (lots more ifs, then add x's to see if all spaces are occupied)

This method seems to be OK for capturing a single stone (as long as its not on the edges of the board, because it also starts causing out of bounds issues), but becomes very convoluted once several stones of the same color are next to each other and may or may not need to be captured.

There has to be a better way of searching these indexes without causing out of bounds? one that will allow me to keep track of all of the stones and their adjacent spaces?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Not a complete answer, but I would recommend taking a look at a recursive algorithm, like a `flood fill` algorithm. This would allow you identify groups of orthogonally adjacent stones. From there, you could get the liberties of each of the stones in a given group by looking up/down/left/right and take the set of these empty spaces to get all of the unique liberties. – CodeSurgeon Apr 12 '18 at 05:04
  • thank you for the suggestion, I'll look into this – Mac n' peas Apr 12 '18 at 16:59

0 Answers0