Created
January 12, 2022 15:07
-
-
Save thunderInfy/45e6d3c25889bd1f9245a03d05c47d34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
row and col are the indices for the event cell | |
the '1' in the following line of code indicates | |
that one orb would be added in that cell | |
''' | |
queue = [(row, col, 1)] | |
while len(queue)>0: | |
row,col,val = queue.pop(0) | |
''' | |
update the orbs count and set the orbs color to be | |
the player's color | |
''' | |
state.orbs[row][col] += val | |
state.color[row][col] = turn_color | |
orbs = state.orbs[row][col] | |
degree = state.degree[row][col] | |
# an explosion of some node has happened | |
if orbs >= degree: | |
# quotient number of orbs would go to the neighbours | |
Quotient = orbs // degree | |
# remaining orbs will remain | |
state.orbs[row][col] = orbs % degree | |
# adding the neighbours to the queue because of the explosion | |
if row!=0: | |
queue.append((row-1, col, Quotient)) | |
if row!=args.M-1: | |
queue.append((row+1, col, Quotient)) | |
if col!=0: | |
queue.append((row, col-1, Quotient)) | |
if col!=args.N-1: | |
queue.append((row, col+1, Quotient)) | |
# update the player turn | |
state.turn = 'green' if state.turn == 'red' else 'red' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment