(field, startx, starty, newChar)
| 73 | |
| 74 | |
| 75 | def iterativeFloodFill(field, startx, starty, newChar): |
| 76 | curChar = field[(startx, starty)] |
| 77 | |
| 78 | coordinatesToChange = [(startx, starty)] |
| 79 | |
| 80 | while len(coordinatesToChange) > 0: |
| 81 | x, y = coordinatesToChange.pop() |
| 82 | field[(x, y)] = newChar # Change the character. |
| 83 | |
| 84 | # Change the neighboring characters: |
| 85 | if y + 1 < HEIGHT and field[(x, y + 1)] == curChar: |
| 86 | # Change the character for the southern neighbor: |
| 87 | coordinatesToChange.append((x, y + 1)) |
| 88 | if y - 1 >= 0 and field[(x, y - 1)] == curChar: |
| 89 | # Change the character for the northern neighbor: |
| 90 | coordinatesToChange.append((x, y - 1)) |
| 91 | if x + 1 < WIDTH and field[(x + 1, y)] == curChar: |
| 92 | # Change the character for the eastern neighbor: |
| 93 | coordinatesToChange.append((x + 1, y)) |
| 94 | if x - 1 >= 0 and field[(x - 1, y)] == curChar: |
| 95 | # Change the character for the western neighbor: |
| 96 | coordinatesToChange.append((x - 1, y)) |
| 97 | |
| 98 | |
| 99 | def printField(field): |
nothing calls this directly
no outgoing calls
no test coverage detected