コード例 #1
0
def tests():
    parser_tests()
    a = Actor(global_env,
              Script([Method('method1', [], 'Hurary'),
                      Method('method2:', ['x'], 'x')]))
    n = Number(3)
    env = Env(None, {'a': a, 'n': n})
    test_expr(env, 'a', a)
    should_raise(env, 'b', 'Unbound')
    should_raise(env, 'a method1', 'Unbound')
    should_raise(env, 'a foo', 'No matching method')
    test_expr(env, 'a method2: a', a)
    test_expr(env, 'n * n', Number(9))
    test_expr(env, 'a. n', n)
    test_expr(env, '', void_actor)
    test_expr(env, '42', Number(42))
    test_expr(env, '(a method2: 3) * 2', Number(6))

    s1 = Script([Method('run:', ['x'], 'make Foo')])
    s2 = Script([Method('multiply_by:', ['y'], 'x * y')])
    s1.get_method('run:').set_inner('Foo', s2)
    a1 = Actor(global_env, s1)
    env1 = Env(None, {'a1': a1})
    test_expr(env1, '(a1 run: 4) multiply_by: 5', Number(20))

    assert Method('f', [], 'ab. ab').mark_up_body(global_env) == 'ab. ab'
    assert Method('foo:', ['x'], 'x').get_signature() == 'foo: x'

    s = String('Hello, world!')
    env2 = Env(None, {'s': s})
    test_expr(env2, 's', String('Hello, ' + 'world!'))
    test_expr(env2, 's length', Number(13))
    test_expr(env2, 's from: 1 to: 5', String('Hello'))
    test_expr(env2, "'Hello, world!'", s)
    test_expr(env2, 'let x = 2 * 3. x * x', Number(36))
コード例 #2
0
 def test_stored_values(self):
     'Tests if initial values are stored in Actor'
     ator = Actor(1, 2)
     self.assertEqual(1, ator.x)
     self.assertEqual(2, ator.y)
     self.assertEqual(ACTIVE, ator.status)
     self.assertEqual('A', ator.character())
コード例 #3
0
 def teste_valores_passados_por_parametro(self):
     'Testa se valores passados no inicializador são armazenados no objeto'
     ator = Actor(1, 2)
     self.assertEqual(1, ator.x)
     self.assertEqual(2, ator.y)
     self.assertEqual(ACTIVE, ator.status)
     self.assertEqual('A', ator.character())
コード例 #4
0
 def teste_valores_padrao(self):
     'Testa valores iniciais padrão de um Actor'
     ator = Actor()
     self.assertEqual(0, ator.x)
     self.assertEqual(0, ator.y)
     self.assertEqual(ACTIVE, ator.status)
     self.assertEqual('A', ator.character())
コード例 #5
0
 def test_default_values(self):
     'Test inital values of Actor'
     ator = Actor()
     self.assertEqual(0, ator.x)
     self.assertEqual(0, ator.y)
     self.assertEqual(ACTIVE, ator.status)
     self.assertEqual('A', ator.character())
コード例 #6
0
ファイル: builtin.py プロジェクト: void4/hmph
 def __init__(self, env=None):
     if env is None:
         env = global_env.sprout()
     Actor.__init__(self, env, maildir_script, True)
     # XXX the following might run before env is initialized, when
     # restoring from a snapshot.  We should just throw out this
     # env hack and make something better.
     for key in env.locals:
         self.script.add_element(Example(key))
コード例 #7
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self, env=None):
     if env is None:
         env = global_env.sprout()
     Actor.__init__(self, env, maildir_script, True)
     # XXX the following might run before env is initialized, when
     # restoring from a snapshot.  We should just throw out this
     # env hack and make something better.
     for key in env.locals:
         self.script.add_element(Example(key))
