Ejemplo n.º 1
0
 def app_remove_blockage_goal(self, goal_coord: Coordinate) -> Goal:
     p_type = GType.PLACE_SCAFFOLD
     if goal_coord.y != 0:
         extend_spine = Right
         while extend_spine in self.sim_state.s_blocks:
             extend_spine += Right
         h_coord = extend_spine + Left
         return Goal(extend_spine, p_type, h_coord, Dir.EAST)
     else:
         return Goal(self.cache, p_type, self.seed, Dir.SOUTH)
Ejemplo n.º 2
0
 def find_usable_scaffold(self) -> Goal:
     p_type = GType.PICK_SCAFFOLD
     unneeded_s_blocks = self.get_next_unneeded_block()
     if unneeded_s_blocks:
         coord_offset = Up if unneeded_s_blocks.y > 0 else Down if unneeded_s_blocks.y else Left
         p_dir = Dir.SOUTH if unneeded_s_blocks.y > 0 else Dir.NORTH if unneeded_s_blocks.y else Dir.EAST
         h_coord = unneeded_s_blocks + coord_offset
         return Goal(unneeded_s_blocks, p_type, h_coord, p_dir)
     else:
         self.sim_state.s_blocks[self.cache] = ScaffoldState()
         return Goal(self.cache, p_type, self.seed, Dir.SOUTH)
Ejemplo n.º 3
0
 def get_bridge_goal(self, next_goal: Goal) -> Goal:
     next_needed_coord = self.get_next_needed_block(next_goal.h_coord)
     if next_needed_coord.y == 0:
         h_coord = next_needed_coord + Left
         p_dir = Dir.EAST
     else:
         p_dir = Dir.SOUTH if next_goal.coord.y > 0 else Dir.NORTH
         h_coord = next_needed_coord + (Up
                                        if next_goal.coord.y > 0 else Down)
     return Goal(next_needed_coord, GType.PLACE_SCAFFOLD, h_coord, p_dir)
Ejemplo n.º 4
0
 def get_needed_block_goal(self, next_goal: Goal) -> Tuple[Goal, bool]:
     if next_goal.type is GType.PLACE_SCAFFOLD:
         return self.find_usable_scaffold(), False
     else:
         if next_goal.coord in self.sim_state.s_blocks:
             return self.app_remove_blockage_goal(next_goal.coord), True
         else:
             p_type = GType.PICK_BUILD_BLOCK
             self.sim_state.b_blocks.add(self.cache)
             return Goal(self.cache, p_type, self.seed, Dir.SOUTH), False
Ejemplo n.º 5
0
 def check_is_finished(self) -> bool:
     if len(self.goal_stack) == 0:
         struct_coord = self.get_next_unfinished_block()
         if struct_coord is None:
             self.finished = True
             return True
         else:
             h_coord = struct_coord + (Right if struct_coord.y else Left)
             dir = Dir.WEST if struct_coord.y else Dir.EAST
             new_goal = Goal(struct_coord, GType.PLACE_BUILD_BLOCK, h_coord,
                             dir)
             self.goal_stack = [new_goal]
     return False
Ejemplo n.º 6
0
    def get_place_helper_goal(self, robo_coord: Coordinate,
                              robot: BuilderState, next_goal: Goal) -> bool:
        if robot.not_holding_block():
            if self.coord_is_reachable(robo_coord, next_goal.h_coord):
                goal, recurse = self.get_needed_block_goal(next_goal)
            else:
                goal = self.get_bridge_goal(next_goal)
                recurse = True

            self.goal_stack.append(goal)
            if recurse:
                return self.get_place_helper_goal(robo_coord, robot, goal)

        elif robot.block != next_goal.get_block():
            raise GoalError('Held block does not match next goal')
        return True
Ejemplo n.º 7
0
b_blocks[get_next_coord()] = BuildingBlockState()

for direction in Direction:
    for held_block in HeldBlock:
        robot = BuilderState()
        robot.block = held_block
        robot.direction = direction
        coord = get_next_coord()
        s_blocks[coord] = ScaffoldState(SInstruction.DRIVE_RIGHT)
        robots[coord] = robot

states.states[0].s_blocks = s_blocks
states.states[0].b_blocks = b_blocks
states.states[0].robots = robots
goal = Goal(get_next_coord(), GoalType.PLACE_SCAFFOLD)
states.states[0].target_structure = [get_next_coord()]
states.states[0].goal_stack.append(goal)

s_blocks = {}
b_blocks = {}
robots = {}
for instruction in SInstruction:
    s_blocks[get_next_coord()] = ScaffoldState(instruction)

b_blocks[get_next_coord()] = BuildingBlockState()

for direction in Direction:
    for held_block in HeldBlock:
        robot = BuilderState()
        robot.block = held_block
Ejemplo n.º 8
0
state_controls.max_state = 10

s_blocks = {}
b_blocks = {}
robots = {}
for instruction in SInstruction:
    s_blocks[get_next_coord()] = ScaffoldState(instruction)

b_blocks[get_next_coord()] = BuildingBlockState()

for direction in Direction:
    for held_block in HeldBlock:
        robot = BuilderState()
        robot.block = held_block
        robot.direction = direction
        coord = get_next_coord()
        s_blocks[coord] = ScaffoldState(SInstruction.DRIVE_RIGHT)
        robots[coord] = robot

sim = SimulationState()
sim.s_blocks = s_blocks
sim.b_blocks = b_blocks
sim.robots = robots
sim.target_structure = [get_next_coord()]
board.draw_sim(sim)

goal = Goal(get_next_coord(), GoalType.PLACE_SCAFFOLD, Coordinate(0, 0),
            Direction.NORTH)
board.draw_goal(goal)
root.mainloop()
Ejemplo n.º 9
0
def create_goal(string: str) -> Goal:
    coord, gtype = string.split(':')
    coord = Coordinate.from_string(coord)
    gtype = GoalType[gtype]
    return Goal(coord, gtype, Origin, Origin)