Beispiel #1
0
 def create_fleet(self):
     robot1 = Robot("Bumblebee")
     robot2 = Robot("Optimus Prime")
     robot3 = Robot("Grimlock")
     self.robots.append(robot1)
     self.robots.append(robot2)
     self.robots.append(robot3)
Beispiel #2
0
    def setUp(self):
        rospy.init_node('test_status')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
        self.robot1 = Robot('robot_1', 1, 0.5, 5, 5, pi / 2)

        # Execute robots a few times to allow statuses to become existant.
        for i in range(0, 10):
            self.robot.execute()
            self.robot1.execute()
            time.sleep(0.1)
Beispiel #3
0
 def iniData(self, points, connections, first_point, robots):
     if not robots:
         robots = 1
     self.first_point = first_point
     self.points = points
     self.points = [(x.x(), x.y()) for x in self.points]
     self.connections = connections
     self.robots = [Robot((first_point.x(), first_point.y())) for x in range(int(robots))]
Beispiel #4
0
def test_robot_initial_position():
    ''' test all strings for bearings will work '''

    bearings = ['north', 'south', 'east', 'west']

    for b in bearings:
        robot = Robot(1, 2, b)
        assert robot.x == 1 and robot.y == 2 and robot.bearing == b
Beispiel #5
0
def test_name_does_not_change_when_rebooted():
    robot = Robot()
    robot.start()
    name1 = robot.name()

    robot.stop()
    robot.start()
    name2 = robot.name()
    assert name1 == name2
Beispiel #6
0
def test_name_changes_after_a_reset():
    robot = Robot()
    robot.start()
    name1 = robot.name()

    robot.stop()
    robot.reset()
    robot.start()
    name2 = robot.name()
    assert name1 != name2
Beispiel #7
0
 def test_can_create_a_robot(self):
     orange = Robot()
Beispiel #8
0
    def initialize_battle():
        #Weapons List
        weapons = Weapons()
        #Fighters
        marvin = Robot('Marvin')
        megaman = Robot('Megaman')
        wall_E = Robot('Wall-e')
        stegosaurus = Dinosaur('Stegosaurus')
        velociraptor = Dinosaur('Velociraptor')
        tyrannosaurus = Dinosaur('Tyrannosaurus')
        #Select Weapon/Attack
        weapons.choose_weapon(marvin)
        weapons.choose_weapon(megaman)
        weapons.choose_weapon(wall_E)

        weapons.choose_attack(stegosaurus)
        weapons.choose_attack(velociraptor)
        weapons.choose_attack(tyrannosaurus)

        #Robots
        marvin.power_level = 120
        marvin.attack_power = 70

        megaman.power_level = 110
        megaman.attack_power = 100

        wall_E.power_level = 100
        wall_E.attack_power = 60

        #Dinos
        stegosaurus.attack_power = 60

        velociraptor.attack_power = 80

        tyrannosaurus.attack_power = 100

        #Fleet
        robot_fleet = Fleet()
        robot_fleet.add_to_fleet([marvin, megaman, wall_E])
        # print(robot_fleet.fleet)

        #Herd
        dino_herd = Herd()
        dino_herd.add_to_herd([stegosaurus, velociraptor, tyrannosaurus])
        # print(dino_herd.herd)

        #Display fighters and battlefield
        display(battlefield)

        # --- Fighters will attack each other randomly, last fighter standing wins!---
        def battle(fleet, herd):
            counter = 0
            for element in fleet:
                fleet_health = 0
                for i in range(0, len(element)):
                    fleet_health += element[i].health
                for obj in herd:
                    herd_health = 0
                    for a in range(0, len(obj)):
                        herd_health += obj[a].health
                    while counter <= 100 or fleet_health <= 0 or herd_health <= 0:
                        n = random.randint(0, 2)
                        i = random.randint(0, 2)
                        obj[n].attack_robo(element[n])
                        element[n].attack_dino(obj[i])
                        counter += 1

        battle(robot_fleet.fleet, dino_herd.herd)

        #Stats
        print(wall_E)
        print(megaman)
        print(marvin)
        print(stegosaurus)
        print(velociraptor)
        print(tyrannosaurus)

        def conclude_battle(robot_fleet, dino_herd):
            for element in robot_fleet.fleet:
                count = 0
                while count <= len(element):
                    for robot in element:
                        if robot.status == 'Defeated' or robot.status == 'Resting':
                            element.remove(robot)
                    count += 1

                if len(element) == 0:
                    return ctypes.windll.user32.MessageBoxW(
                        0, 'Battle concluded: Dinos have won!',
                        'Robots vs Dinosaurs', 64)

            for element in dino_herd.herd:
                count = 0
                while count <= len(element):
                    for dino in element:
                        if dino.health <= 0 or dino.status == 'Resting':
                            element.remove(dino)
                    count += 1

                if len(element) == 0:
                    return ctypes.windll.user32.MessageBoxW(
                        0, 'Battle concluded: Robos have won!',
                        'Robots vs Dinosaurs', 64)

            return ctypes.windll.user32.MessageBoxW(0, 'Battle is Ongoing!',
                                                    'Robots vs Dinosaurs', 64)

        conclude_battle(robot_fleet, dino_herd)