コード例 #8
0
ファイル: test_actions.py プロジェクト: euribates/grafel
def test_move_ten_steps():
    sujeto = Actor('A')
    a = actions.Move(sujeto, 0, 10, Vector(100, 10))
    a.start(0)
    a.step(0)
    assert sujeto.pos == Vector(10, 1)
    a.step(1)
    assert sujeto.pos == Vector(20, 2)
    a.step(2)
    assert sujeto.pos == Vector(30, 3)
    a.step(3)
    assert sujeto.pos == Vector(40, 4)
    a.step(4)
    assert sujeto.pos == Vector(50, 5)
    a.step(5)
    assert sujeto.pos == Vector(60, 6)
    a.step(6)
    assert sujeto.pos == Vector(70, 7)
    a.step(7)
    assert sujeto.pos == Vector(80, 8)
    a.step(8)
    assert sujeto.pos == Vector(90, 9)
    a.step(9)
    assert sujeto.pos == Vector(100, 10)
    a.end(10)
コード例 #9
0
    def add_cast(self, cast_info):
        try:
            from actors import Actor
        except ImportError:
            from coactors.actors import Actor

        query = """MERGE (t:Title {uid: $uid}) 
            ON CREATE SET t += {title: $title, released: $released, title_type: $title_type} 
            SET t.children_known = True  
            WITH t 
            CALL {
                WITH t 
                UNWIND $batch as row 
                MERGE (_:Actor {uid: row.uid}) 
                ON CREATE SET _ += {name: row.name} 
                MERGE (_)-[:ACTED_IN]->(t) 
                RETURN _ 
            }"""
        params = {
            "title": self.title,
            "uid": self.uid,
            "released": self.released,
            "title_type": self.title_type
        }
        batch = []

        for i in range(0, len(cast_info)):

            batch.append({
                "uid": cast_info[i]["uid"],
                "name": cast_info[i]["name"]
            })

        params['batch'] = batch
        return Actor.match(graph).raw_query(query, params)
コード例 #10
0
def embody(symbol):
    from actors import Actor, Being
    kind = Habitor(symbol)
    if kind in (Habitor.Elf, Habitor.Goblin):
        return Actor(Habitor(symbol))
    else:
        return Being(Habitor(symbol))
コード例 #11
0
ファイル: app.py プロジェクト: Alisa-Modeste/coactors
def actor_text_search():
    query = request.args.get('query')
    not_listed = request.args.get('more') if request.args.get('more') else None
    actors = None

    if not not_listed:
        actors = Actor.find_by_name(query)

    if actors:
        response = []
        for actor in actors:
            response.append({
                "uid":
                actor.uid,
                "name":
                actor.name,
                "children_known":
                actor.children_known if actor.children_known else False
            })

        return {"known": True, "results": response, "query": query}

    response = API.retrieve('/search/person', {'query': query})
    actors = parse_search_results(response, "actors")

    return {"known": False, "results": actors}
コード例 #12
0
 def eval(self, env):
     from actors import Actor, void_actor  # XXX circular dependency
     nested_env = env.sprout()
     env.define(self.name, void_actor)  # XXX need some other marker
     result = Actor(nested_env, self.script)
     env.define(self.name, result)
     return result
コード例 #13
0
ファイル: test_actions.py プロジェクト: euribates/grafel
def test_get_relative_frame():
    task = actions.Action(Actor('A'), 5, 10)
    assert task.get_relative_frame(5) == 1
    assert task.get_relative_frame(6) == 2
    assert task.get_relative_frame(7) == 3
    assert task.get_relative_frame(8) == 4
    assert task.get_relative_frame(9) == 5
    assert task.get_relative_frame(10) == 6
コード例 #14
0
 def agregar(self, k=0, modif=False):
     if modif is False:
         k = input("\nIngrese el codigo de Actor: ")
     nombre = input("Ingrese el nombre: ")
     personajes = {}
     actor = Actor(nombre, personajes)
     self.repoA.repoActors[k] = actor
     self.listar()
コード例 #15
0
 def get_cast(self):
     try:
         from actors import Actor
     except ImportError:
         from coactors.actors import Actor
     return Actor.match(graph).raw_query(
         "MATCH(t:Title {uid: $uid})<-[:ACTED_IN]-(_:Actor) ",
         {"uid": self.uid})
