コード例 #1
0
ファイル: texasHoldEm.py プロジェクト: JohnBrod/PokerBots
class PlaysHand(object):
    def __init__(self, interacts):
        self._interacts = interacts
        self.evt_done = Event()
        self._deck = DealsTexasHoldEm(self._interacts)
        self._takeBets = TakesBets(self._interacts)
        self._takeBets.evt_done += self._onRoundDone

    def start(self):
        for player in self._interacts.players:
            player.dropCards()

        self._deck.start()
        self._takeBets.start()

    def _onRoundDone(self, sender=None, args=None):
        if not self._deck.more() or self._onePlayerLeft():
            self._finish()
        else:
            self._deck.next()
            self._takeBets.next()

    def _finish(self):
        dw = DistributesWinnings(self._interacts)
        dw.toPlayers()
        self.evt_done.fire(self)

    def _onePlayerLeft(self):
        hasCards = len([p for p in self._interacts.players if p.isPlaying()])
        return hasCards == 1
コード例 #2
0
class PlaysHand(object):
    def __init__(self, interacts):
        self._interacts = interacts
        self.evt_done = Event()
        self._deck = DealsTexasHoldEm(self._interacts)
        self._takeBets = TakesBets(self._interacts)
        self._takeBets.evt_done += self._onRoundDone

    def start(self):
        for player in self._interacts.players:
            player.dropCards()

        self._deck.start()
        self._takeBets.start()

    def _onRoundDone(self, sender=None, args=None):
        if not self._deck.more() or self._onePlayerLeft():
            self._finish()
        else:
            self._deck.next()
            self._takeBets.next()

    def _finish(self):
        dw = DistributesWinnings(self._interacts)
        dw.toPlayers()
        self.evt_done.fire(self)

    def _onePlayerLeft(self):
        hasCards = len([p for p in self._interacts.players if p.isPlaying()])
        return hasCards == 1
コード例 #3
0
ファイル: Xmpp.py プロジェクト: JohnBrod/PokerBots
class XmppMessenger(sleekxmpp.ClientXMPP):

    def __init__(self, jid, password):
        sleekxmpp.ClientXMPP.__init__(self, jid, password)
        self.evt_messageReceived = Event()
        self.targets = []

    def on_start(self, event):

        self.send_presence()
        self.get_roster()

    def on_message(self, msg):
        if not chat(msg):
            return

        msg = (getName(msg['from']), msg['body'])
        self.evt_messageReceived.fire(self, msg)

    def listen(self, domain, port):

        self.add_event_handler("session_start", self.on_start)
        self.add_event_handler("message", self.on_message)

        self.register_plugin('xep_0030')  # Service Discovery
        self.register_plugin('xep_0004')  # Data Forms
        self.register_plugin('xep_0060')  # PubSub
        self.register_plugin('xep_0199')  # XMPP Ping

        if self.connect((domain, port)):
            self.process(block=False)
        else:
            logging.error('failed to connect to ' + domain + port)

    def addTarget(self, jid):
        self.targets.append(jid)

    def sendMessage(self, jid, message):
        self.send_message(mto=jid, mbody=str(message), mtype='chat')

    def broadcast(self, msg):
        for target in self.targets:
            self.sendMessage(target, msg)

    def finish(self):
        self.disconnect(wait=True)
コード例 #4
0
ファイル: Xmpp.py プロジェクト: vatsaltrivedi/PokerBots
class XmppMessenger(sleekxmpp.ClientXMPP):
    def __init__(self, jid, password):
        sleekxmpp.ClientXMPP.__init__(self, jid, password)
        self.evt_messageReceived = Event()
        self.targets = []

    def on_start(self, event):

        self.send_presence()
        self.get_roster()

    def on_message(self, msg):
        if not chat(msg):
            return

        msg = (getName(msg['from']), msg['body'])
        self.evt_messageReceived.fire(self, msg)

    def listen(self, domain, port):

        self.add_event_handler("session_start", self.on_start)
        self.add_event_handler("message", self.on_message)

        self.register_plugin('xep_0030')  # Service Discovery
        self.register_plugin('xep_0004')  # Data Forms
        self.register_plugin('xep_0060')  # PubSub
        self.register_plugin('xep_0199')  # XMPP Ping

        if self.connect((domain, port)):
            self.process(block=False)
        else:
            logging.error('failed to connect to ' + domain + port)

    def addTarget(self, jid):
        self.targets.append(jid)

    def sendMessage(self, jid, message):
        self.send_message(mto=jid, mbody=str(message), mtype='chat')

    def broadcast(self, msg):
        for target in self.targets:
            self.sendMessage(target, msg)

    def finish(self):
        self.disconnect(wait=True)
コード例 #5
0
class StubMessenger(object):
    def __init__(self):
        self.evt_playerResponse = Event()
        self.evt_messageReceived = Event()
        self.replies = deque()
        self.sentMessages = []
        self.broadcastMessages = []
        self.goMessages = []
        self.lastMessage = None
        self.cardMessages = []
        self.allMessages = []
        self.dealingMessages = []
        self.wonMessages = []

    def skipBlind(self):
        self.replies.append('skip')
        return self

    def bet(self, player, amount):
        self.replies.append((player, str(amount)))
        return self

    def join(self, jid):
        self.evt_messageReceived.fire(self, (jid, 'JOIN'))

    def addTarget(self, jid):
        pass

    def sendMessage(self, jid, msg):

        # print 'sending', jid, msg
        if msg.startswith('CARD'):
            msg = 'CARD'

        self.allMessages.append((jid, msg))
        self.sentMessages.append((jid, msg))
        self.lastMessage = (jid, msg)
        if msg.startswith('GO'):
            self.goMessages.append((jid, msg))

        if msg.startswith('CARD'):
            self.cardMessages.append((jid, 'CARD'))

        if msg != 'GO' or len(self.replies) == 0:
            return

        response = self.replies.popleft()

        if response == 'skip':
            return

        # print 'responding', response
        self.evt_messageReceived.fire(self, response)
        self.evt_playerResponse.fire(self, response)

    def broadcast(self, msg):
        # print 'broadcasting', msg

        if msg.startswith('CARD'):
            self.cardMessages.append('CARD')
            msg = 'CARD'

        if msg.startswith('WON'):
            self.wonMessages.append(msg)
            msg = 'WON'

        if msg.startswith('DEALING'):
            self.dealingMessages.append(msg)

        if msg.startswith('WINNER'):
            msg = 'WINNER'

        self.allMessages.append(msg)
        self.broadcastMessages.append(msg)
        self.lastMessage = msg