(board)
| 362 | |
| 363 | |
| 364 | def getDropSlots(board): |
| 365 | # Creates a "drop slot" for each column and fills the slot with a |
| 366 | # number of gems that that column is lacking. This function assumes |
| 367 | # that the gems have been gravity dropped already. |
| 368 | boardCopy = copy.deepcopy(board) |
| 369 | pullDownAllGems(boardCopy) |
| 370 | |
| 371 | dropSlots = [] |
| 372 | for i in range(BOARDWIDTH): |
| 373 | dropSlots.append([]) |
| 374 | |
| 375 | # count the number of empty spaces in each column on the board |
| 376 | for x in range(BOARDWIDTH): |
| 377 | for y in range(BOARDHEIGHT-1, -1, -1): # start from bottom, going up |
| 378 | if boardCopy[x][y] == EMPTY_SPACE: |
| 379 | possibleGems = list(range(len(GEMIMAGES))) |
| 380 | for offsetX, offsetY in ((0, -1), (1, 0), (0, 1), (-1, 0)): |
| 381 | # Narrow down the possible gems we should put in the |
| 382 | # blank space so we don't end up putting an two of |
| 383 | # the same gems next to each other when they drop. |
| 384 | neighborGem = getGemAt(boardCopy, x + offsetX, y + offsetY) |
| 385 | if neighborGem != None and neighborGem in possibleGems: |
| 386 | possibleGems.remove(neighborGem) |
| 387 | |
| 388 | newGem = random.choice(possibleGems) |
| 389 | boardCopy[x][y] = newGem |
| 390 | dropSlots[x].append(newGem) |
| 391 | return dropSlots |
| 392 | |
| 393 | |
| 394 | def findMatchingGems(board): |
no test coverage detected