コード例 #16
0
 def test_character(self):
     'Testing char for ACTIVE and DESTROYED status'
     ator = Actor()
     self.assertEqual('A', ator.character())
     actor_on_same_position = Actor()
     ator.clash(actor_on_same_position)
     self.assertEqual(' ', ator.character())
コード例 #17
0
 def test_caracter(self):
     'Teste de caracter para status ATIVO e DESTRUIDO'
     ator = Actor()
     self.assertEqual('A', ator.character())
     outro_ator_na_mesma_posicao = Actor()
     ator.clash(outro_ator_na_mesma_posicao)
     self.assertEqual(' ', ator.character())
コード例 #18
0
ファイル: app.py プロジェクト: Alisa-Modeste/coactors
def get_actors():
    actors = Actor.get_all()

    actor_list = []
    for actor in actors:
        actor_list.append(actor.serialize())

    from flask import jsonify
    return jsonify(actor_list)
コード例 #19
0
ファイル: main.py プロジェクト: Xetoxyc/SnakeAI
def main():
    args = setup_arguments()

    actor = Actor.get_actor(args.a, args.r)
    gui = True if type(actor) is ActorHuman else args.g

    game = Game.get_game(gui, actor)
    game.run()

    quit()
コード例 #20
0
ファイル: app.py プロジェクト: Alisa-Modeste/coactors
def find_actor(uid):
    group = request.args.get('ca').split(",") if request.args.get(
        'ca') else None
    actor = Actor.find_by_uid(uid)

    if actor and group:
        group_members = Actor.find_by_uids(group)

        coactors = actor.get_groups_coactors(group.copy())
        titles = actor.get_groups_titles(group.copy())

        return actor.serialize2(titles, coactors, group_members)

    elif actor:
        coactors = actor.get_coactors()
        titles = actor.get_titles()

        return actor.serialize2(titles, coactors)
    else:
        return {}
コード例 #21
0
ファイル: test_actions.py プロジェクト: euribates/grafel
def test_last_frame():
    task = actions.Action(Actor('A'), 5, 10)
    with pytest.raises(ValueError):
        task.is_last(4)
    assert not task.is_last(5)
    assert not task.is_last(6)
    assert not task.is_last(7)
    assert not task.is_last(8)
    assert not task.is_last(9)
    assert task.is_last(10)
    with pytest.raises(ValueError):
        task.is_last(11)
コード例 #22
0
ファイル: builtin.py プロジェクト: void4/hmph
def make_account():
    from actors import Expression # XXX circular module dependency
    root_env = global_env.sprout()

    sender_script = \
        Script([Method('send:', ['message'],
                       'inbox <- ([message] + inbox get)')])
    mailbox_script = \
        Script([Method('first', [], 'inbox get at: 1'),
                Method('removefirst', [], 'inbox <- (inbox get from: 2)'),
                Method('sender', [], 'sender')])
    makemailbox_run = \
        Method('run', [],
               Expression('let inbox = makebox holding: []. make sender. make mailbox',
                          {'sender': sender_script,
                           'mailbox': mailbox_script}))
    root_env.define('makemailbox', Actor(root_env, Script([makemailbox_run])))

    root_env.define('maildirectory', maildir_actor)

    root_actor = \
        Actor(root_env,
              Script([Text('Welcome to your new account.  You should bookmark this page if you ever intend to return, because going back and clicking "Go!" again would create another new account with a different URI.\n\nIn Hmph, everything is an object, and every object has a page with a generated URI.  For example, the number 2 is an object.  Below, we send it the message "+ 3" and it adds 3 to itself, yielding 5:'),
                      Example('2 + 3'),
                      Example('(3*3) + (4*4)'),
                      Text('The syntax is related to Smalltalk, but not the same.  To make a new type of object, decide on what to call it in the local scope, such as Foo, and enter "make Foo":'),
                      Example('make Foo'),
                      Text('You can also give a local name to any other object using "let name = expression". For example:'),
                      Example('let box = makebox holding: true'),
                      Example('box get'),
                      Example('box <- false. box get'),
                      Example("['hello']"),
                      Text("""There's a public directory of message boxes for other users, in maildirectory:"""),
                      Example('maildirectory'),
                      Text('You can create your own mailbox:'),
                      Example('let mailbox = makemailbox run'),
                      Text("""To add it to the directory, enter "maildirectory at: 'alice' put: mailbox sender" into the "Add example" field below, changing alice to some single-word identifier of your choice. (This will fail and return false if that identifier is already taken.)  Then inspect "mailbox" to see how to get your messages. A message can be any object, not just plain text."""),
                      Text("""Have fun exploring!  Don't put much work into it, at least yet, because this account *will* get zapped during code upgrades; I'm not ready to commit to continuity yet.  There will be actual documentation real soon now.  Please send feedback to Darius Bacon <*****@*****.**>. Thanks!""")
                      ]))
    return get_editor(root_actor)
