I'm trying to make a small function that checks whether a spot is taken on a Tic Tac Toe board or not. I have created an array of zeroes called tttArray where when each spot is filled, its location is changed to 1. So I first take the input from the player from the below function.
function [pXInputRow, pXInputCol] = pickXspot(playerInput)%This function is to take inputs from Player X
pXInputRow = 0;pXInputCol = 0;%Set text for Row/Col Prompt
prompt = {'Row (1,2, or 3)', '(Col (1, 2, or 3)'};name = 'Player X Turn';%Show prompt to input values
playerInput = inputdlg(prompt, name);pXInputRow = str2num(playerInput{2});pXInputCol = str2num(playerInput{1});tttArray(pXInputRow, pXInputCol) = 1;end
And then use the below function to see if the spot is taken.
function [spotTaken] = checktaken(tttArray)%Function used to check if spot is taken
%Setup Error Messages
errorMessage = 'This spot is taken, please choose another spot';errorMessageTitle = 'Spot Taken';if tttArray(pXInputRow, pXInputCol) || tttArray(pOInputRow, pOInputCol) == 1 msgbox(errorMessage, errorMessageTitle) spotTaken = 1;endend
However, I keep getting the following error after I run and put a row/col in the prompt dialog box. Any Suggestions?
Not enough input arguments.Error in checktaken (line 8)if tttArray(pXInputRow, pXInputCol) || tttArray(pOInputRow, pOInputCol) == 1
Best Answer