By 'n' I mean any length of square grid. You solution should still be valid for a 1x1 grid. (I've now added an extra test script for this case). Though in reality I agree such a game wouldnt be much fun!
https://www.mathworks.com/matlabcentral/cody/problems/44851 adds the dynamic of stopping play when someone wins, though Ciaran's test suite needs fixing before you can attempt this one
https://www.mathworks.com/matlabcentral/cody/problems/44851 provides a more challenging extension that asks the user to take into account that games end when there's a "win".
My first attempt at producing a community problem so thanks for the feedback on improving the test suite.