コード例 #23
0
ファイル: app.py プロジェクト: Alisa-Modeste/coactors
def create_title():
    uid = request.args.get('uid')
    title_type = request.args.get('title_type')
    if uid.isnumeric():

        if title_type == "movie" or title_type == "tv":
            prefix = title_type[0:2]
        else:
            return {}

    elif uid[2:].isnumeric():
        prefix = uid[0:2]
        uid = uid[2:]
        if prefix == "mo":
            title_type = "movie"
        elif prefix == "tv":
            title_type = "tv"

    else:
        return {}

    title = find_title(prefix + uid)
    if title and 'children_known' in title:
        return title

    title_data = get_titles_data([{'uid': uid, "title_type": title_type}])
    t = Title(title_data[0]['uid'], title_data[0]['title'],
              title_data[0]['released'], title_data[0]['title_type'])
    actors_added = t.add_cast(title_data[0]['cast'])

    actors = get_actors_data(actors_added)

    for actor in actors:

        a = Actor(actor['uid'], actor['name'])

        a.add_titles(actor['titles'])

    return redirect(url_for('find_title', uid=title_data[0]['uid']))
コード例 #24
0
ファイル: app.py プロジェクト: Alisa-Modeste/coactors
def create_actor():
    uid = request.args.get('uid')
    uid = uid if uid.isnumeric() else uid[2:]

    if not uid.isnumeric():
        return {}
    actor = find_actor("na" + uid)
    if actor and 'children_known' in actor:
        return actor

    actor_data = get_actors_data([{'uid': uid}])
    a = Actor(actor_data[0]['uid'], actor_data[0]['name'])
    titles_added = a.add_titles(actor_data[0]['titles'])

    casts = get_titles_data(titles_added)

    for cast in casts:
        t = Title(cast['uid'], cast['title'], cast['released'],
                  cast['title_type'])

        t.add_cast(cast['cast'])

    return redirect(url_for('find_actor', uid=actor_data[0]['uid']))
コード例 #25
0
 def test_actor_destroyed_not_clashing(self):
     "Tests that a destroyed actor can't clash, even if it is neighbor of another actor"
     ator = Actor(2, 2)
     ator.clash(ator, 0)  # clashing actor with itself make its status equals to destroyed
     ator2 = Actor(2, 2)
     self.assert_not_clashing(ator, ator2)
     self.assert_not_clashing(Actor(2, 3), ator)
     self.assert_not_clashing(Actor(3, 3), ator)
     self.assert_not_clashing(Actor(3, 2), ator)
     self.assert_not_clashing(Actor(3, 1), ator)
     self.assert_not_clashing(Actor(2, 1), ator)
     self.assert_not_clashing(Actor(1, 1), ator)
     self.assert_not_clashing(Actor(1, 2), ator)
     self.assert_not_clashing(Actor(1, 3), ator)
     self.assert_not_clashing(ator2, ator)
     self.assert_not_clashing(Actor(2, 3), ator)
     self.assert_not_clashing(Actor(3, 3), ator)
     self.assert_not_clashing(Actor(3, 2), ator)
     self.assert_not_clashing(Actor(3, 1), ator)
     self.assert_not_clashing(Actor(2, 1), ator)
     self.assert_not_clashing(Actor(1, 1), ator)
     self.assert_not_clashing(Actor(1, 2), ator)
     self.assert_not_clashing(Actor(1, 3), ator)
