- if (
- (nb < 16 or r + s + t + u + v + w + x + y > 0)
- and (s == 0 or r + t > 0)
- and (u == 0 or t + v > 0)
- and (w == 0 or x + v > 0)
- and (y == 0 or x + r > 0)
- ):
- # if r+s+t+u+v+w+x+y==0:
- Z[i, j] = 1
- nb += 1
-
- if nb == self.height * self.width // 2:
- break
-
- if nb == self.height * self.width // 2:
- break
-
- M = Z.clone()
- Z[i0, j0] = 2
- X[...] = (Z[1:-1, 1:-1] == 1) * c[0] + (Z[1:-1, 1:-1] == 2) * c[1]
-
- for _ in range(self.height + self.width):
- Z[1:-1, 1:-1] = Z[1:-1, 1:-1].maximum(
- torch.maximum(
- torch.maximum(Z[0:-2, 1:-1], Z[2:, 1:-1]),
- torch.maximum(Z[1:-1, 0:-2], Z[1:-1, 2:]),
- )
+ while True:
+ i, j = (
+ torch.randint(self.height // 2, (1,)).item(),
+ torch.randint(self.width // 2, (1,)).item(),