Tuesday, December 15, 2009

DESIGNING TIC TAC TOE PROGRAM USING C++ LANGUAGE


Find the file in Google Groups

Tic-tac-toe, also spelled tick tack toe, and alternatively called noughts and crosses, X's and O's, and many other names, is a pencil-and-paper game for two players, O and X, who take turns marking the spaces in a 3×3 grid, usually X going first. The player who succeeds in placing three respective marks in a horizontal, vertical or diagonal row wins the game.

The following example game is won by the first player, X:

Game of tic-tac-toe, won by X

Players soon discover that best play from both parties leads to a draw. Hence, tic-tac-toe is most often played by young children; when they have discovered an unbeatable strategy they move on to more sophisticated games such as chess or chinese checkers. This reputation for ease has led to casinos offering gamblers the chance to play tic-tac-toe against trained chickens—though the chicken is advised by a computer program.


How do we design a simple DOS program for two players?


First of all, we need to approach the game structure systematically using problem decomposition, i.e., breaking down the main problem into small manageable chunks of problem.


EXAMPLE 1

basic procedures:

1. main() - to control the program

2. PlayGame() - to control the game session

3. GameRound() - to control each player's turn

4. DisplayPanel() - to control the game display

5. DisplaySymbol() - to control the symbol display

6. CheckWin() - to determine winning condition

7. InitVar() - to initialize variables before a game session starts

optional procedures:

8. GetPlayerNames() - to get the name of each players

9. PlaySound() - to play certain sounds to accompany events in the game

10. ComputerPlayer() - to play against the human

No comments:

Post a Comment