コード例 #26
0
ファイル: app.py プロジェクト: Alisa-Modeste/coactors
def get_multi():
    actors = Actor.get_all(limit=10)

    actor_list = []
    for actor in actors:
        actor_list.append(actor.serialize())

    titles = Title.get_all(limit=10)

    title_list = []
    for title in titles:
        title_list.append(title.serialize())

    return {'titles': title_list, "actors": actor_list}
コード例 #27
0
ファイル: player.py プロジェクト: bedardn93/Shmup-v2
 def __init__(self,x=None,y=None,img=None):
     if x is None and y is None and img is None:
         Actor.__init__(self)
     elif x is None and y is None:
         Actor.__init__(self,None,None,img)
     else:
         Actor.__init__(self,x,y,img)
     self.player_speed = 5
     self.health = 20
コード例 #28
0
ファイル: test_actions.py プロジェクト: euribates/grafel
def test_move_not_in_origin():
    sujeto = Actor('A', pos=Vector(50, 50))
    a = actions.Move(sujeto, 0, 5, Vector(50, 0))
    a.start(0)
    a.step(0)
    assert sujeto.pos == Vector(50, 40)
    a.step(1)
    assert sujeto.pos == Vector(50, 30)
    a.step(2)
    assert sujeto.pos == Vector(50, 20)
    a.step(3)
    assert sujeto.pos == Vector(50, 10)
    a.step(4)
    assert sujeto.pos == Vector(50, 0)
    a.end(5)
コード例 #29
0
ファイル: test_actions.py プロジェクト: euribates/grafel
def test():
    sujeto = Actor('A')
    a = actions.Fall(sujeto, 0, 5, Vector(100, 0))
    a.start(0)
    a.step(0)
    assert sujeto.pos == Vector(4, 0)
    a.step(1)
    assert sujeto.pos == Vector(16, 0)
    a.step(2)
    assert sujeto.pos == Vector(36, 0)
    a.step(3)
    assert sujeto.pos == Vector(64, 0)
    a.step(4)
    assert sujeto.pos == Vector(100, 0)
    a.end(5)
コード例 #30
0
ファイル: test_actions.py プロジェクト: euribates/grafel
def test_fall_not_in_origin():
    sujeto = Actor('A', pos=(100, 0))
    a = actions.Fall(sujeto, 0, 5, Vector(200, 0))
    a.start(0)
    a.step(0)
    assert sujeto.pos == Vector(104, 0)
    a.step(1)
    assert sujeto.pos == Vector(116, 0)
    a.step(2)
    assert sujeto.pos == Vector(136, 0)
    a.step(3)
    assert sujeto.pos == Vector(164, 0)
    a.step(4)
    assert sujeto.pos == Vector(200, 0)
    a.end(5)
コード例 #31
0
ファイル: test_actions.py プロジェクト: euribates/grafel
def test_move_five_steps():
    sujeto = Actor('A')
    a = actions.Move(sujeto, 0, 5, Vector(50, 0))
    a.start(0)
    a.step(0)
    assert sujeto.pos == Vector(10, 0)
    a.step(1)
    assert sujeto.pos == Vector(20, 0)
    a.step(2)
    assert sujeto.pos == Vector(30, 0)
    a.step(3)
    assert sujeto.pos == Vector(40, 0)
    a.step(4)
    assert sujeto.pos == Vector(50, 0)
    a.end(5)
コード例 #32
0
ファイル: backdrop.py プロジェクト: bedardn93/Shmup-v2
    def __init__(self,x=None,y=None,img=None):
        if x is None and y is None and img is None:
            Actor.__init__(self)
        elif x is None and y is None:
            Actor.__init__(self,None,None,img)
        else:
            Actor.__init__(self,x,y,img)

        pygame.transform.scale(self.getImage(),(1920,1080))
        self.y_speed = 4
