(For example, if step is 3 and bombs is 1, bombs - step will be -2.)Īlso, can I make a couple of suggestions about your code from a readability point of view? Firstly, you are repeating bombs and bombs a lot: if you add lines x = bombs and y = bombs you could write x and y instead of bombs and bombs in the rest of the loop. I'm also a bit concerned about step: is this equal to 1? You are including step in your checks for falling off the right-hand side or the bottom of the grid, but not when falling off the top or left-hand side, so if step is greater than 1 you may run into problems. Clearly these checks are trying to stop you going off the edge of the grid, but the extra -1 is unnecessary. Looking at your code, I'm not sure you need the -1 in conditions such as if (bombs < heigth-step-1). You would also make the same changes to the other three if statements that handle adding one to the counts for diagonally-adjacent squares in other directions. # This line will now be reached if there is another bomb to the left of bombs. What you want to do is to remove a level of indentation from the third if statement in the above: if (bombs > 0): This is incorrect: for any bomb, we need to check the cell above and to the left of it whether or not the cell to the left of it is also a bomb. Note that we only look at the cell above and to the left of the bomb and add one to it if it isn't a bomb if the cell to the left is also not a bomb. # The cell above and to the left is not a bomb, so add one to its count # This bomb is not in the top row of the grid. # The cell to the left is not a bomb, so add one to its count # This bomb is not in the leftmost column of the grid I think a problem is in this section of code: if (bombs > 0): Numbers+0, bombs+step)] = numbers+0, bombs+step)] + 1 Numbers+0, bombs-step)] = numbers+0, bombs-step)] + 1 Numbers+step, bombs-step)] = numbers+step, bombs-step)] + 1 Numbers-step, bombs-step)] = numbers-step, bombs-step)] + 1 Numbers-step, bombs+0)] = numbers-step, bombs+0)] + 1 Counting the numbers of an field surrounded by bombs, I get an worse problem - no error. I tried to program Minesweeper in python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |