Created
July 13, 2014 21:43
-
-
Save ferd/35a4e9af633339150411 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(demo). | |
% ... | |
check(Board) -> | |
case winner(Board) of | |
{victory, Player} -> % Player wins; | |
undefined -> | |
case is_full(Board) of | |
true -> draw; | |
false -> keep_playing | |
end | |
end. | |
winner(Board) of | |
case Board of | |
{x, x, x, | |
_, _, _, | |
_, _, _} -> {victory, x}; | |
{x, _, _, | |
_, x, _, | |
_, _, x} -> {victory, x}; | |
{x, _, _, | |
x, _, _, | |
x, _, _} -> {victory, x}; | |
%% [snip] | |
_ -> undefined | |
end. | |
is_full(Board) -> | |
lists:all(fun(X) -> X =/= undefined end, tuple_to_list(Board)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment