コード例 #1
0
ファイル: test_build_choice.py プロジェクト: zzkklep/thbattle
    def testImperialChoice(self):
        from thb.item import ImperialChoice
        from thb.characters.sp_aya import SpAya

        class p:
            class account:
                userid = 1

        pi = {1: ['imperial-choice:SpAya', 'foo']}
        eq_(ImperialChoice.get_chosen(pi, [p]), [(p, SpAya)])
コード例 #2
0
    def testImperialChoice(self):
        from thb.item import ImperialChoice
        from thb.characters.sp_aya import SpAya

        class p:
            class account:
                userid = 1

        pi = {1: ['imperial-choice:SpAya', 'foo']}
        eq_(ImperialChoice.get_chosen(pi, [p]), [(p, SpAya)])
コード例 #3
0
def build_choices(g, items, candidates, players, num, akaris, shared):
    from thb.item import ImperialChoice
    from thb.characters.baseclasses import Character

    # ANCHOR(test)
    # ----- testing -----
    all_characters = Character.character_classes
    testing = list(all_characters[i] for i in settings.TESTING_CHARACTERS)
    candidates, _ = partition(lambda c: c not in testing, candidates)

    if g.SERVER_SIDE:
        candidates = list(candidates)
        g.random.shuffle(candidates)
    else:
        candidates = [None] * len(candidates)

    if shared:
        entities = ['shared']
        num = [num]
        akaris = [akaris]
    else:
        entities = players

    assert len(num) == len(akaris) == len(entities), 'Uneven configuration'
    assert sum(num) <= len(candidates) + len(testing), 'Insufficient choices'

    result = defaultdict(list)

    entities_for_testing = entities[:]

    candidates = list(candidates)
    seed = get_seed_for(g.players)
    shuffler = random.Random(seed)
    shuffler.shuffle(entities_for_testing)

    for e, cls in zip(cycle(entities_for_testing), testing):
        result[e].append(CharChoice(cls))

    # ----- imperial (force chosen by ImperialChoice) -----
    imperial = ImperialChoice.get_chosen(items, players)
    imperial = [(p, CharChoice(cls)) for p, cls in imperial]

    for p, c in imperial:
        result['shared' if shared else p].append(c)

    # ----- normal -----
    for e, n in zip(entities, num):
        for _ in xrange(len(result[e]), n):
            result[e].append(CharChoice(candidates.pop()))

    # ----- akaris -----
    if g.SERVER_SIDE:
        rest = candidates
    else:
        rest = [None] * len(candidates)

    g.random.shuffle(rest)

    for e, n in zip(entities, akaris):
        for i in xrange(-n, 0):
            result[e][i].set(rest.pop(), True)

    # ----- compose final result, reveal, and return -----
    if shared:
        result = OrderedDict([(p, result['shared']) for p in players])
    else:
        result = OrderedDict([(p, result[p]) for p in players])

    for p, l in result.items():
        p.reveal(l)

    return result, imperial
コード例 #4
0
def build_choices(g, items, candidates, players, num, akaris, shared):
    from thb.item import ImperialChoice
    from thb.characters.baseclasses import Character

    # ANCHOR(test)
    # ----- testing -----
    all_characters = Character.character_classes
    testing = list(all_characters[i] for i in settings.TESTING_CHARACTERS)
    candidates, _ = partition(lambda c: c not in testing, candidates)

    if g.SERVER_SIDE:
        candidates = list(candidates)
        g.random.shuffle(candidates)
    else:
        candidates = [None] * len(candidates)

    if shared:
        entities = ['shared']
        num = [num]
        akaris = [akaris]
    else:
        entities = players

    assert len(num) == len(akaris) == len(entities), 'Uneven configuration'
    assert sum(num) <= len(candidates) + len(testing), 'Insufficient choices'

    result = defaultdict(list)

    entities_for_testing = entities[:]

    candidates = list(candidates)
    seed = get_seed_for(g.players)
    shuffler = random.Random(seed)
    shuffler.shuffle(entities_for_testing)

    for e, cls in zip(cycle(entities_for_testing), testing):
        result[e].append(CharChoice(cls))

    # ----- imperial (force chosen by ImperialChoice) -----
    imperial = ImperialChoice.get_chosen(items, players)
    imperial = [(p, CharChoice(cls)) for p, cls in imperial]

    for p, c in imperial:
        result['shared' if shared else p].append(c)

    # ----- normal -----
    for e, n in zip(entities, num):
        for _ in xrange(len(result[e]), n):
            result[e].append(CharChoice(candidates.pop()))

    # ----- akaris -----
    if g.SERVER_SIDE:
        rest = candidates
    else:
        rest = [None] * len(candidates)

    g.random.shuffle(rest)

    for e, n in zip(entities, akaris):
        for i in xrange(-n, 0):
            result[e][i].set(rest.pop(), True)

    # ----- compose final result, reveal, and return -----
    if shared:
        result = OrderedDict([(p, result['shared']) for p in players])
    else:
        result = OrderedDict([(p, result[p]) for p in players])

    for p, l in result.items():
        p.reveal(l)

    return result, imperial