# Report. Tic-Tac-Toe

Topics: Computer, MATLAB, Computer program Pages: 3 (980 words) Published: April 6, 2013
Modeling and Software Development

Individual coursework

Tic-Tac-Toe
Matlab code

Introduction
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.

Theory.
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.

Methodology
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
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}