def shiftRight(grid, rnd, value): g = [] idxs = [] for idx, r in enumerate(grid): if row.canShiftRight(r): idxs.append(idx) g.append(row.shiftRight(r)) else: g.append(row.copy(r)) if len(idxs) > 0: g[idxs[int(rnd * len(idxs))]][0] = value return g
def canShiftRight(grid): for r in grid: if row.canShiftRight(r): return True return False