def main(): r = RandomizedQueue() print(r) r.add(Item('One', 10)) r.add(Item('Two', 10)) r.add(Item('Three', 10)) r.add(Item('Four', 10)) r.add(Item('Five', 10)) print(r) r.remove() print(r) for item in r: print(f'item: {item}')
def make_random_move(self): """ Returns a move to make on the Minesweeper board. Should choose randomly among cells that: 1) have not already been chosen, and 2) are not known to be mines """ random = set() for i in range(self.height): for j in range(self.width): if (i, j) not in self.moves_made and (i, j) not in self.mines: random.add((i, j)) if len(random) != 0: return list(random)[randint(0, len(random) - 1)] return None
def rle2coords(rle): n = '' e = '' x = 0 y = 0 r = cca.Pattern() for c in rle: if c.isdigit(): n += c else: if n == '': n = 1 e += c * int(n) n = '' for c in e: if c == 'o' or c == 'b': if c == 'o': r.add((x, y)) x += 1 elif c == '$': y += 1 x = 0 return r