Guest User

FarmerWasReplaceAllCode

a guest
May 20th, 2026
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.45 KB | None | 0 0
  1. FarmLoops file:
  2.  
  3. import FarmerManager
  4. import FarmFunctions
  5. import PumpkinUtils
  6. import CactusUtils
  7. import FarmPlan
  8. import Utils
  9.  
  10. dead_patches = {}
  11.  
  12. ### Multi drone ###
  13.  
  14. def MultiFarmerPumpkinPatchLoop():
  15. for y in range(get_world_size()):
  16. if spawn_drone(HorizontalFarm):
  17. move(North)
  18. return
  19.  
  20.  
  21. def spawn_drone_wrapper(function, companion_x, companion_y, companion_type):
  22. def func():
  23. return function(companion_x, companion_y, companion_type)
  24. return func
  25.  
  26.  
  27. def CompanionFarmingLoop():
  28. for x in range(get_world_size()):
  29. for y in range(get_world_size()):
  30. # plant within our normal FarmPlan
  31. CheckeredFarm()
  32. if get_companion() != None:
  33. companion_type, pos = get_companion()
  34. companion_x, companion_y = pos
  35. #print("Spawning companion drone for: ", companion_type, " at ", pos)
  36. if spawn_drone(spawn_drone_wrapper(CompanionFarm, companion_x, companion_y, companion_type)):
  37. move(North)
  38. continue
  39. move(North)
  40. move(East)
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. def CompanionFarm(companion_x, companion_y, companion_type):
  48. FarmerManager.MoveFarmer(companion_x, companion_y)
  49. FarmFunctions.Farm()
  50. if companion_type != Entities.Grass:
  51. FarmFunctions.TillableFarm(companion_type)
  52.  
  53.  
  54. def HorizontalFarm():
  55. basic_farm = True
  56. for x in range(get_world_size()):
  57. x, y = Utils.get_pos()
  58. if basic_farm == True:
  59. if Utils.is_even(x):
  60. if Utils.is_even(y):
  61. #FarmFunctions.TillableFarm(Entities.Carrot)
  62. FarmFunctions.Farm()
  63. else:
  64. FarmFunctions.TillableFarm(Entities.Sunflower)
  65. else:
  66. if Utils.is_even(y):
  67. FarmFunctions.TillableFarm(Entities.Tree)
  68. else:
  69. if y % 3 == 1:
  70. FarmFunctions.TillableFarm(Entities.Carrot)
  71. else:
  72. FarmFunctions.Farm()
  73. #FarmFunctions.TillableFarm(Entities.Sunflower)
  74. else:
  75. FarmFunctions.PumpkinFlowerFarm(x, y)
  76.  
  77. #FarmFunctions.TillableFarm(Entities.Tree, True)
  78.  
  79.  
  80. move(East)
  81. #spawn_drone(ReverseHorizontalFarm)
  82. return
  83.  
  84. def ReverseHorizontalFarm():
  85. basic_farm = True
  86. for x in range(get_world_size()):
  87. x, y = Utils.get_pos()
  88. if basic_farm == True:
  89. if Utils.is_even(x):
  90. if Utils.is_even(y):
  91. FarmFunctions.TillableFarm(Entities.Carrot)
  92. else:
  93. FarmFunctions.TillableFarm(Entities.Sunflower)
  94. else:
  95. if Utils.is_even(y):
  96. FarmFunctions.TillableFarm(Entities.Tree)
  97. else:
  98. if y % 3 == 1:
  99. FarmFunctions.TillableFarm(Entities.Carrot)
  100. else:
  101. FarmFunctions.Farm()
  102. else:
  103. FarmFunctions.PumpkinFlowerFarm(x, y)
  104.  
  105. move(West)
  106. return
  107.  
  108. def CheckeredFarm():
  109. x, y = Utils.get_pos()
  110. if Utils.is_even(x):
  111. if Utils.is_even(y):
  112. FarmFunctions.TillableFarm(Entities.Carrot)
  113. else:
  114. FarmFunctions.TillableFarm(Entities.Sunflower)
  115. else:
  116. if Utils.is_even(y):
  117. FarmFunctions.TillableFarm(Entities.Tree)
  118. else:
  119. if y % 3 == 1:
  120. FarmFunctions.TillableFarm(Entities.Carrot)
  121. else:
  122. FarmFunctions.Farm()
  123.  
  124. ### single drone
  125. def PumpkinPatchLoop():
  126. FarmerManager.MoveFarmer(0,0)
  127. for x in range(get_world_size()):
  128. for y in range(get_world_size()):
  129. FarmingUtils.PumpkinFlowerFarm(x, y)
  130. move(North)
  131. move(East)
  132.  
  133. for x in range(get_world_size()):
  134. for y in range(get_world_size()):
  135. if get_entity_type() == Entities.Sunflower:
  136. FarmFunctions.TillableFarm(Entities.Sunflower)
  137. if get_entity_type() == Entities.Dead_Pumpkin:
  138. FarmFunctions.PumpkinFlowerFarm(x, y)
  139. dead_patches[(x,y)] = 1
  140. move(North)
  141. move(East)
  142.  
  143. while dead_patches:
  144. patches = []
  145. for patch in dead_patches:
  146. patches.append(patch)
  147. for patch in patches:
  148. dead_patches.pop(patch)
  149. x, y = patch
  150. FarmerManager.MoveFarmer(x, y)
  151. if get_entity_type() == Entities.Dead_Pumpkin:
  152. FarmFunctions.PumpkinFlowerFarm(x, y)
  153. dead_patches[(x,y)] = 1
  154.  
  155. CactusUtils.sort_cactus()
  156.  
  157. for name in FarmPlan.pumpkin_patches:
  158. (x0, y0, x1, y1) = FarmPlan.pumpkin_patches[name]
  159. FarmerManager.MoveFarmer(x0, y0)
  160. FarmFunctions.Farm()
  161.  
  162.  
  163. def FarmLoop():
  164. for x in range(get_world_size()):
  165. for y in range(get_world_size()):
  166. if Utils.is_even(y) and Utils.is_even(x):
  167. #FarmFunctions.Farm()
  168. FarmFunctions.TillableFarm(Entities.Carrot)
  169. elif Utils.is_odd(y) and Utils.is_odd(x):
  170. if y % 3 == 1 or y % 5 == 1:
  171. FarmFunctions.TillableFarm(Entities.Carrot)
  172. #FarmFunctions.Farm()
  173. else:
  174. FarmFunctions.TillableFarm(Entities.Carrot)
  175. #FarmFunctions.Farm()
  176. else:
  177. FarmFunctions.TillableFarm(Entities.Carrot)
  178. move(North)
  179. move(East)
  180.  
  181.  
  182.  
  183.  
  184. CactusUtils File:
  185. cactus_sizes = {}
  186.  
  187.  
  188. def sort_cactus():
  189. for (type, x0, y0, x1, y1) in FarmPlan.cactus_highways:
  190. cactuses = []
  191. for x in range(x0, x1 + 1):
  192. cactuses.append((x, y0))
  193.  
  194. def size_at(key):
  195. return cactus_sizes[key]
  196.  
  197. n = len(cactuses)
  198. if n <= 1:
  199. return
  200.  
  201. FarmerManager.MoveFarmer(x0 + 1, y0)
  202.  
  203. while True:
  204. swapped = False
  205. comparisons = max(0, n - 1)
  206. for i in range(1, comparisons + 1):
  207. left_key = cactuses[i - 1]
  208. right_key = cactuses[i]
  209.  
  210. if size_at(left_key) > size_at(right_key):
  211. swap(West)
  212. swapped = True
  213. swap_val = Utils.swap_values(cactuses[i - 1], cactuses[i])
  214. cactuses[i - 1], cactuses[i] = swap_val
  215. move(East)
  216. else:
  217. move(East)
  218.  
  219. n -= 1
  220. if not swapped:
  221. break
  222. for _ in range(comparisons):
  223. move(West)
  224.  
  225. def record_sizes(x, y):
  226. cactus_sizes[(x,y)] = measure()
  227.  
  228.  
  229.  
  230. PumpkinUtils File:
  231.  
  232. import FarmPlan
  233. import Utils
  234.  
  235. patch_2_pumpkinIds = {}
  236.  
  237. def end_of_patch(x,y, patch):
  238. _, x0, y0, x1,y1 = patch
  239. if x == x1:
  240. return True
  241. return False
  242.  
  243.  
  244. def check_pumpkin_patch(x, y):
  245. global patch_2_pumpkinIds
  246. if get_entity_type() == Entities.Pumpkin:
  247. if FarmPlan.in_farm_plan(x, y, FarmPlan.pumpkin_patches):
  248. patch = FarmPlan.get_patch(x, y)
  249. if patch != None:
  250. id = measure()
  251. if patch not in patch_2_pumpkinIds:
  252. patch_2_pumpkinIds[patch] = set()
  253. patch_2_pumpkinIds[patch].add(id)
  254. else:
  255. patch_2_pumpkinIds[patch].add(id)
  256. if end_of_patch(x, y, patch):
  257. if len(patch_2_pumpkinIds[patch]) == 1:
  258. FarmingUtils.Farm()
  259.  
  260.  
  261.  
  262. FarmerManager File:
  263.  
  264. import Utils
  265.  
  266. HATS = [Hats.Brown_Hat,
  267. Hats.Green_Hat, Hats.Purple_Hat]
  268.  
  269.  
  270. def ChangeHat():
  271. change_hat(HATS[random() * len(HATS)])
  272.  
  273.  
  274. def determine_move_xtype(diff_x):
  275. if diff_x > 0:
  276. return West
  277. elif diff_x < 0:
  278. return East
  279.  
  280.  
  281. def determine_move_ytype(diff_y):
  282. if diff_y > 0:
  283. return South
  284. elif diff_y < 0:
  285. return North
  286.  
  287.  
  288. def MoveFarmer(target_x, target_y):
  289. farmer_x, farmer_y = Utils.get_pos()
  290.  
  291. diff_x = farmer_x - target_x
  292. diff_y = farmer_y - target_y
  293.  
  294. x_dir = determine_move_xtype(diff_x)
  295. y_dir = determine_move_ytype(diff_y)
  296.  
  297. if x_dir != None:
  298. for _ in range(abs(diff_x)):
  299. move(x_dir)
  300.  
  301. if y_dir != None:
  302. for _ in range(abs(diff_y)):
  303. move(y_dir)
  304.  
  305.  
  306. FarmFunctions File:
  307.  
  308. import FarmingUtils
  309. import PumpkinUtils
  310. import FarmPlan
  311.  
  312.  
  313. def Farm():
  314. if can_harvest():
  315. harvest()
  316.  
  317. def TillableFarm(entity, fertilize=False):
  318. Farm()
  319. FarmingUtils.till_water_plant(entity, fertilize)
  320.  
  321.  
  322. def BushFarm():
  323. Farm()
  324. if get_entity_type() not in FarmPlan.farmed_entities:
  325. plant(Entities.Bush)
  326.  
  327. def PumpkinFarm():
  328. FarmingUtils.till_water_plant(Entities.Pumpkin)
  329.  
  330.  
  331. def PumpkinFlowerFarm(x, y):
  332. if PumpkinPatchFarm(x, y):
  333. PumpkinUtils.check_pumpkin_patch(x, y)
  334. return
  335.  
  336. if CactusHighwayFarm(x, y):
  337. return
  338.  
  339. if SunflowerHighwayFarm(x, y):
  340. return
  341.  
  342. TillableFarm(Entities.Carrot)
  343.  
  344. def PumpkinPatchFarm(x, y):
  345. if FarmPlan.in_farm_plan(x,y, FarmPlan.pumpkin_patches):
  346. TillableFarm(Entities.Pumpkin, True)
  347. return True
  348. return False
  349.  
  350. def SunflowerHighwayFarm(x, y):
  351. if FarmPlan.in_farm_plan(x,y, FarmPlan.sunflower_highways):
  352. TillableFarm(Entities.Sunflower)
  353. return True
  354. return False
  355.  
  356. def CactusHighwayFarm(x, y):
  357. if FarmPlan.in_farm_plan(x,y, FarmPlan.cactus_highways):
  358. TillableFarm(Entities.Cactus)
  359. return True
  360. return False
  361.  
  362.  
  363.  
  364. FarmingUtils File:
  365.  
  366. import FarmPlan
  367. import PumpkinUtils
  368. import CactusUtils
  369. import FarmerManager
  370. import Utils
  371.  
  372.  
  373. def water():
  374. if get_water() <= 0.5:
  375. use_item(Items.Water)
  376.  
  377.  
  378. def till_water_plant(entity, fertilize):
  379. if get_ground_type() != Grounds.Soil:
  380. till()
  381. if get_ground_type() == Grounds.Soil:
  382. water()
  383. plant(entity)
  384. if fertilize:
  385. use_item(Items.Fertilizer)
  386. if get_entity_type() == Entities.Cactus:
  387. x, y = Utils.get_pos()
  388. CactusUtils.record_sizes(x,y)
  389.  
  390.  
  391.  
  392.  
  393.  
  394. main file:
  395. import FarmLoops
  396. import FarmerManager
  397. import MazeSolver
  398. import Utils
  399.  
  400. clear()
  401.  
  402. def analyze_runs(runs):
  403. total_time = 0
  404. total_chests_solved = 0
  405. for run in runs:
  406. total_time += runs[run]["time"]
  407. total_chests_solved += runs[run]["chests_solved"]
  408.  
  409. avg_time = total_time / len(runs)
  410. avg_chests = total_chests_solved / len(runs)
  411. move(South)
  412. move(South)
  413. print("Over the course of ", len(runs), " runs,")
  414. move(South)
  415. move(South)
  416. print("the drones found ", total_chests_solved, " chests.")
  417. move(South)
  418. move(South)
  419. print("It took an average", avg_time, " seconds")
  420. move(South)
  421. move(South)
  422. print("to find ", avg_chests , " chests per run.")
  423.  
  424.  
  425.  
  426. def spawn_drone_wrapper(function, x, y):
  427. def func():
  428. return function(x, y)
  429. return func
  430.  
  431.  
  432.  
  433.  
  434. def maze_loop_multi(x, y):
  435. FarmerManager.MoveFarmer(x, y)
  436. first_flag = False
  437. while True:
  438. if not first_flag:
  439. if x == 24 and y == 24:
  440. MazeSolver.SpawnMaze()
  441. first_flag = True
  442. else:
  443. do_a_flip()
  444. MazeSolver.SpawnMaze()
  445.  
  446. if get_entity_type() != Entities.Hedge:
  447. continue
  448.  
  449. MazeSolver.SolveMaze()
  450.  
  451.  
  452.  
  453.  
  454.  
  455. DRONE_LOCATIONS = [
  456. (7, 24),
  457. (7, 7),
  458. (24, 7),
  459. (24, 24),
  460. (16, 16)
  461. ]
  462.  
  463. def better_maze_loop():
  464. for location in DRONE_LOCATIONS:
  465. x,y = location
  466. spawn_drone(spawn_drone_wrapper(maze_loop_multi, x,y))
  467.  
  468.  
  469.  
  470. def MazeLoop():
  471. #set_execution_speed(1)
  472. runs = {}
  473. i = 0
  474. while True:
  475.  
  476.  
  477. start_time = get_time()
  478. MazeSolver.SpawnMaze()
  479. chests_solved = MazeSolver.SolveMaze()
  480. total_time = get_time() - start_time
  481. print("total time: ", total_time)
  482. #move(South)
  483. #move(South)
  484. print("chests found: ", chests_solved)
  485. runs[i] = {"time": total_time, "chests_solved": chests_solved}
  486. i+=1
  487.  
  488.  
  489. analyze_runs(runs)
  490.  
  491. def CompanionLoop():
  492. farmer_count = 6
  493. while True:
  494. for farmer in range(farmer_count):
  495. spawn_drone(FarmLoops.CompanionFarmingLoop)
  496. for i in range(farmer):
  497. move(West)
  498.  
  499. better_maze_loop()
  500. #MazeLoop()
  501. #while True:
  502. # FarmLoops.MultiFarmerPumpkinPatchLoop()
  503.  
  504.  
  505.  
  506.  
  507. Maze Solver file:
  508. import FarmerManager
  509. import Utils
  510. import MazeUtils
  511.  
  512. maze_map = {}
  513. path_taken = []
  514. chest_positions = set()
  515. last_seen_chest_count = len(chest_positions)
  516. current_generation = 0
  517. last_hint = None
  518.  
  519. def get_hint_cached():
  520. global last_hint
  521. hint = safe_treasure_hint()
  522. if hint != None:
  523. last_hint = hint
  524. return last_hint
  525.  
  526. def reset_state():
  527. global maze_map
  528. global path_taken
  529. global current_generation
  530. global last_hint
  531. maze_map = {}
  532. path_taken = []
  533. current_generation += 1
  534. last_hint = None
  535.  
  536. def is_deadend(x,y):
  537. if (x,y) in maze_map:
  538. return maze_map[(x,y)]["dead_end"] == True or maze_map[(x,y)]["dead_path"] == True
  539. return False
  540.  
  541. def was_visited(x, y):
  542. if (x, y) in maze_map and maze_map[(x, y)]["visited"] == True :
  543. return True
  544. return False
  545.  
  546. def collect_treasure():
  547. global chest_positions
  548. if get_entity_type() == Entities.Treasure:
  549. if len(chest_positions) >= MazeUtils.NUM_CHESTS:
  550. harvest()
  551. chest_positions = set()
  552. return True
  553. else:
  554. if MazeUtils.CUSTOM_MAZE_SIZE == 0:
  555. substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1)
  556. else:
  557. substance = MazeUtils.CUSTOM_MAZE_SIZE
  558. if not use_item(Items.Weird_Substance, substance):
  559. harvest()
  560. chest_positions = set()
  561. return True
  562. return False
  563.  
  564. def is_hedge():
  565. return get_entity_type() == Entities.Hedge
  566.  
  567. def safe_treasure_hint():
  568. if not is_hedge():
  569. return None
  570. hint = measure()
  571. if hint == None:
  572. return None
  573. if len(hint) == 2:
  574. return (hint[0], hint[1])
  575. return None
  576.  
  577. def evaluate_position():
  578. if not is_hedge():
  579. return None
  580. hint = get_hint_cached()
  581. if hint == None:
  582. return None
  583. chest_x, chest_y = hint
  584. x, y = Utils.get_pos()
  585. score = Utils.manhattan(x, y, chest_x, chest_y)
  586. return score
  587.  
  588. def spawn_in_direction(directions):
  589. global maze_map
  590. global chest_positions
  591. global current_generation
  592. best_dir = choose_direction(directions)
  593. other_dirs = []
  594. for dir in directions:
  595. if dir != best_dir:
  596. other_dirs.append(dir)
  597. drone_ids = []
  598. for dir in other_dirs:
  599. current_generation += 1
  600. drone_id = spawn_drone(spawn_drone_wrapper(SolveMazeShadowClone, maze_map, dir, chest_positions, current_generation))
  601. drone_ids.append(drone_id)
  602. return best_dir, drone_ids
  603.  
  604.  
  605. def log_dir_and_move(direction):
  606. global path_taken
  607. if direction == None:
  608. return
  609. path_taken.append(direction)
  610. move(direction)
  611. global last_hint
  612. last_hint = None
  613.  
  614. def filter_visited(available_directions):
  615. unvisited = []
  616. for dir in available_directions:
  617. x, y = Utils.dir_increment(dir)
  618. if not was_visited(x,y) and not is_deadend(x, y):
  619. unvisited.append(dir)
  620. return unvisited
  621.  
  622. def choose_n_move(unvisited):
  623. direction = choose_direction(unvisited)
  624. if direction == None:
  625. return True
  626. log_dir_and_move(direction)
  627. return True
  628.  
  629. def spawn_n_move(unvisited):
  630. direction, drone_ids = spawn_in_direction(unvisited)
  631. if direction == None:
  632. return True
  633. log_dir_and_move(direction)
  634. return True
  635.  
  636. def chest_moved():
  637. global last_seen_chest_count
  638. global chest_positions
  639. temp_chest_count = last_seen_chest_count
  640. last_seen_chest_count = len(chest_positions)
  641. return temp_chest_count != last_seen_chest_count
  642.  
  643. def spawn_drone_wrapper(function, arg_map, direction, chest_positions, gen):
  644. def func():
  645. return function(arg_map, direction, chest_positions, gen)
  646. return func
  647.  
  648. def map_sourroundings():
  649. global chest_positions
  650. global maze_map
  651. if not is_hedge():
  652. return [], Utils.get_pos()
  653. hint = safe_treasure_hint()
  654. if hint != None and hint not in chest_positions:
  655. chest_positions.add(hint)
  656. coordinates = Utils.get_pos()
  657. connections = []
  658. for d in Utils.DIRS:
  659. if can_move(d):
  660. connections.append(d)
  661. if coordinates not in maze_map:
  662. maze_map[coordinates] = {
  663. "connections": connections,
  664. "dead_end": (len(connections) == 1),
  665. "visited": True,
  666. "dead_path": False
  667. }
  668. else:
  669. maze_map[coordinates]["connections"] = connections
  670. return connections, coordinates
  671.  
  672. def choose_direction(directions):
  673. if not is_hedge():
  674. return directions[0]
  675. hint = get_hint_cached()
  676. if hint == None:
  677. return directions[0]
  678. chest_x, chest_y = hint
  679. best_score = 1000000
  680. best_dir = directions[0]
  681. for dir in directions:
  682. x, y = Utils.dir_increment(dir)
  683. score = Utils.manhattan(x, y, chest_x, chest_y)
  684. if score < best_score:
  685. best_score = score
  686. best_dir = dir
  687. return best_dir
  688.  
  689. def SolveMaze():
  690. global maze_map
  691. global path_taken
  692. global chest_positions
  693. global last_hint
  694. reset_state()
  695. while True:
  696. chests_collected = len(chest_positions)
  697. if chests_collected >= MazeUtils.NUM_CHESTS:
  698. chest_positions = set()
  699. return chests_collected
  700. if chest_moved():
  701. reset_state()
  702. if collect_treasure():
  703. reset_state()
  704. if outside_maze():
  705. return len(chest_positions)
  706. available_directions, coordinates = map_sourroundings()
  707. unvisited = filter_visited(available_directions)
  708. if len(unvisited) >= 2:
  709. if spawn_n_move(unvisited):
  710. continue
  711. if len(unvisited) > 0:
  712. if choose_n_move(unvisited):
  713. continue
  714. if len(path_taken) == 0:
  715. return len(chest_positions)
  716. if outside_maze():
  717. return len(chest_positions)
  718. maze_map[coordinates]["dead_path"] = True
  719. last_dir = path_taken.pop()
  720. move(Utils.reverse_dir(last_dir))
  721.  
  722. def outside_maze():
  723. if get_entity_type() != Entities.Hedge and get_entity_type() != Entities.Treasure:
  724. return True
  725. return False
  726.  
  727. def SolveMazeShadowClone(map, direction, chest_poses, my_generation):
  728. global maze_map
  729. global chest_positions
  730. global path_taken
  731. global current_generation
  732. global last_hint
  733. chest_positions = chest_poses
  734. maze_map = map
  735. path_taken = []
  736. last_hint = None
  737. change_hat(FarmerManager.HATS[my_generation % len(FarmerManager.HATS)])
  738. log_dir_and_move(direction)
  739. allowed_moves = MazeUtils.ALLOWED_MOVES
  740. while True:
  741. if outside_maze():
  742. return
  743. if collect_treasure():
  744. return
  745. if allowed_moves <= 0:
  746. return
  747. available_directions, coordinates = map_sourroundings()
  748. unvisited = filter_visited(available_directions)
  749. allowed_moves -= 1
  750. score = evaluate_position()
  751. if score != None and score <= 14:
  752. allowed_moves += 50
  753. if outside_maze():
  754. return
  755. if len(unvisited) >= 2:
  756. if spawn_n_move(unvisited):
  757. continue
  758. if len(unvisited) > 0:
  759. if choose_n_move(unvisited):
  760. continue
  761. if len(path_taken) == 0:
  762. return
  763. if score > 10:
  764. return
  765.  
  766. maze_map[coordinates]["dead_path"] = True
  767. last_dir = path_taken.pop()
  768. move(Utils.reverse_dir(last_dir))
  769.  
  770.  
  771. def SpawnMaze():
  772. use_item(Items.Water)
  773. plant(Entities.Bush)
  774. use_item(Items.Fertilizer)
  775. while not can_harvest():
  776. FarmerManager.ChangeHat()
  777. if MazeUtils.CUSTOM_MAZE_SIZE == 0:
  778. substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1)
  779. else:
  780. substance = MazeUtils.CUSTOM_MAZE_SIZE
  781. use_item(Items.Weird_Substance, substance)
  782.  
  783.  
  784.  
  785. Utils File:
  786. DIRS = [North, East, South, West]
  787.  
  788. def get_pos():
  789. return(get_pos_x(), get_pos_y())
  790.  
  791. def is_even(n):
  792. return n % 2 == 0
  793.  
  794. def is_odd(n):
  795. return n % 2 != 0
  796.  
  797. def in_rect(x, y, x0, y0, x1, y1):
  798. return (x0 <= x <= x1) and (y0 <= y <= y1)
  799.  
  800. def in_vertical(x, y, x_const, y0, y1):
  801. return (x == x_const) and (y0 <= y <= y1)
  802.  
  803. def in_horizontal(x, y, y_const, x0, x1):
  804. return (y == y_const) and (x0 <= x <= x1)
  805.  
  806. def swap_values(x, y):
  807. return y, x
  808.  
  809. def reverse_dir(dir):
  810. if dir == North:
  811. return South
  812. if dir == South:
  813. return North
  814. if dir == East:
  815. return West
  816. if dir == West:
  817. return East
  818.  
  819. def dir_increment(dir, coordinates=None, x=None, y=None):
  820. if coordinates != None:
  821. x, y = coordinates
  822.  
  823. if coordinates == None and x == None:
  824. x, y = get_pos()
  825.  
  826. if dir == North:
  827. y += 1
  828. elif dir == South:
  829. y -= 1
  830. elif dir == East:
  831. x += 1
  832. elif dir == West:
  833. x -= 1
  834. return x, y
  835.  
  836. def manhattan(x1, y1, x2, y2):
  837. return abs(x1 - x2) + abs(y1 - y2)
  838.  
  839.  
  840.  
  841.  
Advertisement
Add Comment
Please, Sign In to add comment