MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / getNewBoard

Function getNewBoard

src/gamesbyexample/flooder.py:88–105  ·  view source on GitHub ↗

Return a dictionary of a new Flood It board.

()

Source from the content-addressed store, hash-verified

86
87
88def getNewBoard():
89 """Return a dictionary of a new Flood It board."""
90
91 # Keys are (x, y) tuples, values are the tile at that position.
92 board = {}
93
94 # Create random colors for the board.
95 for x in range(BOARD_WIDTH):
96 for y in range(BOARD_HEIGHT):
97 board[(x, y)] = random.choice(TILE_TYPES)
98
99 # Make several tiles the same as their neighbor. This creates groups
100 # of the same color/shape.
101 for i in range(BOARD_WIDTH * BOARD_HEIGHT):
102 x = random.randint(0, BOARD_WIDTH - 2)
103 y = random.randint(0, BOARD_HEIGHT - 1)
104 board[(x + 1, y)] = board[(x, y)]
105 return board
106
107
108def displayBoard(board, displayMode):

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected