-module(prog).
-export([main/0, play/1]).

-define(RULES, [{spock, [scissors, stone]},
				{lizard, [spock, paper]},
				{paper, [spock, stone]},
				{stone, [lizard, scissors]},
				{scissors, [lizard, paper]}]).


main() ->
	play(spock),
	play(pizda_tvoei_mamki),
	play(scissors),
	play(scissors).
	

play(Item) ->
	Members = proplists:get_keys(?RULES),
	case lists:member(Item, Members) of
		false ->
			io:format("Wrong item passed ~n");
		_ ->
			random:seed(now()),
			EnemyItem = lists:nth(random:uniform(length(Members)), Members),
			case fight(Item, EnemyItem) of
				draw ->
					io:format("Draw ~n");
				{win, Item} ->
					io:format("You win with ~p against ~p~n", [Item, EnemyItem]);
				_ ->
					io:format("You loose with ~p against ~p~n", [Item, EnemyItem])
			end
	end.

	
fight(X, X) -> draw;
fight(X, Y) -> 
	case lists:member(Y, proplists:get_value(X, ?RULES)) of
		true ->
			{win, X};
		_ ->
			{win, Y}
	end.