Esempio n. 1
0
    def initialise(self, initial_state):
        self.our_defender = None
        self.our_attacker = None
        if initial_state['our_defender']:
            self.our_defender = self.scene.add_robot(
                "defender", initial_state['our_defender'])
        if initial_state['our_attacker']:
            self.our_attacker = self.scene.add_robot(
                "attacker", initial_state['our_attacker'])

        self.ball = self.scene.add_ball(initial_state['ball'])
        self.p = DefencePlanner(comms=SimulatorComms(
            self.our_defender, self.ball, self.wait_and_next_step))
        self.p.set_task(initial_state['task'])
        self.w = World('left', 0)
        self.w.our_defender._receiving_area = {
            'width': 40,
            'height': 50,
            'front_offset': 20
        }
        self.w.our_defender._catch_distance = 32
        self.steps = 0
        self.max_steps = initial_state['max_steps']
Esempio n. 2
0
    def initialise(self, initial_state):
        self.our_defender = None
        self.our_attacker = None
        if initial_state['our_defender']:
            self.our_defender = self.scene.add_robot("defender", initial_state['our_defender'])
        if initial_state['our_attacker']:
            self.our_attacker = self.scene.add_robot("attacker", initial_state['our_attacker'])

        self.ball = self.scene.add_ball(initial_state['ball'])
        self.p = DefencePlanner(comms=SimulatorComms(self.our_defender, self.ball, self.wait_and_next_step))
        self.p.set_task(initial_state['task'])
        self.w = World('left', 0)
        self.w.our_defender._receiving_area = {'width': 40, 'height': 50, 'front_offset': 20}
        self.w.our_defender._catch_distance = 32
        self.steps = 0
        self.max_steps = initial_state['max_steps']
Esempio n. 3
0
class Test:

    def __init__(self, scene):
        self.scene = scene

    def initialise(self, initial_state):
        self.our_defender = None
        self.our_attacker = None
        if initial_state['our_defender']:
            self.our_defender = self.scene.add_robot("defender", initial_state['our_defender'])
        if initial_state['our_attacker']:
            self.our_attacker = self.scene.add_robot("attacker", initial_state['our_attacker'])

        self.ball = self.scene.add_ball(initial_state['ball'])
        self.p = DefencePlanner(comms=SimulatorComms(self.our_defender, self.ball, self.wait_and_next_step))
        self.p.set_task(initial_state['task'])
        self.w = World('left', 0)
        self.w.our_defender._receiving_area = {'width': 40, 'height': 50, 'front_offset': 20}
        self.w.our_defender._catch_distance = 32
        self.steps = 0
        self.max_steps = initial_state['max_steps']

    def run(self, initial_state, test_name):
        logging.info(">> " + test_name + " started")
        self.initialise(initial_state)
        self.step()

    def step(self):
        print("\nStep: " + str(self.steps))
        if self.steps >= self.max_steps:
            print "Finished"
            return

        # update & act
        self.w.update_positions(our_attacker=self.our_attacker.get_vec() if self.our_attacker is not None else None, our_defender=self.our_defender.get_vec() if self.our_defender is not None else None, ball=self.ball.get_vec())
        self.p.plan_and_act(self.w)

        self.steps += 1

    def wait_and_next_step(self, delay):
        print("Waiting for " + str(delay) + " seconds...")
        t = Timer(delay, self.step)
        t.start()

    def test1(self):
        initial_state = {
            'task': 'move-grab',
            'max_steps': 2,
            'our_defender': Vector(100, 100, math.radians(270), 0),
            'our_attacker': None,
            'ball': Vector(200, 170, 0, 0),
        }

        self.run(initial_state, "Test 1")

    def test2(self):
        initial_state = {
            'task': 'move-grab',
            'max_steps': 2,
            'our_defender': Vector(100, 100, math.radians(315), 0),
            'our_attacker': None,
            'ball': Vector(200, 170, 0, 0),
        }

        self.run(initial_state, "Test 2")

    def test3(self):
        initial_state = {
            'task': 'move-grab',
            'max_steps': 2,
            'our_defender': Vector(250, 220, math.radians(200), 0),
            'our_attacker': None,
            'ball': Vector(200, 170, 0, 0),
        }

        self.run(initial_state, "Test 3")

    def testm3_1(self):
        initial_state = {
            'task': 'm31',
            'max_steps': 2,
            'our_defender': Vector(400, 300, math.radians(90), 0),
            'our_attacker': Vector(50, 200, math.radians(45), 0),
            'ball': Vector(100, 200, 0, 0),
        }

        self.run(initial_state, "Test M3 - Receiving a pass")
Esempio n. 4
0
class Test:
    def __init__(self, scene):
        self.scene = scene

    def initialise(self, initial_state):
        self.our_defender = None
        self.our_attacker = None
        if initial_state['our_defender']:
            self.our_defender = self.scene.add_robot(
                "defender", initial_state['our_defender'])
        if initial_state['our_attacker']:
            self.our_attacker = self.scene.add_robot(
                "attacker", initial_state['our_attacker'])

        self.ball = self.scene.add_ball(initial_state['ball'])
        self.p = DefencePlanner(comms=SimulatorComms(
            self.our_defender, self.ball, self.wait_and_next_step))
        self.p.set_task(initial_state['task'])
        self.w = World('left', 0)
        self.w.our_defender._receiving_area = {
            'width': 40,
            'height': 50,
            'front_offset': 20
        }
        self.w.our_defender._catch_distance = 32
        self.steps = 0
        self.max_steps = initial_state['max_steps']

    def run(self, initial_state, test_name):
        logging.info(">> " + test_name + " started")
        self.initialise(initial_state)
        self.step()

    def step(self):
        print("\nStep: " + str(self.steps))
        if self.steps >= self.max_steps:
            print "Finished"
            return

        # update & act
        self.w.update_positions(our_attacker=self.our_attacker.get_vec()
                                if self.our_attacker is not None else None,
                                our_defender=self.our_defender.get_vec()
                                if self.our_defender is not None else None,
                                ball=self.ball.get_vec())
        self.p.plan_and_act(self.w)

        self.steps += 1

    def wait_and_next_step(self, delay):
        print("Waiting for " + str(delay) + " seconds...")
        t = Timer(delay, self.step)
        t.start()

    def test1(self):
        initial_state = {
            'task': 'move-grab',
            'max_steps': 2,
            'our_defender': Vector(100, 100, math.radians(270), 0),
            'our_attacker': None,
            'ball': Vector(200, 170, 0, 0),
        }

        self.run(initial_state, "Test 1")

    def test2(self):
        initial_state = {
            'task': 'move-grab',
            'max_steps': 2,
            'our_defender': Vector(100, 100, math.radians(315), 0),
            'our_attacker': None,
            'ball': Vector(200, 170, 0, 0),
        }

        self.run(initial_state, "Test 2")

    def test3(self):
        initial_state = {
            'task': 'move-grab',
            'max_steps': 2,
            'our_defender': Vector(250, 220, math.radians(200), 0),
            'our_attacker': None,
            'ball': Vector(200, 170, 0, 0),
        }

        self.run(initial_state, "Test 3")

    def testm3_1(self):
        initial_state = {
            'task': 'm31',
            'max_steps': 2,
            'our_defender': Vector(400, 300, math.radians(90), 0),
            'our_attacker': Vector(50, 200, math.radians(45), 0),
            'ball': Vector(100, 200, 0, 0),
        }

        self.run(initial_state, "Test M3 - Receiving a pass")