1
0
Просмотр исходного кода

bugfix: south/east out of bounds | extra error catching

tBKwtWS 1 месяц назад
Родитель
Сommit
f387cf6e5d
1 измененных файлов с 12 добавлено и 7 удалено
  1. 12 7
      karel_asset.py

+ 12 - 7
karel_asset.py

@@ -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_y = int(0 - size / 2 - 1)
         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))
         case "bottom":
             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
     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)
     
 # 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":
         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":
         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)
 
@@ -416,6 +419,8 @@ def draw_karel(
             top_operand = operator.sub      # Top / Left
             right_operand = operator.sub    # Left / Top
             bottom_operand = operator.add   # Bottom / Right
+        case _:
+            logger.error(f"Invalid orientation: {orientation}")
     
     """ 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)
@@ -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_y = int(0 - size / 2 - 1)
         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))
         case "bottom":
             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
     orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])