[{"name":"XO","comment":" `XO` is a reference to **Xs and Os** which is an alternative name for [Tic-tac-toe](https://en.wikipedia.org/wiki/Tic-tac-toe).\n\n\n# Player\n\n@docs Player, nextPlayer\n\n\n# Game\n\n@docs Game, start\n\n\n# Play\n\n@docs Position, PlayError, play\n@docs Rules, defaultRules, playAgain\n\n\n# State\n\n@docs State, Outcome, Line, toState\n@docs openPositions\n\n\n# Transform\n\n@docs Tile, map\n@docs toString\n\n\n# Analyze\n\n@docs Report, Optimum, AnalysisError, findGoodPositions\n\n","unions":[{"name":"AnalysisError","comment":" Not all games can be analyzed. For e.g. if all positions are occupied or\nthe game is over then there's nothing to analyze.\n","args":[],"cases":[["NoOpenPositions",[]],["NoGameInProgress",[]]]},{"name":"Game","comment":" Keeps track of the internal state of a game.\n\nThis state includes: who played first, who's the current player, and the configuration of the board.\n\n","args":[],"cases":[]},{"name":"Optimum","comment":" The best outcome that can be achieved.\n\n  - `W` means you can win\n  - `D` means you can draw at best\n  - `L` means no matter what position is played you will lose\n\n","args":[],"cases":[["W",[]],["D",[]],["L",[]]]},{"name":"Outcome","comment":" Either there is a winner, the game ended in a draw, or it is undecided because the game is still in progress.\n","args":[],"cases":[["Win",["XO.Player","List.List XO.Line"]],["Draw",["XO.Player"]],["Undecided",[]]]},{"name":"PlayError","comment":" The possible errors that could occur while playing a game.\n","args":[],"cases":[["OutOfBounds",["XO.Position"]],["Occupied",["XO.Position"]],["GameAlreadyEnded",[]]]},{"name":"Player","comment":" A player is either an `X` or an `O`.\n","args":[],"cases":[["X",[]],["O",[]]]}],"aliases":[{"name":"Line","comment":" The three positions on the board that represent the winning line.\n","args":[],"type":"( XO.Position, XO.Position, XO.Position )"},{"name":"Position","comment":" A `(row, column)` position. Both coordinates are 0-based and should range from 0 to 2.\n","args":[],"type":"( Basics.Int, Basics.Int )"},{"name":"Report","comment":" The report tells you the best outcome that can be achieved, assuming both players play perfectly.\n\n`possibilities` is a list of pairs of position and number of moves. Each pair represents the\nposition to play, to achieve the best outcome, and the number of moves it takes to achieve it.\n\n","args":[],"type":"{ optimum : XO.Optimum, possibilities : List.List ( XO.Position, Basics.Int ) }"},{"name":"Rules","comment":" Various rules that help determine how subsequent games are played.\n","args":[],"type":"{ winnerPlaysFirst : Basics.Bool, takeTurnsOnDraw : Basics.Bool }"},{"name":"State","comment":" The external state of a game.\n\n  - Who played first?\n  - Whose turn is it?\n  - What's the outcome?\n\n","args":[],"type":"{ first : XO.Player, turn : XO.Player, outcome : XO.Outcome }"},{"name":"Tile","comment":" Represents which player, if any, is at a position on a Tic-tac-toe board.\n","args":[],"type":"Maybe.Maybe XO.Player"}],"values":[{"name":"defaultRules","comment":" By default, the winner plays first and when a game ends in a draw the other player who didn't play first,\ngets to play first in the next game.\n","type":"XO.Rules"},{"name":"findGoodPositions","comment":" Find the good unoccupied positions on the board of a game for the current player.\n\n\n## Example 1\n\nSuppose `O` has the next turn in a game, `g1`, with a board layout of `x.o.x....`, then\n\n    --\n    --    0   1   2\n    -- 0  x |   | o\n    --   ---+---+---\n    -- 1    | x |\n    --   ---+---+---\n    -- 2    |   |\n    --\n    findGoodPositions g1\n        == { optimum = D\n           , possibilities = [ ( ( 2, 2 ), 6 ) ]\n           }\n\nIt means that `O` can draw at best, in 6 moves, if `O` is played at `(2, 2)`.\n\n\n## Example 2\n\nSuppose `O` has the next turn in a game, `g2`, with a board layout of `xo..x....`, then\n\n    --\n    --    0   1   2\n    -- 0  x | o |\n    --   ---+---+---\n    -- 1    | x |\n    --   ---+---+---\n    -- 2    |   |\n    --\n    findGoodPositions g2\n        == { optimum = L\n           , possibilities =\n                [ ( ( 0, 2 ), 2 )\n                , ( ( 1, 0 ), 2 )\n                , ( ( 1, 2 ), 2 )\n                , ( ( 2, 0 ), 2 )\n                , ( ( 2, 1 ), 2 )\n                , ( ( 2, 2 ), 4 )\n                ]\n           }\n\nIt means that no matter the position `O` plays, `O` will lose. However, if\n`O` is played at `(2, 2)`, in order to block `X` from the immediate win, then\n`O` can extend the game a little more.\n\n\n## Example 3\n\nSuppose `X` has the next turn in a game, `g3`, with a board layout of `x.ox...o.`, then\n\n    --\n    --    0   1   2\n    -- 0  x |   | o\n    --   ---+---+---\n    -- 1  x |   |\n    --   ---+---+---\n    -- 2    | o |\n    --\n    findGoodPositions g3\n        == { optimum = W\n           , possibilities =\n                [ ( ( 1, 1 ), 3 )\n                , ( ( 1, 2 ), 3 )\n                , ( ( 2, 0 ), 1 )\n                , ( ( 2, 2 ), 3 )\n                ]\n           }\n\nIt means that `X` can win. `X` can either win immediately if `X` is played at `(2, 0)`, or\n`X` can have some fun and win in 3 moves if `X` is played at `(1, 1)`, `(1, 2)`, or `(2, 2)`.\n\n\n## Example 4\n\nSuppose `X` has the next turn in a game, `g4`, with a board layout of `x.o...x.o`, then\n\n    --\n    --    0   1   2\n    -- 0  x |   | o\n    --   ---+---+---\n    -- 1    |   |\n    --   ---+---+---\n    -- 2  x |   | o\n    --\n    findGoodPositions g4\n        == { optimum = W\n           , possibilities = [ ( ( 1, 0 ), 1 ) ]\n           }\n\nIt means that `X` can win immediately if `X` is played at `(1, 0)`. Notice that\nwinning is favoured over blocking `O` at `(1, 2)`.\n\n**N.B.** _All the analysis above assumes perfect play by both players._\n\n","type":"XO.Game -> Result.Result XO.AnalysisError XO.Report"},{"name":"map","comment":" There are 9 positions/tiles on a Tic-tac-toe board. Apply a function over those\npositions/tiles in [row-major order](https://en.wikipedia.org/wiki/Row-_and_column-major_order).\n\n    map Tuple.pair (start X)\n        == [ ( ( 0, 0 ), Nothing )\n           , ( ( 0, 1 ), Nothing )\n           , ( ( 0, 2 ), Nothing )\n           , ( ( 1, 0 ), Nothing )\n           , ( ( 1, 1 ), Nothing )\n           , ( ( 1, 2 ), Nothing )\n           , ( ( 2, 0 ), Nothing )\n           , ( ( 2, 1 ), Nothing )\n           , ( ( 2, 2 ), Nothing )\n           ]\n\n","type":"(XO.Position -> XO.Tile -> a) -> XO.Game -> List.List a"},{"name":"nextPlayer","comment":" Get the next player.\n\n    nextPlayer X == O\n\n    nextPlayer O == X\n\n","type":"XO.Player -> XO.Player"},{"name":"openPositions","comment":" Get the unoccupied positions on the board of a game.\n","type":"XO.Game -> List.List XO.Position"},{"name":"play","comment":" Make a move at the given position with the current player of a game.\n","type":"XO.Position -> XO.Game -> Result.Result XO.PlayError XO.Game"},{"name":"playAgain","comment":" Play another game and initialize it using the given rules.\n","type":"XO.Rules -> XO.Game -> XO.Game"},{"name":"start","comment":" Initialize a game with the given player having the first move.\n","type":"XO.Player -> XO.Game"},{"name":"toState","comment":" Get the state of a game.\n","type":"XO.Game -> XO.State"},{"name":"toString","comment":" A representation of the layout of the board for a game in [row-major order](https://en.wikipedia.org/wiki/Row-_and_column-major_order).\n\n    toString (start X) == \".........\"\n\n    let\n        game0 =\n            start X\n\n        game1 =\n            play ( 0, 0 ) game0 |> Result.withDefault game0\n\n        game2 =\n            play ( 1, 1 ) game1 |> Result.withDefault game1\n    in\n    toString game2 == \"x...o....\"\n\n","type":"XO.Game -> String.String"}],"binops":[]}]