Example #1
0
def test_load_world():
    """Tests world.load_world()"""
    gol_world = world.load_world(EXAMPLE_FILE, alive="#")
    assert len(gol_world) == 5
    assert gol_world == set([(3, 1), (1, 2), (3, 2), (2, 3), (3, 3)])

    gol_world = world.load_world(EXAMPLE_FILE, alive="O")
    assert gol_world == set()
Example #2
0
def test_simulate():
    """Tests gol.simulate()"""
    gol_world = world.load_world(EXAMPLE_FILE)

    # x-range:(1, 3), y-range:(1, 3)
    # .....
    # ...#.
    # .#.#.
    # ..##.
    # .....
    actual = gol.simulate(gol_world, iterations=0)
    assert actual == set([(3, 1), (1, 2), (3, 2), (2, 3), (3, 3)])

    # x-range:(2, 4), y-range:(1, 3)
    # .....
    # .#...
    # ..##.
    # .##..
    # .....
    actual = gol.simulate(gol_world, iterations=1)
    assert actual == set([(2, 1), (3, 2), (4, 2), (2, 3), (3, 3)])

    # x-range:(2, 4), y-range:(1, 3)
    # .....
    # ..#..
    # ...#.
    # .###.
    # .....
    actual = gol.simulate(gol_world, iterations=2)
    assert actual == set([(3, 1), (4, 2), (2, 3), (3, 3), (4, 3)])
Example #3
0
def test_render_world():
    """Tests world.render_world()"""
    gol_world = world.load_world(EXAMPLE_FILE)
    actual = world.render_world(gol_world, alive="#", dead=".")
    expected = "x-range:(1, 3), y-range:(1, 3)\n"
    expected += ".....\n"
    expected += "...#.\n"
    expected += ".#.#.\n"
    expected += "..##.\n"
    expected += ".....\n"
    assert actual == expected

    actual = world.render_world(gol_world, alive="O", dead=" ")
    expected = "x-range:(1, 3), y-range:(1, 3)\n"
    expected += "     \n"
    expected += "   O \n"
    expected += " O O \n"
    expected += "  OO \n"
    expected += "     \n"
    assert actual == expected
Example #4
0
def main():
    """
    Main CLI handler
    """
    parser = argparse.ArgumentParser(
        description="Conway's Game of Life simulation")
    parser.add_argument(
        "worldfile",
        help="Path to file containing the initial world layout",
        type=str)
    parser.add_argument(
        "--delay",
        default=0.1,
        help="Delay between frames in seconds (defaults to 0.1)",
        required=False,
        type=float)
    parser.add_argument(
        "--alive",
        default="#",
        help="Character to use when rendering living cells (defaults to \"#\")",
        required=False,
        type=str)
    parser.add_argument(
        "--dead",
        default=" ",
        help="Character to use when rendering living cells (defaults to \" \")",
        required=False,
        type=str)
    args = parser.parse_args()

    if args.worldfile[-3:].upper() == "RLE":
        gol_world = world.load_world_from_rle(args.worldfile)
    else:
        gol_world = world.load_world(args.worldfile)
    while True:
        gol_world = gol.simulate(gol_world, 1)
        print(world.render_world(gol_world, alive=args.alive, dead=args.dead))
        time.sleep(args.delay)
Example #5
0
        date = datetime(2018, 6, 21, 12, 0, 0)  # shifted_datetime()
        if rng is None:
            rng = np.random.RandomState(2018)
        RND = rng
        fov = (-np.pi / 2, np.pi / 2)
        # fov = (-np.pi/6, np.pi/2)
        sky_type = "uniform" if uniform_sky else "live" if update_sky else "fixed"
        if rgb:
            sky_type += "-rgb"
        step = .01  # 1 cm
        tau_phi = np.pi  # 180 deg
        condition = Hybrid(tau_x=step, tau_phi=tau_phi)
        agent_name = create_agent_name(date, sky_type, step, fov[0], fov[1])
        print agent_name

        world = load_world()
        world.enable_pol_filters(enable_pol)
        world.uniform_sky = uniform_sky
        routes = load_routes()
        route = routes[i]
        route.agent_no = 1
        route.route_no = 2
        world.add_route(route)
        i += 1

        agent = CXAgent(
            condition=condition,
            live_sky=update_sky,
            # visualiser=Visualiser(),
            rgb=rgb,
            fov=fov,
Example #6
0
import numpy as np
import matplotlib.pyplot as plt

from world import load_world, load_route
from world.model import cmap
from utils import *

# sky_type = "uniform"
fov = True
bin = True

if 'sky_type' in locals():
    print sky_type
    w = load_world()
    r = load_route("learned")
    r.agent_no = 1
    r.route_no = 2
    w.add_route(r)
    labels = []
    test_ = bin_tests if bin else fov_tests if fov else tests

    for j in xrange(len(test_[sky_type])):
        name = get_agent_name(sky_type, j, fov=fov, bin=bin)
        labels.append(name.split("_")[0] + " " + name.split("_")[1])
        r = load_route(name)
        r.agent_no = j + 2
        r.route_no = 2
        w.add_route(r)

    plt.figure("%s-%sfov-%sbin" %
               (sky_type, "" if fov else "no", "" if bin else "no"),