Skip to lesson
Flawless Poker
Galaxy Bot AcademyProgramming Languages and Coding Techniques
INTERMEDIATE · 9 MIN READ · PROGRAMMING LANGUAGES AND CODING TECHNIQUES

Other Languages and the JSON-Line Contract

Learning objectivePort the strategy to any language that can read and write JSON lines.

Understand the idea

The universal adapter launches the command you supply and exchanges newline-delimited JSON over standard input and output. No official Go, Java, C#, or Rust SDK is required. Your program must stay running, read one line at a time, parse an object, decide, and write exactly one flushed JSON object per observation.

In Go, bufio.Scanner plus encoding/json can read and decode lines. In Java, use a JSON library and BufferedReader. In C#, use Console.ReadLine and System.Text.Json. In Rust, BufRead::lines and serde_json are common choices. Those are language facilities, not Galaxy-specific integrations.

At the poker table

A Go process might decode observation.legal.check and write {"kind":"check" to stdout; the adapter supplies the protocol metadata on the HTTP action.

Code and decision sketch

Language-neutral pseudocode
for each line from stdin:
    observation = parse_json(line)
    legal = observation.legal
    action = legal.check ? {kind:'check'} : legal.fold ? {kind:'fold'} : {kind:'call'}
    write_json_line_to_stdout(action)
    flush_stdout()

Common mistake

Do not emit multi-line pretty-printed JSON or status messages on stdout. Confirm the chosen kind is legal before sending it.

Try it yourself

Identify the standard JSON and buffered-input libraries in your preferred language, then write a three-line check/fold decision.