clawtan 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clawtan/cli.py +64 -1
- package/package.json +1 -1
package/clawtan/cli.py
CHANGED
|
@@ -390,6 +390,15 @@ def _print_opponents(opponents: list):
|
|
|
390
390
|
print(line)
|
|
391
391
|
|
|
392
392
|
|
|
393
|
+
def _format_trade_tuple(val: list) -> str:
|
|
394
|
+
"""Decode a 10-int trade tuple into 'give X for Y' text."""
|
|
395
|
+
giving = {RESOURCES[i]: val[i] for i in range(5) if val[i]}
|
|
396
|
+
wanting = {RESOURCES[i]: val[i + 5] for i in range(5) if val[i + 5]}
|
|
397
|
+
give_str = ", ".join(f"{n}x {r}" for r, n in giving.items()) or "nothing"
|
|
398
|
+
want_str = ", ".join(f"{n}x {r}" for r, n in wanting.items()) or "nothing"
|
|
399
|
+
return f"{give_str} for {want_str}"
|
|
400
|
+
|
|
401
|
+
|
|
393
402
|
_ACTION_HINTS = {
|
|
394
403
|
"RELEASE_CATCH": (
|
|
395
404
|
"Discard half your cards (server selects randomly).\n"
|
|
@@ -408,6 +417,29 @@ _ACTION_HINTS = {
|
|
|
408
417
|
"Year of Plenty: pick 2 free resources.\n"
|
|
409
418
|
" CLI: clawtan act PLAY_BOUNTIFUL_HARVEST '[\"DRIFTWOOD\",\"CORAL\"]'"
|
|
410
419
|
),
|
|
420
|
+
"OFFER_TRADE": (
|
|
421
|
+
"Offer a player-to-player trade. Value = 10-element list:\n"
|
|
422
|
+
" first 5 = resources you GIVE [DRIFTWOOD,CORAL,SHRIMP,KELP,PEARL],\n"
|
|
423
|
+
" last 5 = resources you WANT [DRIFTWOOD,CORAL,SHRIMP,KELP,PEARL].\n"
|
|
424
|
+
" CLI: clawtan act OFFER_TRADE '[0,0,0,1,0,0,1,0,0,0]' # give 1 KELP, want 1 CORAL"
|
|
425
|
+
),
|
|
426
|
+
"ACCEPT_TRADE": (
|
|
427
|
+
"Accept a trade offer. Value = the 10-int trade tuple (echoed from the offer).\n"
|
|
428
|
+
" CLI: clawtan act ACCEPT_TRADE '[0,0,0,1,0,0,1,0,0,0]'"
|
|
429
|
+
),
|
|
430
|
+
"REJECT_TRADE": (
|
|
431
|
+
"Reject a trade offer. Value = the 10-int trade tuple (echoed from the offer).\n"
|
|
432
|
+
" CLI: clawtan act REJECT_TRADE '[0,0,0,1,0,0,1,0,0,0]'"
|
|
433
|
+
),
|
|
434
|
+
"CONFIRM_TRADE": (
|
|
435
|
+
"Confirm trade with a specific acceptee. Value = 11-element list:\n"
|
|
436
|
+
" the 10-int trade tuple + the accepting player's color.\n"
|
|
437
|
+
" CLI: clawtan act CONFIRM_TRADE '[0,0,0,1,0,0,1,0,0,0,\"BLUE\"]'"
|
|
438
|
+
),
|
|
439
|
+
"CANCEL_TRADE": (
|
|
440
|
+
"Cancel your pending trade offer.\n"
|
|
441
|
+
" CLI: clawtan act CANCEL_TRADE"
|
|
442
|
+
),
|
|
411
443
|
}
|
|
412
444
|
|
|
413
445
|
|
|
@@ -671,6 +703,30 @@ def _format_live_action(color, action, val, state=None, pre_resources=None):
|
|
|
671
703
|
if action == "PLAY_CURRENT_BUILDING":
|
|
672
704
|
return f" [{ts}] {color} played Road Building"
|
|
673
705
|
|
|
706
|
+
if action == "OFFER_TRADE":
|
|
707
|
+
if isinstance(val, list) and len(val) == 10:
|
|
708
|
+
return f" [{ts}] {color} offered trade: {_format_trade_tuple(val)}"
|
|
709
|
+
return f" [{ts}] {color} offered a trade"
|
|
710
|
+
|
|
711
|
+
if action == "ACCEPT_TRADE":
|
|
712
|
+
if isinstance(val, list) and len(val) == 10:
|
|
713
|
+
return f" [{ts}] {color} accepted trade: {_format_trade_tuple(val)}"
|
|
714
|
+
return f" [{ts}] {color} accepted a trade"
|
|
715
|
+
|
|
716
|
+
if action == "REJECT_TRADE":
|
|
717
|
+
if isinstance(val, list) and len(val) == 10:
|
|
718
|
+
return f" [{ts}] {color} rejected trade: {_format_trade_tuple(val)}"
|
|
719
|
+
return f" [{ts}] {color} rejected a trade"
|
|
720
|
+
|
|
721
|
+
if action == "CONFIRM_TRADE":
|
|
722
|
+
if isinstance(val, list) and len(val) == 11:
|
|
723
|
+
partner = val[10]
|
|
724
|
+
return f" [{ts}] {color} confirmed trade with {partner}: {_format_trade_tuple(val[:10])}"
|
|
725
|
+
return f" [{ts}] {color} confirmed a trade"
|
|
726
|
+
|
|
727
|
+
if action == "CANCEL_TRADE":
|
|
728
|
+
return f" [{ts}] {color} cancelled their trade offer"
|
|
729
|
+
|
|
674
730
|
if action == "OCEAN_TRADE":
|
|
675
731
|
if isinstance(val, list) and len(val) >= 2:
|
|
676
732
|
giving = val[:-1]
|
|
@@ -1354,7 +1410,14 @@ def main():
|
|
|
1354
1410
|
" PLAY_BOUNTIFUL_HARVEST <r> Year of Plenty, e.g. '[\"DRIFTWOOD\",\"CORAL\"]'\n"
|
|
1355
1411
|
" PLAY_TIDAL_MONOPOLY <res> Monopoly, e.g. SHRIMP\n"
|
|
1356
1412
|
" PLAY_CURRENT_BUILDING Road Building\n"
|
|
1357
|
-
"
|
|
1413
|
+
" OFFER_TRADE <val> Player trade: 10-element list [give5, want5]\n"
|
|
1414
|
+
" e.g. '[0,0,0,1,0,0,1,0,0,0]' = give 1 KELP, want 1 CORAL\n"
|
|
1415
|
+
" ACCEPT_TRADE <val> Accept a trade offer (echo the 10-int tuple)\n"
|
|
1416
|
+
" REJECT_TRADE <val> Reject a trade offer (echo the 10-int tuple)\n"
|
|
1417
|
+
" CONFIRM_TRADE <val> Confirm with acceptee: 10 ints + color, e.g.\n"
|
|
1418
|
+
" '[0,0,0,1,0,0,1,0,0,0,\"BLUE\"]'\n"
|
|
1419
|
+
" CANCEL_TRADE Cancel your pending trade offer\n"
|
|
1420
|
+
" OCEAN_TRADE <val> Maritime trade, e.g. '[\"KELP\",\"KELP\",\"KELP\",\"KELP\",\"SHRIMP\"]'\n"
|
|
1358
1421
|
" END_TIDE End your turn\n"
|
|
1359
1422
|
"\n"
|
|
1360
1423
|
"VALUE is parsed as JSON. Bare words (e.g. SHRIMP) are treated as strings.\n"
|