Esempio n. 1
0
deck = Dominion.Deck(specs)

resultbatch = Dominion.ResultBatch()
decks = {}
modifs = []

start = time.time()
delay = 0.1
try:
    while True:
        resultbatch.base.accumulate(Dominion.Hand(deck).play())
        for m in modifs:
            resultbatch.accumulate(m, Dominion.Hand(decks[m]).play())
        now = time.time()
        if now - start > delay:
            start = now
            Interop.send(sys.stdout, resultbatch)
            modifs = Interop.recv(sys.stdin)
            for m in modifs:
                if m not in decks:
                    d = deck.clone()
                    for mod in m:
                        d.applyModif('+' + mod)
                    decks[m] = d
            resultbatch.reset()
except IOError, e:
    if e.errno != 32:
        raise e
except KeyboardInterrupt:
    pass
Esempio n. 2
0
numbers = [ord(str(x)) for x in [1,2,3,4,5,6,7,8,9,0]]

cardchoices = dict(zip(numbers, cards) + [(ord('w'), 'Copper'), (ord('e'), 'Silver'), (ord('r'), 'Gold'),
                                          (ord('s'), 'Estate'), (ord('d'), 'Duchy'), (ord('f'), 'Province')])

modifs = []

try:
    window = curses.initscr()
    rows, cols = window.getmaxyx()
    window.timeout(0)

    while running:
        for w in workers:
            resultbatch.add(Interop.recv(w.stdout))
            Interop.send(w.stdin, modifs)

        c = window.getch()
        if inputstate == 'main':
            if c == ord('q'):
                running = False
            elif c == ord('a'):
                inputstate = 'add'
            elif c == ord('r'):
                inputstate = 'remove'
        elif inputstate == 'add':
            if c in cardchoices:
                addToDeck(deck, cardchoices[c])
                stop_workers()
                start_workers(deck)