Beispiel #9
0
from herd import Herd
from battlefield import Battlefield
from weapons import Weapons
import ctypes
import random

if __name__ == '__main__':

    #Battlefield
    battlefield = Battlefield()

    #Weapons
    weapons = Weapons()

    # Robots
    robot_wally = Robot("Wall-E")
    robot_wally.power_level = 100
    robot_wally.attack_power = 60
    # weapons.choose_weapon(robot_wally)

    robot_megaman = Robot("Megaman")
    robot_megaman.power_level = 110
    robot_megaman.attack_power = 100
    # weapons.choose_weapon(robot_megaman)

    robot_marvin = Robot("Marvin")
    robot_marvin.power_level = 120
    robot_marvin.attack_power = 70
    # weapons.choose_weapon(robot_marvin)

    #Dinos
from robots import Robot

r1 = Robot(4, 10, 'est', 'Robert', 'Humanoide', 'En service')
print('r1 =', r1)
r2 = Robot(15, 7, 'sud', 'Juliette', 'Mobile', 'En service')
print('r2 =', r2)

r1.nom = "D2R2"  # on a ajouté un nom à r1 mais r2 n'a pas de nom


def tourner_gauche(robot):
    robot.direction = (robot.direction + 3) % 4

    Robot.pivoter_gauche = tourner_gauche

    r2.pivoter_gauche()  # direction devient 'est'
    print('r2 =', r2)
Beispiel #11
0
 def setUp(self):
     rospy.init_node('test_bin')
     self.bin = Bin('robot_0', 1, 0.5, 1, 1, pi / 2)
     self.robot = Robot('robot_1', 1, 0.5, 1, 1, pi / 2)
Beispiel #12
0
def test_Robot():
    r = Robot("Marvin", "Nürnberg")
    assert r.name == "Marvin"
    assert r.city == "Nürnberg"
Beispiel #13
0
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 26 14:22:05 2016

