Exemplo n.º 1
0
 def boost_muthafucka(self, critical_slot):
     boost_slot = reduce(lambda x, y: y if scnt(y[0]) < scnt(x[0]) and y[0] > 31 and y[1] >= 10000 and str(y[2]) == 'I' else x, zip(range(SLOTS), self.game.proponent.vitalities, self.game.proponent.values), (255, 0, ''))[0]
     if boost_slot != 255:
         self.boostable = False
         boost = self.boost_term
         crtslot = number_term(critical_slot)
         bstslot = number_term(boost_slot)
         boost_bot = LambdaSequenceBot(boost_slot, r'(help bstslot crtslot boost)', locals())
         boost_bot.set_game(self.game)
         self.bots.insert(0, boost_bot)
Exemplo n.º 2
0
 def mk_seq(self):
     batslot = number_term(self.battery_slot)
     boost = number_term(self.boost)
     sequence = []
     for t in [
         r'(S help I batslot boost)',
         ]:
         t = parse_lambda(t, locals())
         t = binarize_term(t)
         sequence += term_to_sequence(t)
     seq = SequenceBotNone(sequence, self.execution_slot)
     seq.set_game(self.game)
     return seq
Exemplo n.º 3
0
def test_combo_bot(slot = 0):
    tgtslot = number_term(0)
    selfslot = number_term(slot)
    #m = number_term(INITIAL_VITALITY)
    sequence = []
    for t in [
        #r'((\c f x. (\i. (\g. i c f x) (i f x))) (\c f x. (\i. (\g. i c f x) (i f x))) (dec) (zero))',
        r'(((\atkslot icomb. K (icomb get selfslot) (icomb dec atkslot)) tgtslot) I)',
        ]:
        t = parse_lambda(t, locals())
        t = binarize_term(t)
        sequence += term_to_sequence(t)
    return SequenceBot(sequence, slot)
Exemplo n.º 4
0
 def mk_seq(self):
     batslot = number_term(self.battery_slot)
     boost = number_term(40960)
     sequence = []
     for t in [
         r'(\icomb. (K (icomb get batslot)) (icomb S help I batslot boost))',
         ]:
         t = parse_lambda(t, locals())
         t = binarize_term(t)
         sequence += term_to_sequence(t)
     seq = SequenceBotNone(sequence, self.battery_slot)
     seq.set_game(self.game)
     return seq
Exemplo n.º 5
0
 def mk_seq(self):
     batslot = number_term(self.battery_slot)
     atkslot = number_term(MAX_SLOT - self.target_slot)
     dmg = number_term(self.dmg)
     sequence = []
     for t in [
         r'(attack batslot atkslot dmg)',
         ]:
         t = parse_lambda(t, locals())
         t = binarize_term(t)
         sequence += term_to_sequence(t)
     seq = SequenceBotNone(sequence, self.execution_slot)
     seq.set_game(self.game)
     return seq
Exemplo n.º 6
0
 def mk_seq(self):
     batslot = number_term(self.battery_slot)
     pppslot = number_term(self.pain_slot)
     obsslot = number_term(self.observer_slot)
     ggeslot = number_term(self.gauge_slot)
     sequence = []
     for t in [
         r"(\icomb. (K (icomb get batslot)) ((K (((S help I) batslot) (icomb get pppslot))) (attack batslot (icomb get obsslot) (icomb get ggeslot))))"
     ]:
         t = parse_lambda(t, locals())
         t = binarize_term(t)
         sequence += term_to_sequence(t)
     seq = SequenceBotNone(sequence, self.battery_slot)
     seq.set_game(self.game)
     return seq
Exemplo n.º 7
0
 def __init__(self, bots, lcl):
     self.boost_term = number_term(8192)
     self.boostable = True
     self.lcl = lcl
     self.bots = []
     for bot_slot, bot_lmb in bots:
         self.bots.append(LambdaSequenceBot(bot_slot, bot_lmb, self.lcl))
Exemplo n.º 8
0
    def allocate_register(self, register_slot):
        if not self.is_slot_available(register_slot):
            return False
        prop = self.game.proponent
        register_clean = str(prop.values[register_slot]) == 'I'
        
        terms = [goal.term for goal in self.goals]
        
        register_access = (cards.get, number_term(register_slot))
        register_cost = sequential_cost(register_access)
        sub_term, advantage = optimal_subterm(register_cost, *terms)
        
        if not register_clean:
            advantage -= 1
            # because we have to clean it up
        
        if advantage <= 0:
            return False
        
        sub_goal = Goal(sub_term, register_slot)
        
        self.introduce_get(sub_term, register_access)

        self.add_goal(sub_goal)
        
        return True
