|
@@ -341,11 +341,11 @@ def generate_outofbounds_random_karel(canvas, side:str):
|
|
|
centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
centre_y = int(0 - size / 2 - 1)
|
|
centre_y = int(0 - size / 2 - 1)
|
|
|
case "right":
|
|
case "right":
|
|
|
- centre_x = int(0 + size / 2 + 1)
|
|
|
|
|
|
|
+ centre_x = int(canvas.width + size / 2 + 1)
|
|
|
centre_y = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
centre_y = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
case "bottom":
|
|
case "bottom":
|
|
|
centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
- centre_y = int(0 + size / 2 + 1)
|
|
|
|
|
|
|
+ centre_y = int(canvas.height + size / 2 + 1)
|
|
|
|
|
|
|
|
# Generate random values
|
|
# Generate random values
|
|
|
orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])
|
|
orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])
|
|
@@ -354,7 +354,7 @@ def generate_outofbounds_random_karel(canvas, side:str):
|
|
|
return draw_karel(canvas, centre_x, centre_y, size, orientation, "random", "random", transparent)
|
|
return draw_karel(canvas, centre_x, centre_y, size, orientation, "random", "random", transparent)
|
|
|
|
|
|
|
|
# Draw a random Karel on the canvas
|
|
# Draw a random Karel on the canvas
|
|
|
-def generate_random_karel(canvas, centre_x="random", centre_y="random", size="random"):
|
|
|
|
|
|
|
+def generate_random_karel(canvas, centre_x="random", centre_y="random", size="random", orientation="random", transparent="random"):
|
|
|
if size == "random":
|
|
if size == "random":
|
|
|
size = determine_random_size(canvas)
|
|
size = determine_random_size(canvas)
|
|
|
|
|
|
|
@@ -364,8 +364,11 @@ def generate_random_karel(canvas, centre_x="random", centre_y="random", size="ra
|
|
|
if centre_y == "random":
|
|
if centre_y == "random":
|
|
|
centre_y = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
centre_y = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
|
|
|
|
|
- orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])
|
|
|
|
|
- transparent = random.choice((True, False, False, False))
|
|
|
|
|
|
|
+ if orientation == "random":
|
|
|
|
|
+ orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])
|
|
|
|
|
+
|
|
|
|
|
+ if transparent == "random":
|
|
|
|
|
+ transparent = random.choice((True, False, False, False))
|
|
|
|
|
|
|
|
return draw_karel(canvas, centre_x, centre_y, size, orientation, "random", "random", transparent)
|
|
return draw_karel(canvas, centre_x, centre_y, size, orientation, "random", "random", transparent)
|
|
|
|
|
|
|
@@ -416,6 +419,8 @@ def draw_karel(
|
|
|
top_operand = operator.sub # Top / Left
|
|
top_operand = operator.sub # Top / Left
|
|
|
right_operand = operator.sub # Left / Top
|
|
right_operand = operator.sub # Left / Top
|
|
|
bottom_operand = operator.add # Bottom / Right
|
|
bottom_operand = operator.add # Bottom / Right
|
|
|
|
|
+ case _:
|
|
|
|
|
+ logger.error(f"Invalid orientation: {orientation}")
|
|
|
|
|
|
|
|
""" Coords case
|
|
""" Coords case
|
|
|
X and Y need to be swapped in case of a North or South facing Karel, yet the original vlaues have to be returned. (To prevent diagonal relative translation)
|
|
X and Y need to be swapped in case of a North or South facing Karel, yet the original vlaues have to be returned. (To prevent diagonal relative translation)
|
|
@@ -700,11 +705,11 @@ def generate_outofbounds_random_beeper(canvas, side:str):
|
|
|
centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
centre_y = int(0 - size / 2 - 1)
|
|
centre_y = int(0 - size / 2 - 1)
|
|
|
case "right":
|
|
case "right":
|
|
|
- centre_x = int(0 + size / 2 + 1)
|
|
|
|
|
|
|
+ centre_x = int(canvas.width + size / 2 + 1)
|
|
|
centre_y = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
centre_y = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
case "bottom":
|
|
case "bottom":
|
|
|
centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
- centre_y = int(0 + size / 2 + 1)
|
|
|
|
|
|
|
+ centre_y = int(canvas.height + size / 2 + 1)
|
|
|
|
|
|
|
|
# Generate random values
|
|
# Generate random values
|
|
|
orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])
|
|
orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])
|