--- /dev/null
+#!/usr/bin/python
+
+"""Go all (or not) depending on whats in the hole.
+"""
+
+import logging
+import os
+import sys
+
+
+class RunComplete (Exception):
+ """Raised after receiving the `END` tag to abort execution.
+ """
+ pass
+
+
+class HoleBot (object):
+ def __init__(self, stdin=None, stdout=None, log_level=logging.WARN):
+ if stdin == None:
+ stdin = sys.stdin
+ self.stdin = stdin
+ if stdout == None:
+ stdout = sys.stdout
+ self.stdout = stdout
+ log_file = '%s_%d.log' % (self.__class__.__name__, os.getpid())
+ logging.basicConfig(filename=log_file, level=log_level)
+ self.log = logging
+
+ def run(self):
+ state = self._initial_state()
+ while True:
+ line = self.stdin.readline().strip()
+ if not line:
+ continue # skip blank lines
+ tag,type,data = self._parse(line)
+ try:
+ self._process(tag, type, data, state)
+ except RunComplete:
+ break
+
+ def _parse(self, line):
+ self.log.debug('read: %s' % line)
+ fields = line.split(' ')
+ try:
+ tag = fields[0]
+ type = fields[1]
+ data = fields[2:]
+ except:
+ self.log.debug('tag only: %s' % str(fields))
+ tag = fields[0]
+ type = data = None
+ self.log.debug('parsed tag %s, type %s, data %s'
+ % (repr(tag), repr(type), repr(data)))
+ return (tag, type, data)
+
+ def _process(self, tag, type, data, state):
+ if tag == 'END':
+ raise RunComplete
+ elif tag == 'MOVE':
+ bet = self._bet(state)
+ self.log.info('bet %s' % bet)
+ self.stdout.write('%s\n' % bet)
+ self.stdout.flush()
+ elif tag == 'INFO' and type == 'HOLE':
+ self._process_hole(data, state)
+ self.log.info('processed hole %s, state: %s' % (data, state))
+
+ def _initial_state(self):
+ return {'all_in': False}
+
+ def _bet(self, state):
+ if state['all_in']:
+ bet = 'A'
+ else:
+ bet = 'f'
+ state['all_in'] = False
+ return bet
+
+ def _process_hole(self, data, state):
+ raise NotImplementedError
--- /dev/null
+#!/usr/bin/python
+
+import logging
+
+from hole_bot import HoleBot
+
+
+class AceBot (HoleBot):
+ """Go all in whenever there is an ace in the hole.
+ """
+ def _process_hole(self, hole, state):
+ state['all_in'] = 'A' in [card[0] for card in hole]
+
+
+if __name__ == '__main__':
+ b = AceBot()#log_level=logging.INFO)
+ b.run()
--- /dev/null
+#!/usr/bin/python
+
+import logging
+
+from hole_bot import HoleBot
+
+
+class PairBot (HoleBot):
+ """Go all in on any pocket pair.
+ """
+ def _process_hole(self, hole, state):
+ state['all_in'] = hole[0][0] == hole[1][0]
+
+
+if __name__ == '__main__':
+ b = PairBot()#log_level=logging.INFO)
+ b.run()
+++ /dev/null
-#!/usr/bin/python
-import sys
-import os
-
-IN, OUT = sys.stdin, sys.stdout
-
-FOUT = open("test_anyAce.txt",'a')
-allin = False
-
-while True:
- std_in = IN.readline().strip()
- if std_in:
- FOUT.write(std_in+'\n')
-
- std_in = std_in.split(' ')
- try :
- tag = std_in[0]
- type = std_in[1]
- data = std_in[2:]
- except:
- #FOUT.write(str(std_in))
- tag = std_in[0]
-
- #FOUT.write(tag+' '+type+' '+str(data)+' '+'\n')
- if tag == "END" : FOUT.close(); exit()
- if tag == "MOVE":
- # You must return a valid bet here
- if allin: OUT.write("A\n")
- else : OUT.write("f\n")
-
- OUT.flush()
- allin = False
-
- elif tag == "INFO" and type == "HOLE":
- # Handle new information
- # Save info to a file and go all in on any Ace
- h1, h2 = data[-1], data[-2]
- #FOUT.write(h1+h2+'\n')
-
- if h1[0]=='A' or h2[0]=='A': allin = True
+++ /dev/null
-#!/usr/bin/python
-import sys
-import os
-
-IN, OUT = sys.stdin, sys.stdout
-
-FOUT = open("test_anyPair.txt",'w')
-allin = False
-
-while True:
- std_in = IN.readline().strip()
- if std_in:
- std_in = std_in.split(' ')
- try :
- tag = std_in[0]
- type = std_in[1]
- data = std_in[2:]
- except:
- FOUT.write(str(std_in))
- tag = std_in[0]
-
- #FOUT.write(tag+' '+type+' '+str(data)+' '+'\n')
-
- if tag == "MOVE":
- # You must return a valid bet here
- if allin: OUT.write("A\n")
- else : OUT.write("f\n")
- OUT.flush()
- allin = False
-
- elif tag == "INFO" and type == "HOLE":
- # Handle new information
- # Save info to a file and go all in on any pair
- h1, h2 = data[-1], data[-2]
-
- if h1[0] == h2[0] and h1[0]=="A": allin = True
-
-
-
-
-
-
-
-
-
-