Question: Python In [5: def advance board (game board): Advances the game board using the given rules. Input: the initial game board Output: the advanced game
In [5: def advance board (game board): Advances the game board using the given rules. Input: the initial game board Output: the advanced game board create a new array that's just like the original one, but initially set to all zero new board np.zeros_like (game_board) loop over each cell in the board and decide what to do. # You'll need two loops here, one nested inside the other. # Now that we're inside the loops we need to apply our rules # if the cell was empty last turn, it's still empty. # if it was on fire last turn, it's now empty. # now, if there is a tree in the cell, we have to decide what to do initially make the cell a tree in the new board # If one of the neighboring cells was on fire last turn, # this cell is now on fire ! # (make sure you account for whether or not you're on the edge!) return the new board return new board As good coders, we always test our new functions! Test your function above and make sure it works! Run the code a few times to see whether fire advances according to the rules. You can start with any sort of initial board that you want, you can even just use the default board for the purpose of testing. In [ ]: | # Initialize a new board here In [15]: # Test your new advance, board function here. Make a plot to check it. # Run this cell several times to make sure the fire continues to advance. # Again, we set the figure size for you fig plt.figure(figsize-(10,10))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
