# Constants
GRID_SIZE = 10
# Helper Functions
def get_pos():
# Get the current position of the drone.
return get_pos_x(), get_pos_y()
def custom_move(direction):
# A function that moves the robot in the specified direction (East, West, North, South)
if direction == "East":
return move("East")
elif direction == "West":
return move("West")
elif direction == "North":
return move("North")
elif direction == "South":
return move("South")
return False # Return False if the direction is invalid
def move_to(x, y):
# Move the drone to the specified (x, y) position using custom_move function.
current_x, current_y = get_pos()
# Move horizontally (East/West) to the target position
while current_x != x:
if current_x < x:
if custom_move("East"):
current_x += 1
else:
break
elif current_x > x:
if custom_move("West"):
current_x -= 1
else:
break
# Move vertically (North/South) to the target position
while current_y != y:
if current_y < y:
if custom_move("North"):
current_y += 1
else:
break
elif current_y > y:
if custom_move("South"):
current_y -= 1
else:
break
def plant_entity(entity_type):
# Plant the specified entity at the current position.
if entity_type == "Entities.Hay":
print("Planting hay...")
plant_hay()
elif entity_type == "Entities.Carrots":
print("Planting carrots...")
plant_carrots_x_pattern()
elif entity_type == "Entities.Pumpkin":
print("Planting pumpkins...")
plant_super_pumpkin()
def till_soil():
# Till the soil at the current position.
print("Tilling soil...")
till()
# Task Functions
def plant_hay():
# Fill the entire 10x10 grid with hay.
for x in range(GRID_SIZE):
for y in range(GRID_SIZE):
move_to(x, y)
plant_entity("Entities.Hay")
def plant_carrots_x_pattern():
# Plant carrots in an 'X' pattern across the grid.
for i in range(GRID_SIZE):
# Plant along the primary diagonal
move_to(i, i)
plant_entity("Entities.Carrots")
# Plant along the secondary diagonal
move_to(i, GRID_SIZE - 1 - i)
plant_entity("Entities.Carrots")
def plant_super_pumpkin():
# Plant pumpkins in a 3x3 square at the center of the grid.
for x in range(4, 7): # Rows 4 to 6 (centered in 10x10 grid)
for y in range(4, 7): # Columns 4 to 6
move_to(x, y)
plant_entity("Entities.Pumpkin")
def till_itp100():
# Till the soil to form the text 'ITP100' in the grid.
# Tilling 'I'
for y in range(1, 9):
move_to(1, y)
till_soil()
# Tilling 'T'
for x in range(3, 7):
move_to(x, 8)
till_soil()
for y in range(1, 8):
move_to(5, y)
till_soil()
# Tilling 'P'
for x in range(7, 9):
move_to(x, 8)
till_soil()
for y in range(4, 8):
move_to(8, y)
till_soil()
for x in range(7, 9):
move_to(x, 4)
till_soil()
# Tilling '100'
for x in range(1, 4):
move_to(x + 6, 1)
till_soil()
for x in range(1, 4):
move_to(x + 6, 6)
till_soil()
for y in range(1, 7):
move_to(9, y)
till_soil()
# Main Execution
def main():
# Perform all tasks sequentially: plant hay, plant carrots, plant pumpkins, and till 'ITP100'.
print("Starting grid tasks...")
plant_hay() # Step 1: Fill grid with hay
plant_carrots_x_pattern() # Step 2: Plant carrots in an X pattern
plant_super_pumpkin() # Step 3: Plant a super pumpkin
till_itp100() # Step 4: Till soil to form "ITP100"
# Start the program
main()
# Move horizontally (East/West) to the target position
while current_x != x:
if current_x < x:
if custom_move("East"):
current_x += 1
else:
break
elif current_x > x:
if custom_move("West"):
current_x -= 1
else:
break
# Move vertically (North/South) to the target position
while current_y != y:
if current_y < y:
if custom_move("North"):
current_y += 1
else:
break
elif current_y > y:
if custom_move("South"):
current_y -= 1
else:
break
1 Like
drone just moves left and right and glitches out
Please Tell us what’s happening in your own words.
Learning to describe problems is hard, but it is an important part of learning how to code.
Also, the more you say, the more we can help!
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').