@author: perumal
"""

from robots import Robot, Robot1  # imports Robot class from robots.py

x = Robot("Oscar")

Robot.say_hi(x)
x.say_hi()
#print(Robot.__dict__)
#print(x.get_name())
#print(x.__dict__)    #### outputs "{'_Robot__name': 'Marvin'}"
#                     #### whatever starts with an underscore _Robot... are modified and cannot be modified
#
y = Robot('Henry')

y.set_name(x.get_name())

y.name = x.name

print(x.name)  #### prints "Marvin"

x.name = "Oscar"

m = Robot1("Adam")

m.say_hi()
Beispiel #14
0
def test_started_robots_have_a_name():
    robot = Robot()
    robot.start()
    actual_name = robot.name()
    assert re.match(r"^[A-Z]{2}\d{3}$", actual_name) is not None
Beispiel #15
0
def test_name_is_not_set_at_first():
    robot = Robot()
    assert robot.name() is None
Beispiel #16
0
 def test_robot_can_starts_at_button_1(self):
     self.assertEqual(1, Robot().position)
Beispiel #17
0
 def setUp(self):
     rospy.init_node('test_robot_storage')
     self.robot_obj = Robot('robot_0', 2, 0.9, -20, 43, 0)
Beispiel #18
0
#! /usr/bin/env python3

from robots import Robot


x = Robot("Marvin", "Nürnberg")
x.say_hi()

y = Robot("Hen", "Nürnberg")
y.say_hi()
try:
    y.name = "Henry"
except NameError as e:
    print(e)

try:
    z = Robot("Hans", "München")
except NameError as e:
    print(e)

w = x + y
w.say_hi()

print(w)
print(repr(w))
w2 = eval(repr(w))
w2.say_hi()

print(w == w2)
Beispiel #19
0
from robots import Robot, RC_BLACK, RC_WHITE
from intcomp import IntcodeController

f = open('input11.txt', 'r')
ls1 = f.read().split(',')
vm = IntcodeController([int(s) for s in ls1], buffer=[])
r = Robot(vm)
r.run()
print(len(r.panel))
vm.reset()
r = Robot(vm, panel={(0, 0): RC_WHITE})
r.run()
r.print_as_picture()
 def setUp(self):
     self.mega_man = Robot("Mega Man", battery=50)
Beispiel #21
0
 def setUp(self):
     rospy.init_node('test_navigate_action')
     self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi/2)
Beispiel #22
0
 def test_robot_forward_should_change_robot_position_to_next_position(self):
     robot = Robot()
     robot.forward()
     self.assertEqual(2, robot.position)
Beispiel #23
0
 def setUp(self):
     rospy.init_node('test_move_action')
     self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
     self.robot1 = Robot('robot_0', 1, 0.5, 0, 0, pi / 2)
Beispiel #24
0
 def test_robot_back_should_change_robot_position_to_after_position(self):
     robot = Robot()
     robot.position = 2
     robot.back()
     self.assertEqual(1, robot.position)
Beispiel #25
0
from robots import Robot
from dinosaurs import Dinosaur
from fleet import Fleet
from herd import Herd
from battlefield import Battlefield

r1 = Robot('WALL-E')
r2 = Robot('T-800')
r3 = Robot('Roomba')

d1 = Dinosaur('Trogdor', 55)
d2 = Dinosaur('Allosaurus', 42)
d3 = Dinosaur('Spinosaurus', 55)

Fleet(3)
Fleet.create_fleet(r1)
Fleet.create_fleet(r2)
Fleet.create_fleet(r3)
print(Fleet.robot_fleet)

Herd(3)
Herd.create_herd(d1)
Herd.create_herd(d2)
Herd.create_herd(d3)
print(Herd.dinosaur_herd)
Beispiel #26
0
    def test_robot_move_to_should_move_robot_step_by_step(self):
        robot = Robot()
        for i in range(9):
            robot.move_to(10)

        self.assertEqual(10, robot.position)

#---------------
if __name__ == '__main__':

    params = Parameters(path="../config.yaml")
    mean_time = []
    std_time = []
    for lambda_ in np.linspace(0, 2, 21):
        times = []
        n_failures = 0
        for i in range(10):
            q = make_queues()
            env = Environment()
            gt = set(env.ground_truth)
            robot1 = Robot(1, q.robots, env)
            robot2 = Robot(2, q.robots, env)
            master = NaiveMaster(params, q.master, lambda_=lambda_)
            robot1.start()
            robot2.start()
            master.start()
            directive = {"type_directive": "request_run"}
            q.gui.gui2master.put(Container(directive))
            edges = {}
            start_time = time.time()
            while True:
                if not q.gui.master2gui.empty():
                    directive = q.gui.master2gui.get_nowait()
                    edges = set(directive.summary.edges)
                common = gt.intersection(edges)
                overlap = float(len(common)) / float(len(gt))
Beispiel #28
0
 def setUp(self):
     rospy.init_node('test_robot')
     self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
     for i in range(0, 20):
         self.robot.execute()