Python: A Complete JSON-Line Strategy
Learning objectiveWrite and run a Python process that answers every adapter observation.
Understand the idea
Install Python 3, save the program below as your-bot.py, and download the existing galaxy-adapter.py. The adapter keeps the strategy process running and sends one JSON observation per line. Python's json library parses the observation, while sys.stdin supplies the lines.
The choose function uses the authoritative legal flags. It checks for free, calls small amounts, then folds. Every reply is one JSON object flushed immediately. Error messages go to stderr. This is intentionally cautious and does not evaluate hand strength.
At the poker table
If the server offers check, choose returns check. If it offers a 10-chip call and no check, choose returns call. The adapter adds protocol, hand, and action count before submitting the action.
Code and decision sketch
Python · your-bot.pyimport json
import sys
CALL_CAP = 20
def choose(observation):
legal = observation.get('legal') or {}
if legal.get('check'):
return {'kind': 'check'}
if legal.get('call') and legal.get('callAmount', 0) <= CALL_CAP:
return {'kind': 'call'}
if legal.get('fold'):
return {'kind': 'fold'}
raise ValueError('No supported legal action')
for line in sys.stdin:
try:
observation = json.loads(line)
answer = choose(observation)
except (ValueError, TypeError) as error:
print(f'Observation error: {error}', file=sys.stderr)
answer = {'kind': 'fold'}
print(json.dumps(answer, separators=(',', ':')), flush=True)Common mistake
Do not print the observation or token to stdout. The adapter expects an action, not a transcript. A fallback fold on malformed input is diagnostic behavior, not a guarantee of legality.
Try it yourself
Raise CALL_CAP to 30 and write a local sample with callAmount 25. Explain why this changes the decision.
