def pick(self, block_coord: Coordinate, robot: BuilderState):

        if block_coord in self.sim_state.s_blocks:
            del self.sim_state.s_blocks[block_coord]
            robot.block = HeldBlock.SCAFFOLD
        elif block_coord in self.sim_state.b_blocks:
            self.sim_state.b_blocks.remove(block_coord)
            robot.block = HeldBlock.BUILD
        else:
            raise RobotActionError(
                f'Attempting to pick an empty block at {block_coord}')
    def create_base_sim(strat: ClassVar[BasicStrategy],
                        target: CoordinateList = list()):
        sim_state = SimulationState()

        sim_state.s_blocks[Coordinate(0, 0)] = ScaffoldState(SInstruction.STOP)
        sim_state.robots[Coordinate(0, 0)] = BuilderState()
        sim_state.target_structure = target

        sim = BasicAnalyzerSimulation(sim_state, strat)
        sim.strategy.cache = Down
        return sim
    def drop(self, block_coord: Coordinate, robot: BuilderState):
        if robot.block is HeldBlock.NONE:
            raise RobotActionError('Cannot drop NONE Block')

        sim_state = self.sim_state
        if block_coord in sim_state.b_blocks or block_coord in sim_state.s_blocks:
            raise RobotActionError('Block already present')

        if robot.block is HeldBlock.BUILD:
            self.sim_state.b_blocks.add(block_coord)
        elif robot.block is HeldBlock.SCAFFOLD:
            self.sim_state.s_blocks[block_coord] = ScaffoldState()

        robot.block = HeldBlock.NONE
Ejemplo n.º 4
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.º 5
0
    return next_coord


states = SimulationStateList.create_with_empty_states(400)

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

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 = {}
    get_next_coord(): ScaffoldState(SInstruction.NONE),
    get_next_coord(): ScaffoldState(SInstruction.STOP),
    get_next_coord(): ScaffoldState(SInstruction.STOP),
    get_next_coord(): ScaffoldState(SInstruction.NONE),

    # row 9
    get_next_coord(): ScaffoldState(SInstruction.DRIVE_RIGHT),
    get_next_coord(): ScaffoldState(SInstruction.NONE),
    get_next_coord(): ScaffoldState(SInstruction.NONE),
    get_next_coord(): ScaffoldState(SInstruction.DRIVE_RIGHT),
    get_next_coord(): ScaffoldState(SInstruction.STOP),
    get_next_coord(): ScaffoldState(SInstruction.STOP),
    get_next_coord(): ScaffoldState(SInstruction.DRIVE_RIGHT),
    get_next_coord(): ScaffoldState(SInstruction.NONE),
    get_next_coord(): ScaffoldState(SInstruction.NONE),
    get_next_coord(): ScaffoldState(SInstruction.DRIVE_RIGHT),
}

sim = SimulationState()
sim.s_blocks = s_blocks

robot = BuilderState()
robot.direction = Direction.EAST
robot.block = HeldBlock.BUILD
sim.robots = {Coordinate(1, 0): copy.copy(robot)}

root = tk.Tk()
player = BasicPlayer(root, sim)
player.grid()
root.mainloop()