So, I am making a tic-tac-toe game in Erlang and it keeps throwing a syntax error and I don't know why. It happens in the function to check if X wins. Here's the code:
checkX(["xxx" | _]) -> true;
checkX([_ | ["xxx" | _]]) -> true;
checkX([_ | [_ | ["xxx" | _]]]) -> true;
checkX(Board) ->
if
xy(Board, {0, 0}) == 120 and xy(Board, {0, 1}) == 120 and xy(Board, {0, 2}) == 120 -> true;
xy(Board, {1, 0}) == 120 and xy(Board, {1, 1}) == 120 and xy(Board, {1, 2}) == 120 -> true;
xy(Board, {2, 0}) == 120 and xy(Board, {2, 1}) == 120 and xy(Board, {2, 2}) == 120 -> true;
xy(Board, {0, 0}) == 120 and xy(Board, {1, 1}) == 120 and xy(Board, {2, 2}) == 120 -> true;
xy(Board, {2, 0}) == 120 and xy(Board, {1, 1}) == 120 and xy(Board, {0, 2}) == 120 -> true;
true -> false
end.
(xy/2 is a function that takes a board (which is a list of strings) and a tuple and returns the character at the position in the tuple.) It keeps throwing this error when I compile it:
board.erl:68: syntax error before '=='
(line 68 is the first condition in the if statement.)
Anyone know why this is?