Modeling and Software Development
Tic-Tac-Toe is a popular simple game for two players all over the world. Traditionally one person plays for “X” while another plays for “O”. The game is played on the square board of 3x3 or even more size. The aim of this game for player is to win by filling with “X” or “O” any row, column or diagonal of the main game board. The game sets players thinking because players should reflect a little bit on strategy and predict some moves of the opponent. So it teaches people to make decisions quickly. MATLAB is computer software for technical computing from the MathWorks. Used for a wide variety of scientific and engineering calculations. The functions of the MATLAB are solving equations, plotting 2D, 3D graphs, calculating statistics, etc. The aim of the report is to describe how Tic-Tac-Toe game simulation was made with the help of MATLAB. The report describes how program reads the code and computer strategy for winning/not losing in the game.
The aim the individual coursework was to program 4x4 Tic-Tac-Toe game for player and computer using MATLAB with condition that computer should always win or just not loose. Programming the game basic loops such as “while”, “for”, “if” were used, where “while” means to repeat smth until some particular conditions are holding, “for” means to do smth for particular conditions, and “if” means to do smth if some conditions are true. There also were used “sum” function which helps to count “X”-s or “O”-s in rows, columns, diagonals and basic commands for matrices.
The game is played in command window, using the matrice 4x4, where “X” is 1, “O” is -1 and empty cells are zeros. The main algorithm of the program is on Graph 1.
Graph 1. The main algorithm of the Tic-Tac-Toe program.
The game is starting by choosing randomly either computer is playing for “X” or for “O”. Then first move is...
Please join StudyMode to read the full document