Exemple #1
0
#!/usr/bin/python3

from pysimbotlib.core import PySimbotApp, Robot

class GoStraightRobot(Robot):

    def update(self):
        self.move(5)

class TurnAroundRobot(Robot):
    
    def update(self):
        self.turn(5)

def create_robots():
    robot1 = GoStraightRobot()
    robot2 = TurnAroundRobot()
    return [robot1, robot2]

if __name__ == '__main__':
    # customfn_create_robots will override the default create_robots function which is implemented by [robot_cls() for _ in range(num_robots)]
    app = PySimbotApp(customfn_create_robots=create_robots)
    app.run()
Exemple #2
0
#!/usr/bin/python3

import os, platform
if platform.system() == "Linux" or platform.system() == "Darwin":
    os.environ["KIVY_VIDEO"] = "ffpyplayer"
    
from pysimbotlib.core import PySimbotApp, Robot
from kivy.config import Config
# Force the program to show user's log only for "info" level or more. The info log will be disabled.
Config.set('kivy', 'log_level', 'info')

import random

class RandomWalkRobot(Robot):
    
    def update(self):
        r = random.randint(0, 3)
        self.move(5)
        if r == 1:
            self.turn(15)
        elif r == 2:
            self.turn(-15)

if __name__ == '__main__':
    app = PySimbotApp(robot_cls=RandomWalkRobot, num_robots=2)
    app.run()
#!/usr/bin/python3

import os, platform
if platform.system() == "Linux" or platform.system() == "Darwin":
    os.environ["KIVY_VIDEO"] = "ffpyplayer"

from pysimbotlib.core import PySimbotApp, Robot


class MyRobot(Robot):
    def update(self):
        self.move(10)
        self.turn(-2)


if __name__ == '__main__':
    # The new robots instances will be created every simulation.
    app = PySimbotApp(robot_cls=MyRobot, max_tick=200, simulation_forever=True)
    app.run()
Exemple #4
0
#!/usr/bin/python3

import os, platform
if platform.system() == "Linux" or platform.system() == "Darwin":
    os.environ["KIVY_VIDEO"] = "ffpyplayer"

from pysimbotlib.core import PySimbotApp, Robot
from kivy.logger import Logger
from kivy.config import Config

# Force the program to show user's log only for "info" level or more. The info log will be disabled.
Config.set('kivy', 'log_level', 'info')

# update robot every 0.5 seconds (2 frames per sec)
REFRESH_INTERVAL = 1 / 2


class MyRobot(Robot):
    def update(self):
        Logger.info("Smell Angle: {0}".format(self.smell()))
        Logger.info("Distance: {0}".format(self.distance()))


if __name__ == '__main__':
    app = PySimbotApp(robot_cls=MyRobot,
                      num_robots=1,
                      interval=REFRESH_INTERVAL,
                      enable_wasd_control=True)
    app.run()
Exemple #5
0
#!/usr/bin/python3

from pysimbotlib.core import PySimbotApp
from kivy.config import Config

# Force the program to show user's log only for "debug" level or more. The info log will be disabled.
Config.set('kivy', 'log_level', 'debug')

if __name__ == '__main__':
    app = PySimbotApp(enable_wasd_control=True)
    app.run()
Exemple #6
0
    with open(FileName + "_avg_fitness.csv", "a") as af:
        Asum = 0
        for i in range(len(simbot.robots)):
            Asum += simbot.robots[i].fitness
        Avg = Asum / len(simbot.robots)
        af.write(str(Avg) + '\n')
        af.close()

    with open(FileName + ".csv", "w+") as cf:
        writer = csv.writer(cf, lineterminator="\n")
        for bot in simbot.robots:
            writer.writerows(bot.RULES)

    # except Exception as e:
    #     Logger.error("simbot: fail")
    #     print(e)


if __name__ == '__main__':

    app = PySimbotApp(robot_cls=StupidRobot,
                      num_robots=50,
                      theme='dark',
                      simulation_forever=True,
                      max_tick=MAX_TICK,
                      interval=1 / 1000.0,
                      food_move_after_eat=FOOD_MOVE,
                      customfn_before_simulation=before_simulation,
                      customfn_after_simulation=after_simulation)
    app.run()
#!/usr/bin/python3

import os, platform
if platform.system() == "Linux" or platform.system() == "Darwin":
    os.environ["KIVY_VIDEO"] = "ffpyplayer"

