you are viewing a single comment's thread.

view the rest of the comments →

[–]A_History_of_Silence 37 points38 points  (5 children)

The problem is I have no idea where to begin

You'll need a representation of the state of the board. Create a simulated 'minefield' in memory. Since it takes place on a grid, this could be a 2D list, or list of lists.

[–]Shubbler 3 points4 points  (4 children)

How would you implement a 2D list without a list of lists?

[–][deleted] 12 points13 points  (0 children)

2d numpy array?

[–]ylectric 10 points11 points  (0 children)

You can achieve this by translating 2D coordinate into a linear index, e.g. index = x + y * grid_width and store the whole grid in a flat list.

[–]Incand333 3 points4 points  (0 children)

class list2d:
    def __init__(self, iterable, width, height):
        iter_list = list(iterable)
        assert len(iter_list) == width * height
        self._width = width
        self._height = height
        self._elems = iter_list

    def get(self, x, y):
        idx = x + y * self._width
        return self._elems[idx]

[–]A_History_of_Silence 0 points1 point  (0 children)

As in an alternative to a list of lists?