{"id":17774204,"url":"https://github.com/johnad/negamax","last_synced_at":"2025-06-10T11:04:47.271Z","repository":{"id":141359408,"uuid":"133726242","full_name":"JohnAD/negamax","owner":"JohnAD","description":"negamax AI algorithm for turn-based games","archived":false,"fork":false,"pushed_at":"2019-10-06T19:33:48.000Z","size":32,"stargazers_count":13,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T16:18:04.839Z","etag":null,"topics":["game","negamax-algorithm","nim","turn-based"],"latest_commit_sha":null,"homepage":null,"language":"HTML","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/JohnAD.png","metadata":{"files":{"readme":"README.rst","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":"2018-05-16T21:44:42.000Z","updated_at":"2024-02-24T04:45:03.000Z","dependencies_parsed_at":"2024-06-02T14:06:41.585Z","dependency_job_id":null,"html_url":"https://github.com/JohnAD/negamax","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnAD%2Fnegamax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnAD%2Fnegamax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnAD%2Fnegamax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnAD%2Fnegamax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JohnAD","download_url":"https://codeload.github.com/JohnAD/negamax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065280,"owners_count":21041872,"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","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":["game","negamax-algorithm","nim","turn-based"],"created_at":"2024-10-26T21:50:01.267Z","updated_at":"2025-04-09T16:18:16.266Z","avatar_url":"https://github.com/JohnAD.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"Introduction to negamax\n==============================================================================\nver 0.0.3\n\n.. image:: https://raw.githubusercontent.com/yglukhov/nimble-tag/master/nimble.png\n   :height: 34\n   :width: 131\n   :alt: nimble\n\nNegamax is a nim library for executing the Negamax AI algorithm on a\nturn-based game. The library uses the ``turn_based_game`` nimble library as\nthe framework for the game itself.\n\nThe negamax algorithm searches and weighs possible future moves. It is a\nvaration of the minimax algorithm that is optimized for games where the\n\"value\" of a game's state for one player is directly inverse of the value\nto the oppossing player. This is known as a\n[zero-sum game](https://en.wikipedia.org/wiki/Zero-sum_game).\n\nThis algorithm is desgined to do *alpha/beta pruning*, which shortens the\nsearch tree.\n\nThis algorithem is currently recursive. The author is currently working on\na non-recursive one as well.\n\nNegamax has the following restrictions:\n\n1. It only works for two-player games.\n2. It does not work with games that involve any randomness during game play.\n   (Initial randomness for \"board setup\" etc. before game play begins is just fine.)\n3. It requires that the value of the board be zero-sum in nature.\n\nAlgorithm details:\n\n* https://en.wikipedia.org/wiki/Negamax\n* https://en.wikipedia.org/wiki/Minimax\n\nUsage\n==========\n\nThe bulk of the work is in making the game itself. See the ``turn_based_game``\nlibrary for details.\n\n* turn_based_game (repo): \u003chttps://github.com/JohnAD/turn_based_game\u003e\n\nOnce made, simply import the negamax library and use a ``NegamaxPlayer``\ninstead of a normal ``Player``. Include the ``depth`` of the search as an object\nparameter. The depth is measured in **plies**. One **ply** is a single play.\nSo, one full round of play between two players is two plies.\n\nThe Negamax AI specifically requires that the\n\n* ``scoring``,\n* ``get_state``, and\n* ``restore_state``\n\nmethods be defined. Again, see the ``turn_based_game`` docs for details.\n\nSimple Example\n===============\n\n.. code:: nim\n\n    import turn_based_game\n    import negamax\n\n    import knights\n\n    #\n    #  Game of Knights\n    #\n    # Knights is played on a 5 row by 5 column chessboard with standard Knight pieces. Just like\n    # in chess, the Knight move by jumping in an L pattern: moving one space in any direction followed by\n    # moving two spaces at a right angle to the first move. When a knight makes a jump, the place that it\n    # formerly occupied is marked with an X and it can no longer be landed on by either player. As the\n    # game progresses, there are fewer and fewer places to land. There are no captures in this game.\n    #\n    # To start, each player has one Knight placed in an opposite corner. The players then take turns jumping.\n    # The last player to still have a place to move is the winner.\n    #\n\n    var game = Knights()\n\n    game.setup(@[\n      Player(name: \"Black Knight\"),\n      NegamaxPlayer(name: \"White Knight\", depth: 7)\n    ])\n\n    var history: seq[string] = @[]\n\n    history = game.play()\n\n    echo \"history: \" \u0026 $history\n\nFor the content pulled by \"import knights\", see\nhttps://github.com/JohnAD/negamax/blob/master/examples/knights.nim\n\nVideos\n============\n\nThe following two videos (to be watched in sequence), demonstrate how to use\nthis library and the ``turn_based_game`` library:\n\n* Using \"turn_based_game\": https://www.youtube.com/watch?v=u6w8vT-oBjE\n* Using \"negamax\": https://www.youtube.com/watch?v=op4Mcgszshk\n\nCredit\n=============\n\nThe code for this engine mimics that written in Python at the EasyAI library\nlocated at \u003chttps://github.com/Zulko/easyAI\u003e. That library contains both\nthe game rule engine (called TwoPlayerGame) as well as a variety of AI\nalgorithms to play as game players, such as Negamax.\n\n\n\nTable Of Contents\n=================\n\n1. `Introduction to negamax \u003chttps://github.com/JohnAD/negamax\u003e`__\n2. Appendices\n\n    A. `negamax Reference \u003chttps://github.com/JohnAD/negamax/blob/master/docs/negamax-ref.rst\u003e`__\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnad%2Fnegamax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnad%2Fnegamax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnad%2Fnegamax/lists"}