Exemplo n.º 9
0
def test_seq_bot(slot = 0):
    n = number_term(8192)
    m = number_term(INITIAL_VITALITY)

    #Y = r'(\f. (\q. q q) (\x. f (x x)))'
    #Y = parse_lambda(Y)

    sequence = []
    
    for t in [
        r'(attack zero zero n)',
        r'(attack (succ zero) zero n)',
        r'(zombie zero (\id. (help ((id succ) zero) zero m))'
        ]:
        t = parse_lambda(t, locals())
        t = binarize_term(t)
        sequence += term_to_sequence(t)

    return SequenceBot(sequence, slot)
Exemplo n.º 10
0
 def mk_seq(self):
     value = number_term(self.value)
     sequence = []
     for t in [
         r'((put I) value)',
         ]:
         t = parse_lambda(t, locals())
         t = binarize_term(t)
         sequence += term_to_sequence(t)
     seq = SequenceBotNone(sequence, self.slot)
     seq.set_game(self.game)
     return seq
Exemplo n.º 11
0
 def __init__(self):
     self.terminate = False
     self.voltage = number_term(8192)
     self.otake = number_term(768)
     self.tgt = number_term(255)
     voltage = self.voltage
     otake = self.otake
     tgt = self.tgt
     self.sequence = MultipleLambdaSequencesBot([
                                                ####(2, r'(\icomb. (icomb K (icomb get (succ (succ zero))) icomb) ((icomb get zero) (icomb get (succ zero))))'),
                                                ####(2, r'(\zeroarg icomb. (K (icomb (get (succ (succ zero))) (succ zeroarg) icomb)) ((icomb get zero) zeroarg))'),
                                                ###(2, r'(\zeroarg icomb. ((icomb get) (succ (succ zero)) (succ zeroarg)) ((icomb get) zero zeroarg))'),
                                                ###(0, r'(\x. help x x voltage)'),
                                                ####(1, r'(voltage)'),
                                                ###(3, r'((get (succ (succ zero))) zero I)'),
                                                #(2, r'(\icomb. (icomb K (icomb get (succ (succ zero))) icomb) ((icomb get zero) (icomb get (succ zero))))'),
                                                #(2, r'(\zeroarg icomb. (K (icomb (get (succ (succ zero))) (succ zeroarg) icomb)) ((icomb get zero) zeroarg))'),
                                                (0, r'(\icomb. icomb get 0 (icomb get 1 (icomb get 2)))'),
                                                (1, r'(\x. (\ic. ic attack 0 x otake) (K I x help 0 0 voltage))'),
                                                (2, r'(tgt)'),
                                                (3, r'(put I get zero I)'),
                                                ], locals())
Exemplo n.º 12
0
    def rec(cur, depth):
        global cnt
        scur = str(cur)

        if scur.isdigit() and scur not in optimized_numbers:
            t = terms.number_term(int(scur))
            cost = terms.sequential_cost(t)
            if cost > len(steps):
                print len(steps), steps_to_str(steps), "->", scur
            optimized_numbers.add(scur)

        if scur in desired:
            print len(steps), steps_to_str(steps), "->", scur
            desired.remove(scur)
            if len(desired) == 0:
                print "Done. Press enter to exit"
                raw_input()
                exit()
        if depth == 0:
            return
        cnt += 1
        if cnt % 500000 == 0:
            print cnt
        for i, (f, side) in enumerate(possible_steps):
            if len(steps) == 0 and i % num_parts != our_part:
                continue
            try:
                context.app_limit = 30
                if side == "r":
                    next = apply(cur, f, context)
                else:
                    next = apply(f, cur, context)
            except Error as e:
                continue
            # except Exception as e:
            #    print steps_to_str(steps+[(f, side)])
            #    print e
            #    raise e
            #    exit()
            steps.append((f, side))
            rec(next, depth - 1)
            steps.pop()