コード例 #33
0
def updateSticksCountSprite(sticks: Actor):
    from pyglet.resource import image as PImage
    """
    Update sticks sprite by count.
    """

    # map count to sprite. Distribute 4 point between MIN-MAX
    keys = splitPartition(Sticks.MIN, Sticks.MAX, 4)
    spriteMap = {
        keys[0]: PImage('assets/sticks.png'),
        keys[1]: PImage('assets/sticks-mid.png'),
        keys[2]: PImage('assets/sticks-light.png'),
        keys[3]: PImage('assets/sticks-almost.png')
    }
    key = selectKey(sticks.domain.value, keys)
    sticks.image = spriteMap[key]
コード例 #34
0
    def test_actor_position(self):
        "Test that an ordinary actor doen't move."
        ator = Actor()
        x, y = ator.calculate_position(0)
        self.assertEqual(0, x)
        self.assertEqual(0, y)

        ator = Actor(0.3, 0.5)
        x, y = ator.calculate_position(10)
        self.assertEqual(0.3, x)
        self.assertEqual(0.5, y)
コード例 #35
0
ファイル: tileMapper.py プロジェクト: jamesin4d/MapGenerator
def populate_sprite_lists(layers, all_tiles, tw, th):
    collision_list = []
    background = []
    foreground = []
    for layer in layers:
        collision = False
        back = False
        fore = False
        if 'properties' in layer:
            properties = layer['properties']
            if 'collision' in properties:
                collision = True
            if 'fore' in properties:
                fore = True
            if 'back' in properties:
                back = True
        data = layer['data']
        index = 0
        for y in range(0, layer['height']):
            for x in range(0, layer['width']):
                id_key = data[index]
                if id_key != 0:
                    if collision:
                        solid = Actor()
                        solid.rect = pygame.Rect(x*tw, y*th, tw, th)
                        solid.image = all_tiles[id_key]
                        collision_list.append(solid)
                    if fore:
                        foreground_tile = Actor()
                        foreground_tile.rect = pygame.Rect(x*tw, y*th, tw, th)
                        foreground_tile.image = all_tiles[id_key]
                        foreground.append(foreground_tile)
                    if back:
                        background_tile = Actor()
                        background_tile.rect = pygame.Rect(x * tw, y * th, tw, th)
                        background_tile.image = all_tiles[id_key]
                        background.append(background_tile)
                index += 1
    return collision_list, background, foreground
コード例 #36
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self, initial_value):
     # XXX global_env is mutable
     Actor.__init__(self, global_env, box_script, initial_value)
コード例 #37
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self, elements):
     # XXX global_env is mutable
     Actor.__init__(self, global_env, list_script, tuple(elements))
コード例 #38
0
 def __init__(self, x, y):
     """Create a decoration at acnvas coordinates x,y"""
     self.x = int(x)
     self.y = int(y)
     Actor.__init__(self)
コード例 #39
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self, str):
     # XXX global_env is mutable
     Actor.__init__(self, global_env, string_script, str)
コード例 #40
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self, sample_instance):
     # XXX global_env is mutable
     Actor.__init__(self, global_env, type_guard_script, sample_instance)
コード例 #41
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self):
     # XXX global_env is mutable
     Actor.__init__(self, global_env, stamp_script, False)
コード例 #42
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self, stamp):
     # XXX global_env is mutable
     Actor.__init__(self, global_env, stampguard_script, stamp)
コード例 #43
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self):
     # XXX global_env is mutable
     Actor.__init__(self, global_env, stamp_maker_script, True)
コード例 #44
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self, script, value):
     # XXX global_env is mutable
     Actor.__init__(self, global_env, script, value)
コード例 #45
0
ファイル: builtin.py プロジェクト: darius/hmph
 def __init__(self, n):
     # XXX global_env is mutable
     Actor.__init__(self, global_env, number_script, n)