{"id":15415858,"url":"https://github.com/davidje13/snowball_koth_pitn","last_synced_at":"2025-09-01T10:05:03.829Z","repository":{"id":151511288,"uuid":"92095074","full_name":"davidje13/snowball_koth_pitn","owner":"davidje13","description":"Pain in the Nash entry for https://codegolf.stackexchange.com/questions/120688/snowball-fight-koth","archived":false,"fork":false,"pushed_at":"2017-05-22T20:59:37.000Z","size":690,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-20T13:21:14.265Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidje13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-22T20:10:44.000Z","updated_at":"2020-12-18T19:35:07.000Z","dependencies_parsed_at":"2023-05-18T18:45:29.833Z","dependency_job_id":null,"html_url":"https://github.com/davidje13/snowball_koth_pitn","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"1b99eccce9be154c76019f03f98768d337431b6e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/davidje13/snowball_koth_pitn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidje13%2Fsnowball_koth_pitn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidje13%2Fsnowball_koth_pitn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidje13%2Fsnowball_koth_pitn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidje13%2Fsnowball_koth_pitn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidje13","download_url":"https://codeload.github.com/davidje13/snowball_koth_pitn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidje13%2Fsnowball_koth_pitn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273105953,"owners_count":25046950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T17:10:02.825Z","updated_at":"2025-09-01T10:05:03.395Z","avatar_url":"https://github.com/davidje13.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pain in the Nash\n\nThis is the [Pain in the Nash](https://codegolf.stackexchange.com/a/121943/8927) entry for\n[Snowball Fight KoTH](https://codegolf.stackexchange.com/q/120688/8927), so called because the fact that I had to write my own\nNash equilibrium solver was a real pain.\n\nCompile as C++11 or better. For performance, it's good to compile with OpenMP support (but this is just for speed; it's not\nrequired)\n\n```\ng++ -std=c++11 -fopenmp pain_in_the_nash.cpp -o pain_in_the_nash\n```\n\nRun one turn with:\n\n```\n./pain_in_the_nash \u003cturn\u003e \u003cmy_snowball_count\u003e \u003ctheir_snowball_count\u003e \u003cmy_duck_count\u003e \u003ctheir_duck_count\u003e \u003cmax_snowballs\u003e\n\n# e.g.:\n./pain_in_the_nash 10 20 20 5 7 50\n```\n\nOr (re)generate the data files with:\n\n```\n./pain_in_the_nash \u003cmax_turns\u003e \u003cmax_balls\u003e \u003cmax_ducks\u003e\n\n# e.g.:\n./pain_in_the_nash 1000 50 25\n```\n\nThis uses Nash equilibria to decide what to do on each turn, which means that *in theory* it will always win or draw in the\nlong run (over many games), no matter what strategy the opponent uses. Whether that's the case in practice depends on whether\nI made any mistakes in the implementation. However, since this KoTH competition only has a single round against each opponent,\nit probably won't do very well on the leaderboard.\n\nMy original idea was to have a simple valuation function for each game state (e.g. each ball is worth +b, each duck is +d),\nbut this leads to obvious problems figuring out what those valuations should be, and means it can't act on diminishing returns\nof gathering more and more balls, etc. So instead, this will analyse the *entire game tree*, working backwards from turn 1000,\nand fill in the actual valuations based on how each game could pan out.\n\nThe result is that I have absolutely no idea what strategy this uses, except for a couple of hard-coded \"obvious\" behaviours\n(throw snowballs if you have more balls than your opponent has balls+ducks, and reload if you're both out of snowballs). If\nanybody wants to analyse the dataset it produces I imagine there's some interesting behaviour to discover!\n\nTesting this against \"Save One\" shows that it does indeed win in the long-run, but only by a small margin (514 wins, 486\nlosses, 0 draws in the first batch of 1000 games, and 509 wins, 491 losses, 0 draws in the second).\n\n## manager.sh\n\nThis is a simple script which runs a number of games between 2 agents and records the winner. It will always run games with\nmax_snowballs = 50, initial_ducks = 25, and max_turns = 1000.\n\nUsage:\n\n```\n./manager.sh \u003cagent_1\u003e \u003cagent_2\u003e \u003ctotal_games\u003e\n\n# e.g.:\n./manager.sh ./pain_in_the_nash ./save_one.sh 1000\n```\n\nThe test competitors are:\n\n* save_one.sh (based on the [Save One](https://codegolf.stackexchange.com/a/120848/8927) entry)\n* simple.sh (based on obvious rules with randomisation for any non-clear states)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidje13%2Fsnowball_koth_pitn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidje13%2Fsnowball_koth_pitn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidje13%2Fsnowball_koth_pitn/lists"}