Exemple #1
0
 def determine_new_goals(self, robo_coord: Coordinate, robot: BuilderState):
     """Determines the next goal if needed, returns if the scaffolding should update"""
     self.goal_stack = self.goal_stacks[self.index]
     next_goal = self.goal_stack[-1]
     if next_goal.coord == self.cache and next_goal.type.is_pick():
         if next_goal.type.is_build():
             self.sim_state.b_blocks.add(self.cache)
         else:
             self.sim_state.s_blocks[self.cache] = ScaffoldState()
 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)
    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
Exemple #5
0

def get_next_coord() -> Coordinate:
    global i
    next_coord = Coordinate(i % 10, i // 10)
    i += 1
    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
from roboscaffold_sim.state.simulation_state import SimulationState
from roboscaffold_sim.veiw.basic_player import BasicPlayer

i = 0


def get_next_coord() -> Coordinate:
    global i
    next_coord = Coordinate(i % 10, i // 10)
    i += 1
    return next_coord


s_blocks = {
    # row 0
    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),

    # row 1
    get_next_coord(): ScaffoldState(SInstruction.NONE),
    get_next_coord(): ScaffoldState(SInstruction.STOP),
    get_next_coord(): ScaffoldState(SInstruction.STOP),
    get_next_coord(): ScaffoldState(SInstruction.NONE),