Info

This question is closed. Reopen it to edit or answer.

Help - function definitions are not permitted in this context

1 view (last 30 days)
I'm writing this rough function for a game of tic tac toe, but whenever I try to run it, it gives me that error message
function [winner_check]= WinnerCheckRow(board)
if board(1)==1 && board(4)==1 && board(7)==1
disp('winner=player1')
elseif board(2)==1 && board(5)==1 && board(8)==1
disp('winner=player1')
elseif board(3)==1 && board(6)==1 && board(9)==1
disp('winner=player1')
else
disp(' ')
end
if board(1)==2 && board(4)==2 && board(7)==2
disp('winner=player2')
elseif board(2)==2 && board(5)==2 && board(8)==2
disp('winner=player2')
elseif board(3)==2 && board(6)==2 && board(9)==2
disp('winner=player2')
else
disp(' ')
end
Any tips would really be appreciated!
  1 Comment
per isakson
per isakson on 28 Sep 2015
Edited: per isakson on 28 Sep 2015
Put your code in a new file and and save it with the name WinnerCheckRow.m. Make sure
function [winner_check]= WinnerCheckRow(board)
is the first line of file

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!