{"id":17239023,"url":"https://github.com/binarymuse/ultimate-ttt","last_synced_at":"2025-03-26T02:35:48.269Z","repository":{"id":62430636,"uuid":"259097080","full_name":"BinaryMuse/ultimate-ttt","owner":"BinaryMuse","description":"Elixir implementation of the game Ultimate Tic-Tac-Toe","archived":false,"fork":false,"pushed_at":"2020-04-26T19:15:23.000Z","size":163,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-20T23:16:02.785Z","etag":null,"topics":["board-game","elixir"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/ultimate_ttt/","language":"Elixir","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/BinaryMuse.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}},"created_at":"2020-04-26T17:54:52.000Z","updated_at":"2020-04-26T19:15:25.000Z","dependencies_parsed_at":"2022-11-01T20:21:53.023Z","dependency_job_id":null,"html_url":"https://github.com/BinaryMuse/ultimate-ttt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinaryMuse%2Fultimate-ttt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinaryMuse%2Fultimate-ttt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinaryMuse%2Fultimate-ttt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinaryMuse%2Fultimate-ttt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BinaryMuse","download_url":"https://codeload.github.com/BinaryMuse/ultimate-ttt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245577366,"owners_count":20638302,"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":["board-game","elixir"],"created_at":"2024-10-15T05:47:32.289Z","updated_at":"2025-03-26T02:35:48.237Z","avatar_url":"https://github.com/BinaryMuse.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elixir Ultimate Tic-Tac-Toe\n\n\u003c!-- module-doc --\u003e\n\n`UltimateTtt` is an Elixir module implementing the game Ultimate Tic-Tac-Toe. It implements the core, sequential game logic as well as an OTP app for creating and managing games. If you're unfamiliar with the game, [check out _Ultimate Tic-Tac-Toe_ by Ben Orlin](https://mathwithbaddrawings.com/ultimate-tic-tac-toe-original-post/).\n\n## Links\n\n- Package: [https://hex.pm/packages/ultimate_ttt](https://hex.pm/packages/ultimate_ttt)\n- Documentation: [https://hexdocs.pm/ultimate_ttt/](https://hexdocs.pm/ultimate_ttt/)\n- Source: [https://github.com/BinaryMuse/ultimate-ttt](https://github.com/BinaryMuse/ultimate-ttt)\n\n## Installation\n\nThis package is [available on Hex](https://hex.pm/packages/ultimate_ttt) and can be installed by adding `ultimate_ttt` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:ultimate_ttt, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Game Rules\n\nUltimate Tic-Tac-Toe is played on a 3x3 grid, where each cell of the grid contains another 3x3 grid. The goal of the game is to win three games of tic-tac-toe in the inner grids such that they form a line in the outer grid.\n\nThe key rule of the game is that a play must be made in the board associated with the space the previous player played.\n\nFor example, `x` starts the game by plying anywhere they want. Here, they choose to play in the middle-left board (index 3) in the center space (index 4):\n\n```elixir\nalias UltimateTtt.Game\ngame = Game.new()\n{:ok, game} = Game.place_tile(game, :x, {3, 4})\n```\n\n```text\n   │   │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │   │   │   │   │   │\n───────────┼───────────┼───────────\n   │   │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │ x │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │   │   │   │   │   │\n───────────┼───────────┼───────────\n   │   │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │   │   │   │   │   │\n```\n\nNow, `o` is required to play somewhere in the board at the center of the outer grid, because `x` played in the center space in the grid they chose. Similarly, the square they choose to play on in this center board will affect which grid `x` will be forced to play in next.\n\n```elixir\nGame.valid_moves(game, :o)\n```\n\n```text\n   │   │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │   │   │   │   │   │\n───────────┼───────────┼───────────\n   │   │   │ + │ + │ + │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │ x │   │ + │ + │ + │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │ + │ + │ + │   │   │\n───────────┼───────────┼───────────\n   │   │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │   │   │   │   │   │\n───┼───┼───│───┼───┼───│───┼───┼───\n   │   │   │   │   │   │   │   │\n```\n\nIf a play forces the next player to play in a board that is either already claimed (by someone winning that board) or is full (resulting in a tie in the board), that player may choose to play anywhere they want.\n\nThe game is over when a player has won three inner boards in a row, resulting in a win for that player, or when every board is either won or a tie but no player has won three boards in a line, resulting in a tie.\n\n## Example\n\n### Core Rules\n\nThe core rules of Ultimate Tic-Tac-Toe are implemented by the `UltimateTtt.Game` module.\n\n```elixir\niex\u003e alias UltimateTtt.Game\niex\u003e game = Game.new()\niex\u003e Game.turn(game)\n:x\niex\u003e Game.valid_move?(game, :x, {3, 4})\ntrue\niex\u003e {:ok, game} = Game.place_tile(game, :x, {3, 4})\niex\u003e Game.turn(game)\n:o\niex\u003e Game.valid_move?(game, :o, {3, 0}) # Player o has to play in the board at index 4\nfalse\niex\u003e Game.valid_move?(game, :x, {4, 0}) # Not player x's turn\nfalse\niex\u003e Game.valid_move?(game, :o, {4, 0})\ntrue\niex\u003e Game.valid_moves(game, :o)\n[{4, 0}, {4, 1}, {4, 2}, {4, 3}, {4, 4}, {4, 5}, {4, 6}, {4, 7}, {4, 8}]\niex\u003e Game.status(game)\n:in_progress\niex\u003e Game.last_played_space(game)\n{3, 4}\niex\u003e Game.tile_at(game, {3, 4})\n:x\niex\u003e Game.tile_at(game, {4, 0})\n:empty\n```\n\n### OTP App\n\n(Not yet implemented)\n\n```elixir\ngame = GameSession.start_link()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinarymuse%2Fultimate-ttt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinarymuse%2Fultimate-ttt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinarymuse%2Fultimate-ttt/lists"}