Hello! I'm trying to learn Prolog so I figured rock paper scissors would be good practice, and it'd be a better learning experience with shotgun in order to broaden the scope and make it less linear, so to speak. Here's my code:
beats(rock, scissors). % Basic rules of RPS
beats(scissors, paper).
beats(paper, rock).
beats(shotgun, X) :- X \= shotgun. % Nothing beats shotgun, but shotgun does not beat itself
winner(X, Y) :- beats(X, Y) -> X; beats(Y, X) -> Y; neither. % The winner must explicitly beat the other
I'm finding a few issues here:
1. While using stuff like beats(What, rock). works, beats(shotgun, What). should be giving me rock, paper, and scissors as alternatives. I suppose I could be hardcoding this i.e. beats(shotgun, rock). and so on, but that is not a very programmatic solution.
2. The winner logic seems to be correct, but it's trying to call the value I get as a function. I'm under the impression that a lower-case value is equivalent of an atom in Erlang. Returning true. or false. seems to be fine but neither. or rock. and so on does not.
Could y'all tell me why I'm wrong? :)