Академический Документы
Профессиональный Документы
Культура Документы
A PROJECT REPORT
Submitted by
of
BACHELOR OF ENGINEERING
in
03 MAY 2020
ABSTRACT
This study exhibits the application of the concept of matrices, probability and
optimization in making an electronic Tic-Tac-Toe game. For a finite number of
moves in every single game of Tic-Tac-Toe, the moves are recorded in a 3×3
matrix and the subsequent solution, or a winning combination, is presented from
the data obtained by playing the electronic game. The concept of matrices and
probability is applied in this game to make the foundation of the logic for this
game. The most productive position for placing an `X' or `O' is found out using
probabilities. Also the most effective blocking move is found out through which
a player placing `O' can block `X' from winning. The skills help in
understanding what strategy can be implemented to be on the winning side. The
study is developed with an attempt to realistically model a tic-tac-toe game, and
help in reflecting major tendencies. This knowledge helps in understanding
what strategy to implement to be on the winning side.
ALGORITHM:
STEP 1- START GAME
STEP 2- Decide Who is First and Second
STEP 3- Take turn Player-1 is X whereas Player-2 is O
STEP 4- After 9 moves there will be a result
STEP 5- CASE 1: PLAYER 1 is WINNER…Congrats!!
CASE 2: Match draw…Best of luck for both
CASE 3: PLAYER 2 is WINNER…Congrats!!
FLOWCHAT:
START GAME
Decide who goes
if (data[a] == sign)
flag++;
if (flag == 3) {
winner = 1;
goto win;
}
}
flag = 0;
for (a = 0; a < 3; a++) {
for (b = a; b <= a + 6; b = b + 3) {
if (data[b] == sign)
flag++;
}
if (flag == 3) {
winner = 1;
goto win;
}
flag = 0;
}
if ((data[0] == sign && data[4] == sign && data[8] == sign) ||
(data[2] == sign && data[4] == sign && data[6] == sign)) {
winner = 1;
goto win;
}
}
win:
system("clear");
printf("\n\n");
printf("\t\t\t %c | %c | %c \n", data[0], data[1], data[2]);
printf("\t\t\t----+----+----\n");
printf("\t\t\t %c | %c | %c \n", data[3], data[4], data[5]);
printf("\t\t\t----+----+---\n");
printf("\t\t\t %c | %c | %c \n\n", data[6], data[7], data[8]);
if (winner) {
printf("Player %d is the winner. Congrats!!\n", player);
}
else {
printf("Match draw.. Best of luck for both\n");
}
return 0;
}
OUTPUT: