コード例 #1
0
ファイル: test_utils.py プロジェクト: spiffytech/npcworld
def test_replace_true():
    new_val_fn = lambda n: n**2
    cmp = lambda n: n % 2 == 0
    seq = (1, 2, 3, 4)

    new_seq = utils.replace_true(new_val_fn, cmp, seq)
    assert new_seq == (1, 4, 3, 16)
コード例 #2
0
ファイル: ai.py プロジェクト: spiffytech/npcworld
def move_dot(old_world, new_world, dot_id, path, speed):  # TODO: Set travel speed while moving. Or something. Have to handle it, since we pass it to the browser, too.
    assert isinstance(path, collections.Iterable)
    assert len(path[0]) == 2
    #import pdb; pdb.set_trace()
    return attr_update(
        new_world,
        entities = lambda entities: utils.replace_true(
            new_val_fn = lambda dot: attr_update(dot, path=path),
            cmp = lambda dot: dot.id == dot_id,
            seq = entities
        )
    )