def main():
    random.seed()
    world_width = 10
    world_height = 10
    obstacles = [(4, 4), (4,5), (4,6), (5,6), (6,6), (6,5), (6,4)]
    world = simulator.World(world_width, world_height, sleep_time = 1, obstacles=obstacles, treasure=(5, 5))
    robots = []
    i = 0

    while i < (world_width // 3):
        try:
            robots.append(Robot(world, random.randint(0, world_width-1), random.randint(0, world_height-1), random.randint(0, 7)))
            i += 1
        except simulator.RegistrationException:
            pass

    while True:
        try:
            world.print_state()
            for robot in robots:
                robot.reason(world)

            world.tick()
        except simulator.RobotWallCrashException:
            print("A robot crashed into a wall! Simulation over!")
            return
        except simulator.RobotCollisionException:
            print("A robot crashed into another robot! Simulation over!")
            return
        except simulator.RobotObjectCrashException:
            print("A robot crashed into an object!")
            return
        except simulator.RobotFoundTreasureException:
            print("A robot found the treasure! You win!")
            return
Exemplo n.º 2
0
def main():
    if len(sys.argv) < 3:
        print('Please use the following format:')
        print('./visualizer TEST_FILE BOT_PROGRAM')
        return
    app = QApplication(sys.argv)
    test_path = sys.argv[1]
    bot_program = sys.argv[2]
    world = simulator.World(simulator.Bot(bot_program))
    with open(test_path) as f:
        world.deserialize(f)
    game_visualizer = GameVisualizer(world)
    sys.exit(app.exec_())
Exemplo n.º 3
0
def main():
    if len(sys.argv) != 4:
        print('Please use the following format:')
        print('./sxs_test.py TEST_SET OLD_BOT NEW_BOT')
    else:
        test_set = sys.argv[1]
        bot_program1 = sys.argv[2]
        bot_program2 = sys.argv[3]
        tests = simulator.list_tests(test_set)
        world = simulator.World(None)
        scores_sum1 = 0
        positive_bonus_num1 = 0
        bonuses_sum1 = 0
        scores_sum2 = 0
        positive_bonus_num2 = 0
        bonuses_sum2 = 0
        for test in tests:
            world.bot = simulator.Bot(bot_program1)
            simulator.run_test(world, test)
            world.bot.proc.terminate()
            world.bot = None
            score1 = world.total_score()
            scores_sum1 += world.total_score()
            bonuses_sum1 += world.bonus
            if world.bonus > 0:
                positive_bonus_num1 += 1

            world.bot = simulator.Bot(bot_program2)
            simulator.run_test(world, test)
            world.bot.proc.terminate()
            world.bot = None
            score2 = world.total_score()
            scores_sum2 += world.total_score()
            bonuses_sum2 += world.bonus
            if world.bonus > 0:
                positive_bonus_num2 += 1

            if score1 < score2:
                print('{:31} improvement: {} -> {}'.format(
                    simulator.get_test_name(test), score1, score2))
            elif score1 > score2:
                print('{:31} regression: {} -> {}'.format(
                    simulator.get_test_name(test), score1, score2))
        print('Sum: {} -> {}'.format(scores_sum1, scores_sum2))
        print('Bonus: {} -> {} ({:0.4}% -> {:0.4}%)'.format(
            bonuses_sum1, bonuses_sum2, bonuses_sum1 / scores_sum1 * 100,
            bonuses_sum2 / scores_sum2 * 100))
        print('Positive bonus: {:0.4}% -> {:0.4}%'.format(
            positive_bonus_num1 / len(tests) * 100,
            positive_bonus_num2 / len(tests) * 100))
Exemplo n.º 4
0
"""

from __future__ import print_function

import os

import neat

import simulator
import visualize
import my_statistics

# 2-input XOR inputs and expected outputs.
# xor_inputs = [(0.0, 0.0), (0.0, 1.0), (1.0, 0.0), (1.0, 1.0)]
# xor_outputs = [   (0.0,),     (1.0,),     (1.0,),     (0.0,)]
world = simulator.World('track1.txt')

world.set_speed(.1)
max_iterations_without_getting_goal = 50
points_per_goal = 100
threshold = .9
generations_to_run=10
pop_size=50
output_mult=world.angular_speed_limit


def eval_genomes(genomes, config):
    for genome_id, genome in genomes:
        genome.fitness = 0.0
        iterations_without_getting_goal = 0.0
        net = neat.nn.FeedForwardNetwork.create(genome, config)
Exemplo n.º 5
0
                            "Got random movement from found treasure from 3! YAY!")

        if surroundings[possible_moves[rand_movement]][0] == -3:
            print("Passed for treasure")
            pass

        elif len(surroundings[possible_moves[rand_movement]]) == 3:
            print("Got random movement from randint!!!")
            for i in surroundings[possible_moves[rand_movement]]:
                print(i)

        else:
            rand_movement = Robot.move_right_or_left(
                self, surroundings, possible_moves)

        print("Rand_movement is: " + str(rand_movement))
        self.turn_and_drive_straight(rand_movement)

if __name__ == "__main__":
    world = simulator.World(
        width=10, height=10, sleep_time=0.1, reliability=1, treasure=(-1, -1), obstacles=[(1, 0)])
    robots = []
    robots.append(Robot(world, 0, 0, 4))  # add more robots here if you like

    for _ in range(100000):  # Simulate 50 ticks
        world.print_state()
        for robot in robots:
            robot.decide()
        world.print_state()
        world.tick()