Christian - what are the inputs f_user1 and f_user2? Are one of these the functions that you will create?
As for adding intelligence to your game, you would have to define what the rules are based on the moves by the opponents If the opponent has made its move, you could have one or more functions that determine whether
- you can win on the next move (so the opponents last move is irrelevant)
- you cannot win on the next move but the opponent can (so you need to block)
- neither can win on the next move so you may want to try to find the smartest move so that you win on the next turn.
For the first function, are there empty squares where you can add your x (or o) so that you win? If so, then take that square.
For the second function, are there any empty squares where the opponent can add his/her x (or o) so that they win? If so, then take that square.
etc.
function [board] = myTicTacToeAI(board, marker)
if any(any(board) == 0)
% you are making the first move so choose a random corner
else
% check if you can win on this move
if iCanWinOnNextMove(board, marker)
% make the winning move
elseif opponentCanWinOnNextMove(board, marker)
% block their move
else
% position yourself to win on your next move
end
end
end
Not sure if the above is helpful but it give an idea on what to do. Note that I'm assuming that marker is the value you use to populate the board (the x or o) and that iCanWinOnNextMove and opponentCanWinOnNextMove functions that you would need to define.