From c34d7363b61a9e00c986b79793bf7cdc03e9ea99 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 4 Mar 2024 09:15:01 +0100 Subject: wip --- ttt/src/ttt.app.src | 13 ------------- ttt/src/ttt.erl | 51 --------------------------------------------------- 2 files changed, 64 deletions(-) delete mode 100644 ttt/src/ttt.app.src delete mode 100644 ttt/src/ttt.erl (limited to 'ttt/src') diff --git a/ttt/src/ttt.app.src b/ttt/src/ttt.app.src deleted file mode 100644 index 813faba..0000000 --- a/ttt/src/ttt.app.src +++ /dev/null @@ -1,13 +0,0 @@ -{application, ttt, - [{description, "TTT app"}, - {vsn, "0.1.0"}, - {registered, []}, -% {mod, {myapp_app, []}}, - {applications, - [kernel, stdlib]}, - {env,[]}, - {modules, []}, - - {licenses, ["Apache-2.0"]}, - {links, []} - ]}. diff --git a/ttt/src/ttt.erl b/ttt/src/ttt.erl deleted file mode 100644 index a9fc4d1..0000000 --- a/ttt/src/ttt.erl +++ /dev/null @@ -1,51 +0,0 @@ --module(ttt). - --export_type([ - player/0, - square/0, - board/0, - game_result/0]). - --export([ - who_wins/1, - empty_board/0, - move/4, - format/1]). - --type player() :: 'X' | 'O'. --type square() :: player() | 'E'. --type board() :: list(square()). --type game_result() :: player() | 'draw' | 'running'. - --define(EMPTY_BOARD, ['E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E']). - --spec empty_board() -> board(). -empty_board() -> ?EMPTY_BOARD. - --spec who_wins(Board :: board()) -> game_result(). -who_wins([A, A, A, _, _, _, _, _, _]) when A == 'X' orelse A == 'O' -> A; -who_wins([_, _, _, A, A, A, _, _, _]) when A == 'X' orelse A == 'O' -> A; -who_wins([_, _, _, _, _, _, A, A, A]) when A == 'X' orelse A == 'O' -> A; -who_wins([A, _, _, A, _, _, A, _, _]) when A == 'X' orelse A == 'O' -> A; -who_wins([_, A, _, _, A, _, _, A, _]) when A == 'X' orelse A == 'O' -> A; -who_wins([_, _, A, _, _, A, _, _, A]) when A == 'X' orelse A == 'O' -> A; -who_wins([A, _, _, _, A, _, _, _, A]) when A == 'X' orelse A == 'O' -> A; -who_wins([_, _, A, _, A, _, A, _, _]) when A == 'X' orelse A == 'O' -> A; -who_wins(Board) -> - case lists:member('E', Board) of - true -> running; - false -> draw - end. - -move(_, _, Row, _) when Row < 0 orelse Row > 2 -> {bad_arg}; -move(_, _, _, Col) when Col < 0 orelse Col > 2 -> {bad_arg}; -move(_, Move, _, _) when not (Move == 'X') -> {bad_arg}; -move(Board, Move, Row, Col) -> - I = Row * 3 + Col, - Updated = lists:sublist(Board, I) ++ [Move] ++ lists:nthtail(I + 1, Board), - {ok, Updated}. - -format(Board) when length(Board) == 9 -> - B = lists:map(fun(C) -> case C of 'E' -> ' '; _ -> C end end, Board), - io:format("+---+~n|~s~s~s|~n|~s~s~s|~n|~s~s~s|~n+---+~n", B); -format(_) -> "bad board". -- cgit v1.2.3