Skip to content

Latest commit

 

History

History
190 lines (140 loc) · 6.46 KB

File metadata and controls

190 lines (140 loc) · 6.46 KB

Littleman WASM CLI / Public-test Judge

ICFP Programming Contest 2026 公式の littleman.wasm を Node.js から実行する CLI。公式 Web runner の load、round、expected output、Display frame、verdict 処理を再現する。さらに、公式 Web runner が通常の JSON.parse で失う 2^53 超の int64 は decimal string として保持し、誤判定を避ける。

必要環境

  • Node.js 18 以上
  • 初回のみ littleman.wasm の download にネットワーク接続が必要

WASM は https://icfpcontest2026.com/littleman.wasm から自動取得され、 .gitignore 対象となる。

コンテスト中に WASM が更新されることが実際に確認されている。更新後は sha256sum littleman.wasmnpm test の結果を記録すること。

単純実行

./littleman.js -i "50" test_io2.man
# 100

echo "35" | ./littleman.js test_io2.man
# 70

expected output を指定すると公式 Web runner と同じ streaming judge を使う。 正解を出し終えたプログラムは、halt していなくても outputSettled で合格する。

./littleman.js -i "50" -e "100" test_io2.man
# stdout: 100
# stderr: PASS after 7 ticks

Round

input と expected の / が round 境界。round 1 の expected output が揃うまで round 2 の input は WASM 内部で保留される。

./littleman.js \
  -i "1 / 2 / 3" \
  -e "1 / 2 / 3" \
  program.man

Display frame

--framesround → frames → rows の 3 重配列を持つ JSON file を取る。 各 row は色 0–15 を hexadecimal 文字 0f で表す。

[
  [
    ["0000", "0ff0", "0ff0", "0000"],
    ["1111", "1111", "1111", "1111"]
  ]
]
./littleman.js --frames expected-frames.json display.man

WASM の frameJudge を使用するため、最初の誤 frame、不足 frame、余分な通常 output を区別できる。

公開 test の一括実行

公開 problem detail を保存する。

curl https://icfpcontest2026.com/api/v1/public/problems/triangle \
  -o triangle.json

./littleman.js --test-data triangle.json triangle.man
./littleman.js --test-data triangle.json --case four triangle.man
./littleman.js --test-data triangle.json --case 3 triangle.man

publicTestData の単一 round、複数 round、Display frame を自動変換する。 --case の番号は 1-based。tickCap が problem JSON にあれば使用し、なければ 5,000,000 tick。

Option

Run mode:
  -i, --input <values>      Input。"/" は round 境界
  -e, --expected <values>   Expected output。指定時は judge mode
  -f, --frames <file>       Round-grouped expected frame JSON
  -l, --limit <ticks>       最大 tick(default 5,000,000)
      --batch <ticks>       1 回の stepN(default 5,000)
      --stop-on-frame       frame commit ごとに stepN から戻る

Public-test mode:
  -t, --test-data <file>    Problem detail JSON の publicTestData を実行
  -c, --case <name|number>  1 test だけ実行

Output/setup:
  -j, --json                JSON result
  -v, --verbose             load と全 tick snapshot
      --metadata            validOps と structuralGlyphs
  -d, --download            WASM を再取得
  -h, --help

Status

  • done: judge なしの実行が正常 halt。
  • pass: expected output と全 frame が一致。
  • fail: wrong/extra/missing output、frame mismatch。
  • load-error: room、pipe、literal 等の load error。
  • crash: wall, bad-op, no-pipe, Display error 等。
  • execution-error: WASM API の structured error。
  • timeout: tick 上限まで verdict が出ない。

終了 code は done/pass が 0、実行・判定失敗が 1、CLI usage error が 2。

Test

npm test

回帰 test は次を実際の公式 WASM で検査する。

  • 従来の整数 I/O
  • Web editor と同じ外側 margin crop・座標復元
  • correct/wrong expected output
  • structured load error と runtime bad-op
  • halt しないプログラムの outputSettled
  • round input の保留・解放
  • Display frame の一致・不一致
  • step limit
  • problem-detail publicTestData
  • staging 済みだが Reference 未掲載の Y の実測動作
  • int64 の WASM JSON 境界での lossless 処理

WASM 自体の再現可能な black-box probe:

npm run audit        # 境界値、layout、collision、JSON 精度
npm run audit:fuzz   # seed 固定の算術差分 test 1,000 件
npm run audit:deep   # 65,536-runner の Y 上限(約 20 秒、メモリ消費大)

詳細な reverse engineering 記録は ../aidoc/WebRunner.md../aidoc/WasmAudit.md を参照。

ソースコードの回転・反転 (Transformation Tool)

プログラム(.man ソースコード)を回転・反転させるユーティリティ transform.js が利用可能です。このツールは、部屋の内部にある算術・論理演算の -| といった「命令」のセマンティクスを維持したまま、構造物としての壁やパイプライン(> < ^ v - |)を適切に回転・反転させます。

実行方法

# 90度時計回りに回転
node transform.js rot90 input.man output.man

# 左右反転(水平反転)
node transform.js flip-x input.man output.man

# 標準入力から受け取って標準出力へ出力
cat input.man | node transform.js rot180 > output.man

変換タイプ

  • flip-x / flip-h: 左右反転
  • flip-y / flip-v: 上下反転
  • rot90 / rot90cw: 90度時計回り回転
  • rot180: 180度回転
  • rot270 / rot90ccw: 90度反時計回り回転
  • transpose: 主対角線による転置
  • anti-transpose: 反対角線による転置

オプション

  • --raw: 部屋の解析を行わず、グリッド全体の -| を単純に入れ替えます(命令としての - / | も置換されます)。

注意点

  1. Little man の初期方向: @ で生成される little man は、常に東(右)を向いて開始します。プログラムを回転または反転した場合、@ の周辺レイアウト(進む先が壁にならないようにするなど)をユーザー自身で調整する必要があります。
  2. LM-75 Display の接続: ディスプレイのポート定義(上辺 ADDR、左辺 DATA、下辺 SWAP)は VM 側で固定されています。ディスプレイ自体を回転させた場合は、パイプの接続ポートを正しく再配線する必要があります。