from pysimbotlib.core import PySimbotApp
from kivy.logger import Logger

from kivy.config import Config
# Force the program to show user's log only for "info" level or more. The info log will be disabled.
Config.set('kivy', 'log_level', 'info')

import random

if __name__ == '__main__':
    # possible map value: ["default", "no_wall"]
    app = PySimbotApp(map="no_wall", enable_wasd_control=True)
    app.run()
Exemple #8
0
#!/usr/bin/python3

from pysimbotlib.core import PySimbotApp
from kivy.logger import Logger

from kivy.config import Config
# Force the program to show user's log only for "info" level or more. The info log will be disabled.
Config.set('kivy', 'log_level', 'info')

import random

if __name__ == '__main__':
    # possible theme value: ["default", "light", "dark"]
    app = PySimbotApp(enable_wasd_control=True,
                      save_wasd_history=True,
                      max_tick=4000,
                      simulation_forever=True)
    app.run()
Exemple #9
0
    # - simbot.eat_count
    # - simbot.food_move_count
    # - simbot.score
    # - simbot.scoreStr

    # - simbot.robot[i].eat_count
    # - simbot.robot[i].collision_count
    # - simbot.robot[i].color

    for r in simbot_map.robots:
        Logger.info("Simulation: robot pos = {0}".format(r.pos))
        Logger.info("Simulation: robot eat_count = {0}".format(r.eat_count))
        Logger.info("Simulation: robot collision_count = {0}".format(
            r.collision_count))

    Logger.info("Simulation: End simulation. Robot[0] is at {0}".format(
        simbot_map.robots[0].pos))
    Logger.info("Simulation: Score = {0}".format(simbot_map.score))
    Logger.info("Time: {0}".format(time.time() - start_time))


if __name__ == '__main__':
    app = PySimbotApp(robot_cls=RandomWalkRobot,
                      num_robots=30,
                      max_tick=500,
                      interval=1 / 1000.0,
                      simulation_forever=True,
                      customfn_before_simulation=before_sim,
                      customfn_after_simulation=after_sim,
                      food_move_after_eat=False)
    app.run()
if platform.system() == "Linux" or platform.system() == "Darwin":
    os.environ["KIVY_VIDEO"] = "ffpyplayer"

from pysimbotlib.core import PySimbotApp, Robot
from kivy.logger import Logger

from kivy.config import Config
# Force the program to show user's log only for "info" level or more. The info log will be disabled.
Config.set('kivy', 'log_level', 'info')

import random

# update robot every 0.5 seconds (2 frames per sec)
REFRESH_INTERVAL = 1 / 2


class MyRobot(Robot):
    def update(self):
        Logger.info("Smell Angle: {0}".format(self.smell()))
        Logger.info("Distance: {0}".format(self.distance()))


if __name__ == '__main__':
    app = PySimbotApp(robot_cls=MyRobot,
                      num_robots=2,
                      robot_see_each_other=True,
                      interval=REFRESH_INTERVAL,
                      map="no_wall",
                      enable_wasd_control=True,
                      simulation_forever=True)
    app.run()
Exemple #11
0
#!/usr/bin/python3

import os, platform
if platform.system() == "Linux" or platform.system() == "Darwin":
    os.environ["KIVY_VIDEO"] = "ffpyplayer"

from pysimbotlib.core import PySimbotApp, Robot
from kivy.config import Config

import random

# Force the program to show user's log only for "debug" level or more. The info log will be disabled.
Config.set('kivy', 'log_level', 'debug')


class CollisionAvoidanceRobot(Robot):
    def update(self):
        if self.stuck:
            if random.random() < 0.5:
                self.turn(5)
            else:
                self.turn(-5)


if __name__ == '__main__':
    app = PySimbotApp(robot_cls=CollisionAvoidanceRobot,
                      enable_wasd_control=True)
    app.run()
Exemple #12
0
#!/usr/bin/python3

from pysimbotlib.core import PySimbotApp
from kivy.logger import Logger

from kivy.config import Config
# Force the program to show user's log only for "info" level or more. The info log will be disabled.
Config.set('kivy', 'log_level', 'info')

import random

if __name__ == '__main__':
    # possible theme value: ["default", "light", "dark"]
    app = PySimbotApp(theme="light", enable_wasd_control=True)
    app.run()