def placetile(context, x): '''Current player places a tile at location x, determines resulting chain effects''' '''This function only ends after all resulting actions have finished, and finishes by filling in the placed tile''' context['player'][context['cp']]['tilerack'].remove(x) #determine result: # Tile has no neighbors: nothing happens if infos.filled_neighbors(context, x) == []: context['grid'][x]['filled'] = 1 return # neighors all of chain x, or some chain x and some unaffiliated: grow chain x elif len(infos.neighbor_chains(context, x)) == 1: new = infos.neighbor_chains(context, x)[0] context['grid'][x]['chain'] = new adj_chain(context, x, new) context['grid'][x]['filled'] = 1 # neighbor(s) that are all no chain: new chain elif len(infos.neighbor_chains(context, x)) == 0: newchain_at(context, x) context['grid'][x]['filled'] = 1 # neighbors of more than one chain: MERGER! elif len(infos.neighbor_chains(context, x)) > 1: merger_at(context, x) context['grid'][x]['filled'] = 1
def crawl(context, tile, chain, changed_tiles): for adj_tile in infos.filled_neighbors(context, tile): if adj_tile not in changed_tiles: context['grid'][adj_tile]['chain'] = chain changed_tiles.append(adj_tile) crawl(context, adj_tile, chain, changed_tiles)