| 233 | |
| 234 | |
| 235 | def getSwappingGems(board, firstXY, secondXY): |
| 236 | # If the gems at the (X, Y) coordinates of the two gems are adjacent, |
| 237 | # then their 'direction' keys are set to the appropriate direction |
| 238 | # value to be swapped with each other. |
| 239 | # Otherwise, (None, None) is returned. |
| 240 | firstGem = {'imageNum': board[firstXY['x']][firstXY['y']], |
| 241 | 'x': firstXY['x'], |
| 242 | 'y': firstXY['y']} |
| 243 | secondGem = {'imageNum': board[secondXY['x']][secondXY['y']], |
| 244 | 'x': secondXY['x'], |
| 245 | 'y': secondXY['y']} |
| 246 | highlightedGem = None |
| 247 | if firstGem['x'] == secondGem['x'] + 1 and firstGem['y'] == secondGem['y']: |
| 248 | firstGem['direction'] = LEFT |
| 249 | secondGem['direction'] = RIGHT |
| 250 | elif firstGem['x'] == secondGem['x'] - 1 and firstGem['y'] == secondGem['y']: |
| 251 | firstGem['direction'] = RIGHT |
| 252 | secondGem['direction'] = LEFT |
| 253 | elif firstGem['y'] == secondGem['y'] + 1 and firstGem['x'] == secondGem['x']: |
| 254 | firstGem['direction'] = UP |
| 255 | secondGem['direction'] = DOWN |
| 256 | elif firstGem['y'] == secondGem['y'] - 1 and firstGem['x'] == secondGem['x']: |
| 257 | firstGem['direction'] = DOWN |
| 258 | secondGem['direction'] = UP |
| 259 | else: |
| 260 | # These gems are not adjacent and can't be swapped. |
| 261 | return None, None |
| 262 | return firstGem, secondGem |
| 263 | |
| 264 | |
| 265 | def getBlankBoard(): |