{"id":13737197,"url":"https://github.com/JohnAD/turn_based_game","last_synced_at":"2025-05-08T13:33:22.838Z","repository":{"id":141359454,"uuid":"130525811","full_name":"JohnAD/turn_based_game","owner":"JohnAD","description":"Game rules engine for simulating or playing turn-based games.","archived":false,"fork":false,"pushed_at":"2020-01-02T21:05:58.000Z","size":181,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-26T22:45:49.226Z","etag":null,"topics":["game","nimble","rules-engine","turn-based"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","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":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-04-22T01:39:21.000Z","updated_at":"2024-02-21T18:42:45.000Z","dependencies_parsed_at":"2024-01-06T12:05:41.292Z","dependency_job_id":"ca3bbd07-fde0-4aa1-8a86-550414041b59","html_url":"https://github.com/JohnAD/turn_based_game","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnAD%2Fturn_based_game","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnAD%2Fturn_based_game/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnAD%2Fturn_based_game/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnAD%2Fturn_based_game/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JohnAD","download_url":"https://codeload.github.com/JohnAD/turn_based_game/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224737430,"owners_count":17361345,"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","nimble","rules-engine","turn-based"],"created_at":"2024-08-03T03:01:37.293Z","updated_at":"2025-05-08T13:33:22.834Z","avatar_url":"https://github.com/JohnAD.png","language":"HTML","readme":"Introduction to turn_based_game\n==============================================================================\nver 1.1.6\n\n.. image:: https://raw.githubusercontent.com/yglukhov/nimble-tag/master/nimble.png\n   :height: 34\n   :width: 131\n   :alt: nimble\n   :target: https://nimble.directory/pkg/turnbasedgame\n\n.. image:: https://repo.support/img/rst-banner.png\n   :height: 34\n   :width: 131\n   :alt: repo.support\n   :target: https://repo.support/gh/JohnAD/turn_based_game\n\nThis framework encapsulates the critical information (rules) needed for\nplaying or simulating a turn-based game.\n\nSome common turn-based games: Checkers, Reversi, Chess, Stratego,\nConnect 4.\n\nUsage\n=====\n\nTo use, simply:\n\n1. Define a game object that inherits from ``Game``.\n2. Add the game rules as methods for ``setup``, ``set_possible_moves``,\n   ``make_move``, and ``determine_winner``. You can override additional\n   methods for more rule changes. And, you can add new ones. But the basic\n   four are the minimum for enabling a game.\n3. Invoke your new object and pass in a list of player objects. (Or, AI\n   objects if using an AI library.)\n4. Run the new object's ``setup`` method. This resets the game.\n\nAnd, when running from a terminal,\n5. Run the new object's ``play`` method\n\nQuick Example\n=============\n\n.. code:: nim\n\n    #\n    # Game of Thai 21 example\n    #\n    # Description: Twenty one flags are placed on a beach. Each player takes a turn\n    # removing between 1 and 3 flags. The player that removes the last remaining flag wins.\n    #\n    # This game was introduced by an episode of Survivor: http://survivor-org.wikia.com/wiki/21_Flags\n    #\n\n    import strutils\n    import turn_based_game\n    import tables\n\n    #\n    # 1. define our game object\n    #\n\n    type\n      GameOfThai21 = ref object of Game\n        pile*: int\n\n    #\n    #  2. add our rules (methods)\n    #\n\n    method setup*(self: GameOfThai21, players: seq[Player]) =\n      self.default_setup(players)\n      self.pile = 21\n\n    method set_possible_moves(self: GameOfThai21, moves: var OrderedTable[string, string]) =\n      if self.pile==1:\n        moves = {\"1\": \"Take One\"}.toOrderedTable\n      elif self.pile==2:\n        moves = {\"1\": \"Take One\", \"2\": \"Take Two\"}.toOrderedTable\n      else:\n        moves = {\"1\": \"Take One\", \"2\": \"Take Two\", \"3\": \"Take Three\"}.toOrderedTable\n\n    method make_move(self: GameOfThai21, move: string): string =\n      var count = move.parseInt()\n      self.pile -= count  # remove bones.\n      return \"$# flags removed.\".format([count])\n\n    method determine_winner(self: GameOfThai21) =\n      if self.winner_player_number \u003e 0:\n        return\n      if self.pile \u003c= 0:\n        self.winner_player_number = self.current_player_number\n\n    # the following method is not _required_, but makes it nicer to read\n    method status(self: GameOfThai21): string =\n      \"$# flags available.\".format([self.pile])\n\n    #\n    # 3. invoke the new game object\n    #\n\n    var game = GameOfThai21()\n\n    #\n    # 4. reset (start) a new game with, in this case, 3 players\n    #\n\n    game.setup(@[Player(name: \"A\"), Player(name: \"B\"), Player(name: \"C\")])\n\n    #\n    # 5. play the game at a terminal\n    #\n\n    game.play()\n\nDocumentation\n=============\n\nGreater documentation is being built at the wiki on this repository.\n\nVisit https://github.com/JohnAD/turn_based_game/wiki\n\nVideos\n======\n\nThe following two videos (to be watched in order), demonstrate how to\nuse this library and the 'turn\\_based\\_game' library:\n\n1. Using \"turn\\_based\\_game\":\n   https://www.youtube.com/watch?v=u6w8vT-oBjE\n2. 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\nlibrary located at https://github.com/Zulko/easyAI. That library\ncontains both the game rule engine (called TwoPlayerGame) as well as a\nvariety of AI algorithms to play as game players, such as Negamax.\n\n\n\nTable Of Contents\n=================\n\n1. `Introduction to turn_based_game \u003chttps://github.com/JohnAD/turn_based_game\u003e`__\n2. Appendices\n\n    A. `turn_based_game Reference \u003chttps://github.com/JohnAD/turn_based_game/blob/master/docs/turn_based_game-ref.rst\u003e`__\n","funding_links":[],"categories":["Game Development"],"sub_categories":["Rules Engines"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJohnAD%2Fturn_based_game","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJohnAD%2Fturn_based_game","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJohnAD%2Fturn_based_game/lists"}