Building the Board

Alright, so lets start with the big picture thinking. How to do represent the board itself? Well, as we saw with the chess program (design lecture) it seems like nested lists trump strings. So lets run with that.

Okay so our board is going to look something like this:

[ _, B, _ ]
[ B, _, _ ]
[ _, _, _ ]

Where "B" = Bomb

Now. If we show the player the board above then clearly the game is easy. So thats something we need to think about; how are we going to handle (a) the internal state of the game and (b) what we show to the player.

So now if the player selects the first square (0, 0) then we want to display something like this:

[ 2, _, _ ]
[ _, _, _ ]
[ _, _, _ ]

Where '2' denotes the number of bombs nearby. 

What else might our build board function need to do? Well, I think it would be nice to be able to set the board size (e.g. 10x10, 5x20) and we may also want to set the number of bombs in the game.

Alright, so now that we have fleshed out the problem we need to solve the next thing to do is to try to come up with a solution. There are of course many possible ways to do this, but I think a simple approach is to just we build two boards of the same size. One board represents the internal games state and the other board is what we show the player. This two boards will need to be kept 'insync'.

Test-Driven Development

Remember in the testing lecture I talked about how sometimes writing the tests first makes implementing the problem easier? Well, I'd encourage you to think about writing some tests before getting 'stuck in', in the long run, it may save you a lot of time.

As a quick tip, if you want to place bombs randomly and also want to test the code then you may wish to set random.seed to some constant.


In [ ]:
def test_board():
    """
    Write your tests here...
    
    Example:
    >>> 1 + 1
    2
    
    """
    import doctest
    doctest.testmod()
    print("TESTING COMPLETE... if you see nothing, (other than this message) that means all tests passed.")

In [ ]:
#def build_board
    # Your code here

# Runing the tests...
test_board()
# Note if you recieve an error message saying test_board not found 
# try hitting the run button on the test_board cell and try again.

If you get stuck, then you can always check out my solution to the problem (just look for _1 Building the board (HW))