~statianzo/sevenlangs

sevenlangs/erlang/tictactoe.erl -rw-r--r-- 576 bytes
2fcd4511Jason Staten day one logic style 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-module(tictactoe).

-export([winner/1]).

is_full(Board) ->
    lists:all(fun (A) -> A == x orelse A == o end,
	      tuple_to_list(Board)).

winner({A, A, A, _, _, _, _, _, _}) -> A;
winner({_, _, _, A, A, A, _, _, _}) -> A;
winner({_, _, _, _, _, _, A, A, A}) -> A;
winner({A, _, _, A, _, _, A, _, _}) -> A;
winner({_, A, _, _, A, _, _, A, _}) -> A;
winner({_, _, A, _, _, A, _, _, A}) -> A;
winner({A, _, _, _, A, _, _, _, A}) -> A;
winner({_, _, A, _, A, _, A, _, _}) -> A;
winner(Board) ->
    case is_full(Board) of
      true -> cat;
      false -> no_winner
    end.