Skip to content

Commit

Permalink
Oink.
Browse files Browse the repository at this point in the history
  • Loading branch information
pbl64k committed Jun 19, 2011
1 parent 2762fac commit 17fc7ac
Showing 1 changed file with 79 additions and 26 deletions.
105 changes: 79 additions & 26 deletions ltg/src/loop_de_loop.py
@@ -1,7 +1,7 @@

import sys

from rules import cards, SLOTS, MAX_SLOT, LEFT_APP, RIGHT_APP
from rules import cards, SLOTS, MAX_SLOT, LEFT_APP, RIGHT_APP, IntValue
from sequence_bot import SequenceBot
from simple_bot import Bot
from slot_killer import SequenceBotNone
Expand All @@ -13,17 +13,22 @@ def loop_de_loop_bot():


class LambdaSequenceBot(Bot):
def __init__(self, slot, lmb, lcl):
def __init__(self, slot, lmb, lcl, add = None):
self.slot = slot
self.lmb = lmb
self.lcl = lcl
self.add = None

def set_game(self, game):
super(LambdaSequenceBot, self).set_game(game)
self.sequence = self.mk_seq()

def choose_move(self):
return self.sequence.choose_move()
move = self.sequence.choose_move()
if move == None:
move = self.add
self.add = None
return move

def mk_seq(self):
sequence = []
Expand All @@ -41,6 +46,7 @@ def mk_seq(self):

class MultipleLambdaSequencesBot(Bot):
def __init__(self, bots, lcl):
self.boost_term = number_term(8192)
self.boostable = True
self.lcl = lcl
self.bots = []
Expand All @@ -53,35 +59,59 @@ def set_game(self, game):
bot.set_game(game)

def boost_muthafucka(self, critical_slot):
self.boostable = False
boost = number_term(8192)
boost_slot = reduce(lambda x, y: y if scnt(y[0]) < scnt(x[0]) and y[0] > 3 and y[1] >= 10000 else x, zip(range(SLOTS), self.game.proponent.vitalities), (255, 0))[0]
crtslot = number_term(critical_slot)
bstslot = number_term(boost_slot)
boost_bot = LambdaSequenceBot(boost_slot, r'(put I help bstslot crtslot boost)', locals())
boost_bot.set_game(self.game)
self.bots.insert(0, boost_bot)
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)

def revive_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
crtslot = number_term(critical_slot)
boost_bot = LambdaSequenceBot(boost_slot, r'(crtslot)', locals(), (LEFT_APP, boost_slot, cards.revive))
boost_bot.set_game(self.game)
self.bots.insert(0, boost_bot)

def choose_move(self):
if self.boostable:
for critical_slot in range(4):
if self.game.proponent.vitalities[critical_slot] < 60000:
if self.game.proponent.vitalities[critical_slot] <= 0:
self.revive_muthafucka(critical_slot)
break
if self.game.proponent.vitalities[critical_slot] < 10000:
self.boost_muthafucka(critical_slot)
break
for bot in self.bots:
move = bot.choose_move()
if move != None:
return move
self.boostable = True
return None
if len(self.bots) == 0:
return None
cur_bot = self.bots[0]
move = cur_bot.choose_move()
if move == None:
self.boostable = True
self.bots = self.bots[1:]
return self.choose_move()
return move
#for bot in self.bots:
# move = bot.choose_move()
# if move != None:
# return move
#self.boostable = True


class LoopDeLoop(Bot):
def __init__(self):
self.terminate = False
voltage = number_term(40960)
otake = number_term(4096)
tgt = number_term(255)
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))'),
Expand All @@ -93,7 +123,7 @@ def __init__(self):
#(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'(zero)'),
(2, r'(tgt)'),
(3, r'(put I get zero I)'),
], locals())

Expand All @@ -114,8 +144,31 @@ 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.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([
Expand All @@ -125,7 +178,7 @@ def choose_move(self):
self.sequence.set_game(self.game)
self.terminate = False
return self.choose_move()
elif self.game.opponent.vitalities[MAX_SLOT - self.game.proponent.values[2]] > 0:
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())
Expand All @@ -139,7 +192,7 @@ def choose_move(self):
self.sequence.set_game(self.game)
self.terminate = False
return self.choose_move()
elif self.game.opponent.vitalities[MAX_SLOT - self.game.proponent.values[2]] <= 0:
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:
Expand Down

0 comments on commit 17fc7ac

Please sign in to comment.