Exemplo n.º 13
0
 def reuse_shit(self):
     assert self.current_goal is None
     
     prop = self.game.proponent
     terms = [goal.term for goal in self.goals]
     costs, _ = calc_costs_and_weights(*terms)
     for slot in slot_numbers_by_reachability:
         if prop.vitalities[slot] <= 0:
             continue
         value = prop.values[slot]
         if value == cards.I:
             continue # for speed
         shit = value_to_term(value)
         shit = unfold_numbers(shit)
         if shit in costs:
             access = (cards.get, number_term(slot))
             if sequential_cost(access) < costs[shit]:
                 if self.is_slot_available(slot):
                     self.introduce_get(shit, access)
             del costs[shit]
Exemplo n.º 14
0
    def choose_move(self):
        if self.terminate:
            danger = self.spider_sense()

#            if self.we_re_done_for():
#                return (LEFT_APP, 0, cards.I)
            if self.game.proponent.vitalities[0] > 0 and str(self.game.proponent.values[0]) == 'I':
                self.sequence = MultipleLambdaSequencesBot([
                                                           (0, r'(\icomb. icomb get 0 (icomb get 1 (icomb get 2)))'),
                                                           ], locals())
                self.sequence.set_game(self.game)
                self.terminate = False
                return self.choose_move()
            elif self.game.proponent.vitalities[1] > 0 and str(self.game.proponent.values[1]) == 'I':
                voltage = self.voltage
                otake = self.otake
                self.sequence = MultipleLambdaSequencesBot([
                                                           (1, r'(\x. (\ic. ic attack 0 x otake) (K I x help 0 0 voltage))'),
                                                           ], locals())
                self.sequence.set_game(self.game)
                self.terminate = False
                return self.choose_move()
            elif self.game.proponent.vitalities[2] > 0 and str(self.game.proponent.values[2]) == 'I':
                self.sequence = MultipleLambdaSequencesBot([
                                                           (2, r'(zero)'),
                                                           ], locals())
                self.sequence.set_game(self.game)
                self.terminate = False
                return self.choose_move()
            elif danger != -1:
                dng = number_term(MAX_SLOT - danger)
                self.sequence = MultipleLambdaSequencesBot([
                                                           (2, r'(put I dng)'),
                                                           (3, r'(put I get zero I)'),
                                                           ], locals())
                self.sequence.set_game(self.game)
                self.terminate = False
                return self.choose_move()
            elif isinstance(self.game.proponent.values[2], IntValue) and self.game.opponent.vitalities[MAX_SLOT - self.game.proponent.values[2]] > 0:
                self.sequence = MultipleLambdaSequencesBot([
                                                           (3, r'(put I get zero I)'),
                                                           ], locals())
                self.sequence.set_game(self.game)
                self.terminate = False
                return self.choose_move()
            elif self.game.proponent.values[2] == 255:
                self.sequence = MultipleLambdaSequencesBot([
                                                           (2, r'(put I zero)'),
                                                           ], locals())
                self.sequence.set_game(self.game)
                self.terminate = False
                return self.choose_move()
            elif isinstance(self.game.proponent.values[2], IntValue) and self.game.opponent.vitalities[MAX_SLOT - self.game.proponent.values[2]] <= 0:
                self.terminate = False
                return (LEFT_APP, 2, cards.succ)
            else:
                self.terminate = False
                return (LEFT_APP, 2, cards.succ)
        move = self.sequence.choose_move()
        if move != None:
            return move
        self.terminate = True
        return self.choose_move()
Exemplo n.º 15
0
def attack_term(i, j, n):
    i = number_term(i)
    j = number_term(j)
    n = number_term(n)
    return (cards.attack, i, j, n)
Exemplo n.º 16
0
    
    def introduce_get(self, sub_term, register_access):
        g, register_slot = fold_numbers(register_access)
        assert isinstance(register_slot, int)
        assert g == cards.get
        
        self.gets.add(register_slot)
        
        if not is_subterm_eager(sub_term, self.term):
            self.lazy_gets.add(register_slot)
        self.term = replace_leaf_subterm(sub_term, register_access, self.term)


slot_numbers_by_reachability = sorted(
    range(rules.SLOTS), 
    key=lambda n: sequential_cost(number_term(n)))


class NetworkFail(Exception):
    pass


def global_optimize_network(network):
    best = None
    best_cost = 1e100
    orig = str(network)
    for reg_count in [1]+[3]*5:
        assert str(network) == orig
        t = network.clone()
        t.reg_count = reg_count
        t.refine()