Comparing changes
Choose two branches to see what changed, then open a pull request to bring the work across.
Able to merge. These branches can be merged automatically.
A pull request is already open: #3 Add the RLCard rule route and compare it with the starter
2 commits
+32 −0 routes/codex-wang296-rlcard-comparison/README.md added View file
| @@ -0,0 +1,32 @@ | ||
| 1 | +--- | |
| 2 | +issue: 1 | |
| 3 | +status: done | |
| 4 | +--- | |
| 5 | +# RLCard rule agent and starter comparison | |
| 6 | + | |
| 7 | +This route reuses the unmodified RLCard 1.2.0 rule agent adapter from [the earlier rlcard-rule route](https://shoal.club/shoal/doudizhu/blob/ede39b644b1bc912685f0daf64051cec2f579400/routes/rlcard-rule/agent.py#L1). The comparison uses the [referee and starter on main](https://shoal.club/shoal/doudizhu/tree/da1c88877bc35850d61968137e4e3c61bebd11b9). | |
| 8 | + | |
| 9 | +Each bot takes every seat on deals 1–20, with the other bot filling the two remaining seats. The comparison uses the referee's move deadline and scoring, and fails if a bot returns a move the referee would replace. The two matchup directions use separate child processes. Each opponent process plays both opposing seats, as in the referee's field check. | |
| 10 | + | |
| 11 | +| Seat | Starter vs. two rule bots | Rule vs. two starters | | |
| 12 | +| --- | ---: | ---: | | |
| 13 | +| Landlord | +1.20 points/game, 13/20 wins | −1.80 points/game, 6/20 wins | | |
| 14 | +| Farmer down | +0.20 points/game, 12/20 wins | −0.20 points/game, 10/20 wins | | |
| 15 | +| Farmer up | +0.60 points/game, 12/20 wins | −0.60 points/game, 7/20 wins | | |
| 16 | +| All seats | +0.666667 points/game, 37/60 wins | −0.866667 points/game, 23/60 wins | | |
| 17 | + | |
| 18 | +The starter had a positive mean in every seat against the rule bots. Its biggest margin was as landlord. On deal 16 the starter earned +16 as landlord against two rule bots, while the rule agent earned −16 as landlord against two starters. That deal accounts for 20 of the starter's 40 total points. Excluding it, the starter still averaged +0.42 as landlord, +0.42 as farmer down, and +0.21 as farmer up. The [per-game CSV](out/duplicate-deals.csv) contains all 120 games. | |
| 19 | + | |
| 20 | +## Reproduce | |
| 21 | + | |
| 22 | +From the repository root, use Python 3.12 with `referee/requirements.txt` installed. The checked-in CSV was generated on Python 3.12.14 with NumPy 2.3.5 and RLCard 1.2.0. | |
| 23 | + | |
| 24 | +```sh | |
| 25 | +PYTHONHASHSEED=0 python3 -s routes/codex-wang296-rlcard-comparison/compare.py | |
| 26 | +``` | |
| 27 | + | |
| 28 | +Two runs produced identical CSVs and completed without fallback moves. The local field check, `python3 -I referee/play.py check routes/codex-wang296-rlcard-comparison`, reproduced the earlier route's overall score of 0.775 (1.483333 vs. random and 0.066667 vs. rule). For the starter, the same check with `routes` reproduced the overall baseline of 1.208333 (1.75 vs. random and 0.666667 vs. rule). | |
| 29 | + | |
| 30 | +## Next | |
| 31 | + | |
| 32 | +Replay deal 16 in both matchup directions to find the first move that changes the landlord's outcome. | |
+2 −0 routes/codex-wang296-rlcard-comparison/agent.py added View file
| @@ -0,0 +1,2 @@ | ||
| 1 | +"""RLCard's own rule-based Dou Dizhu agent, doudizhu-rule-v1, as it ships (rlcard.models).""" | |
| 2 | +from rlcard.models.doudizhu_rule_models import DouDizhuRuleAgentV1 as Agent # noqa: F401 | |
+69 −0 routes/codex-wang296-rlcard-comparison/compare.py added View file
| @@ -0,0 +1,69 @@ | ||
| 1 | +"""Print paired duplicate-deal results as CSV using the project's referee.""" | |
| 2 | + | |
| 3 | +import csv | |
| 4 | +import os | |
| 5 | +import sys | |
| 6 | +from contextlib import contextmanager | |
| 7 | +from pathlib import Path | |
| 8 | + | |
| 9 | +import rlcard | |
| 10 | + | |
| 11 | +ROUTE = Path(__file__).resolve().parent | |
| 12 | +sys.path.insert(0, str(ROUTE.parents[1] / "referee")) | |
| 13 | +from play import game, player # noqa: E402 | |
| 14 | + | |
| 15 | +DEALS = range(1, 21) | |
| 16 | +SEATS = ("landlord", "farmer_down", "farmer_up") | |
| 17 | + | |
| 18 | + | |
| 19 | +class CheckedPlayer: | |
| 20 | + """Fail on a move the referee would otherwise replace with a fallback.""" | |
| 21 | + | |
| 22 | + def __init__(self, child, name): | |
| 23 | + self.child = child | |
| 24 | + self.name = name | |
| 25 | + | |
| 26 | + def ask(self, message): | |
| 27 | + move = self.child.ask(message) | |
| 28 | + if move not in message["raw_obs"]["actions"]: | |
| 29 | + raise RuntimeError(f"{self.name} returned no legal move: {move!r}") | |
| 30 | + return move | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | +def checked_player(folder, name): | |
| 35 | + child = player(folder) | |
| 36 | + try: | |
| 37 | + yield CheckedPlayer(child, name) | |
| 38 | + finally: | |
| 39 | + child.close() | |
| 40 | + | |
| 41 | + | |
| 42 | +def compare(writer, focal, opponent): | |
| 43 | + focal_name, focal_folder = focal | |
| 44 | + opponent_name, opponent_folder = opponent | |
| 45 | + env = rlcard.make("doudizhu") | |
| 46 | + with checked_player(focal_folder, focal_name) as me, checked_player( | |
| 47 | + opponent_folder, opponent_name | |
| 48 | + ) as them: | |
| 49 | + for deal in DEALS: | |
| 50 | + for seat, role in enumerate(SEATS): | |
| 51 | + seats = [them] * len(SEATS) | |
| 52 | + seats[seat] = me | |
| 53 | + points, _ = game(env, seats, deal) | |
| 54 | + writer.writerow((focal_name, opponent_name, deal, role, points[seat])) | |
| 55 | + | |
| 56 | + | |
| 57 | +def main(): | |
| 58 | + if os.environ.get("PYTHONHASHSEED") != "0" or sys.flags.ignore_environment: | |
| 59 | + sys.exit("Run with PYTHONHASHSEED=0 python3 -s compare.py") | |
| 60 | + writer = csv.writer(sys.stdout, lineterminator="\n") | |
| 61 | + writer.writerow(("focal", "opponent", "deal", "seat", "points")) | |
| 62 | + starter = ("starter", ROUTE.parent) | |
| 63 | + rule = ("rule", ROUTE) | |
| 64 | + compare(writer, starter, rule) | |
| 65 | + compare(writer, rule, starter) | |
| 66 | + | |
| 67 | + | |
| 68 | +if __name__ == "__main__": | |
| 69 | + main() | |
+121 −0 routes/codex-wang296-rlcard-comparison/out/duplicate-deals.csv added View file
| @@ -0,0 +1,121 @@ | ||
| 1 | +focal,opponent,deal,seat,points | |
| 2 | +starter,rule,1,landlord,-4 | |
| 3 | +starter,rule,1,farmer_down,2 | |
| 4 | +starter,rule,1,farmer_up,-2 | |
| 5 | +starter,rule,2,landlord,-2 | |
| 6 | +starter,rule,2,farmer_down,1 | |
| 7 | +starter,rule,2,farmer_up,1 | |
| 8 | +starter,rule,3,landlord,-2 | |
| 9 | +starter,rule,3,farmer_down,-1 | |
| 10 | +starter,rule,3,farmer_up,-1 | |
| 11 | +starter,rule,4,landlord,2 | |
| 12 | +starter,rule,4,farmer_down,1 | |
| 13 | +starter,rule,4,farmer_up,1 | |
| 14 | +starter,rule,5,landlord,-2 | |
| 15 | +starter,rule,5,farmer_down,1 | |
| 16 | +starter,rule,5,farmer_up,1 | |
| 17 | +starter,rule,6,landlord,2 | |
| 18 | +starter,rule,6,farmer_down,-1 | |
| 19 | +starter,rule,6,farmer_up,1 | |
| 20 | +starter,rule,7,landlord,2 | |
| 21 | +starter,rule,7,farmer_down,1 | |
| 22 | +starter,rule,7,farmer_up,1 | |
| 23 | +starter,rule,8,landlord,2 | |
| 24 | +starter,rule,8,farmer_down,-1 | |
| 25 | +starter,rule,8,farmer_up,-1 | |
| 26 | +starter,rule,9,landlord,2 | |
| 27 | +starter,rule,9,farmer_down,1 | |
| 28 | +starter,rule,9,farmer_up,-1 | |
| 29 | +starter,rule,10,landlord,4 | |
| 30 | +starter,rule,10,farmer_down,1 | |
| 31 | +starter,rule,10,farmer_up,-1 | |
| 32 | +starter,rule,11,landlord,-2 | |
| 33 | +starter,rule,11,farmer_down,1 | |
| 34 | +starter,rule,11,farmer_up,1 | |
| 35 | +starter,rule,12,landlord,2 | |
| 36 | +starter,rule,12,farmer_down,1 | |
| 37 | +starter,rule,12,farmer_up,1 | |
| 38 | +starter,rule,13,landlord,-4 | |
| 39 | +starter,rule,13,farmer_down,2 | |
| 40 | +starter,rule,13,farmer_up,2 | |
| 41 | +starter,rule,14,landlord,2 | |
| 42 | +starter,rule,14,farmer_down,-1 | |
| 43 | +starter,rule,14,farmer_up,1 | |
| 44 | +starter,rule,15,landlord,2 | |
| 45 | +starter,rule,15,farmer_down,-1 | |
| 46 | +starter,rule,15,farmer_up,-1 | |
| 47 | +starter,rule,16,landlord,16 | |
| 48 | +starter,rule,16,farmer_down,-4 | |
| 49 | +starter,rule,16,farmer_up,8 | |
| 50 | +starter,rule,17,landlord,2 | |
| 51 | +starter,rule,17,farmer_down,1 | |
| 52 | +starter,rule,17,farmer_up,1 | |
| 53 | +starter,rule,18,landlord,2 | |
| 54 | +starter,rule,18,farmer_down,-1 | |
| 55 | +starter,rule,18,farmer_up,-1 | |
| 56 | +starter,rule,19,landlord,-2 | |
| 57 | +starter,rule,19,farmer_down,2 | |
| 58 | +starter,rule,19,farmer_up,2 | |
| 59 | +starter,rule,20,landlord,2 | |
| 60 | +starter,rule,20,farmer_down,-1 | |
| 61 | +starter,rule,20,farmer_up,-1 | |
| 62 | +rule,starter,1,landlord,-4 | |
| 63 | +rule,starter,1,farmer_down,2 | |
| 64 | +rule,starter,1,farmer_up,2 | |
| 65 | +rule,starter,2,landlord,-2 | |
| 66 | +rule,starter,2,farmer_down,1 | |
| 67 | +rule,starter,2,farmer_up,1 | |
| 68 | +rule,starter,3,landlord,2 | |
| 69 | +rule,starter,3,farmer_down,1 | |
| 70 | +rule,starter,3,farmer_up,-1 | |
| 71 | +rule,starter,4,landlord,-2 | |
| 72 | +rule,starter,4,farmer_down,-1 | |
| 73 | +rule,starter,4,farmer_up,-1 | |
| 74 | +rule,starter,5,landlord,-2 | |
| 75 | +rule,starter,5,farmer_down,-1 | |
| 76 | +rule,starter,5,farmer_up,1 | |
| 77 | +rule,starter,6,landlord,-2 | |
| 78 | +rule,starter,6,farmer_down,1 | |
| 79 | +rule,starter,6,farmer_up,-1 | |
| 80 | +rule,starter,7,landlord,-2 | |
| 81 | +rule,starter,7,farmer_down,-1 | |
| 82 | +rule,starter,7,farmer_up,-1 | |
| 83 | +rule,starter,8,landlord,2 | |
| 84 | +rule,starter,8,farmer_down,-1 | |
| 85 | +rule,starter,8,farmer_up,-1 | |
| 86 | +rule,starter,9,landlord,2 | |
| 87 | +rule,starter,9,farmer_down,-1 | |
| 88 | +rule,starter,9,farmer_up,1 | |
| 89 | +rule,starter,10,landlord,-2 | |
| 90 | +rule,starter,10,farmer_down,2 | |
| 91 | +rule,starter,10,farmer_up,-2 | |
| 92 | +rule,starter,11,landlord,-2 | |
| 93 | +rule,starter,11,farmer_down,-2 | |
| 94 | +rule,starter,11,farmer_up,1 | |
| 95 | +rule,starter,12,landlord,-2 | |
| 96 | +rule,starter,12,farmer_down,1 | |
| 97 | +rule,starter,12,farmer_up,-1 | |
| 98 | +rule,starter,13,landlord,-4 | |
| 99 | +rule,starter,13,farmer_down,2 | |
| 100 | +rule,starter,13,farmer_up,2 | |
| 101 | +rule,starter,14,landlord,-2 | |
| 102 | +rule,starter,14,farmer_down,2 | |
| 103 | +rule,starter,14,farmer_up,-1 | |
| 104 | +rule,starter,15,landlord,2 | |
| 105 | +rule,starter,15,farmer_down,1 | |
| 106 | +rule,starter,15,farmer_up,-1 | |
| 107 | +rule,starter,16,landlord,-16 | |
| 108 | +rule,starter,16,farmer_down,-8 | |
| 109 | +rule,starter,16,farmer_up,-8 | |
| 110 | +rule,starter,17,landlord,-2 | |
| 111 | +rule,starter,17,farmer_down,-1 | |
| 112 | +rule,starter,17,farmer_up,-1 | |
| 113 | +rule,starter,18,landlord,2 | |
| 114 | +rule,starter,18,farmer_down,-1 | |
| 115 | +rule,starter,18,farmer_up,-1 | |
| 116 | +rule,starter,19,landlord,-4 | |
| 117 | +rule,starter,19,farmer_down,1 | |
| 118 | +rule,starter,19,farmer_up,1 | |
| 119 | +rule,starter,20,landlord,2 | |
| 120 | +rule,starter,20,farmer_down,-1 | |
| 121 | +rule,starter,20,farmer_up,-1 | |
