Tic tac toe

24
TIC TAC TOE Submitted to- Submitted by- Mrs.Dipti Kunra Jasleen Kaur D2 CSE 1144384 PROJECT

Transcript of Tic tac toe

Page 1: Tic tac toe

TIC TAC TOESubmitted to- Submitted by-Mrs.Dipti Kunra Jasleen Kaur D2 CSE 1144384

PROJECT

Page 2: Tic tac toe

TIC-TAC-TOE

Page 3: Tic tac toe

INTRODUCTIONTic-tac-toe, also called noughts and crosses (in the British Commonwealth countries), Xs and Os (in Ireland) and X and 0 (in India) is a pencil-and-paper game for two players, X and O, who take turns marking the spaces in a 3×3 grid. 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:

Players soon discover that best play from both parties leads to a draw (often referred to as cat or cat's game). Hence, tic-tac-toe is most often played by young children.The friendliness of tic-tac-toe games makes them ideal as a pedagogical tool for teaching the concepts of good sportsmanship and the branch of artificial intelligence that deals with the searching of game trees. It is straightforward to write a computer program to play tic-tac-toe perfectly, to enumerate the 765 essentially different positions (the state space complexity), or the 26,830 possible games up to rotations and reflections (the game tree complexity) on this space

Page 4: Tic tac toe

StrategyOptimal strategy for player X. In each grid, the shaded red X denotes the optimal move, and the location of O's next move gives the next subgrid to examine. Note that only two sequences of moves by O (both starting with center, top-right, left-mid) lead to a draw, with the remaining sequences leading to wins from X.A player can play perfect tic-tac-toe (win or draw) given they choose the first possible move from the following list.

Win: If the player has two in a row, he or she can place a third to get three in a row.

Block: If the [opponent] has two in a row, the player must play the third himself or herself to block them.

Fork: Creation of an opportunity where the player has two threats to win (two non-blocked lines of 2).Blocking an opponent's fork:Option 1: The player should create two in a row to force the opponent into defending, as long as it doesn't result in them creating a fork. For example, if "X" has a corner, "O" has the center, and "X" has the opposite corner as well, "O" must not play a corner in order to win. (Playing a corner in this scenario creates a fork for "X" to win.)Option 2: If there is a configuration where the opponent can fork, the player should block that fork.

Center: A player marks the center. (If it is the first move of the game, playing on a corner gives "O" more opportunities to make a mistake and may therefore be the better choice; however, it makes no difference between perfect players.)

Opposite corner: If the opponent is in the corner, the player plays the opposite corner.

Page 5: Tic tac toe

INTRODUCTION TO C++ The c++ programming language is a very powerful general purpose programming language that supports procedural programming as well as object oriented programming .It incoporates all the ingredients required for building software for large and complex problems.The C++ programming language provides a model of memory and computation that closely matches that of most computers. In addition, it provides powerful and flexible mechanisms for abstraction; that is, language constructs that allow the programmer to introduce and use new types of objects that match the concepts of an application. Thus, C++ supports styles of programming that rely on fairly direct manipulationof hardware resources to deliver a high degree of efficiency plus higher-level styles of programming that rely on user-defined types to provide a model of data and computation that is closer to a human’s view ofthe task being performed by a computer. These higher-level styles of programming are often called data abstraction, object-oriented programming, and generic programming.

Page 6: Tic tac toe

EVOLUTION OF C++LANGUAGEC++ is a powerful programming language that had attracted worldwide attention because the software industry had adopted the language to great advantage. The programs written in c++ are portable ,fast and efficient.C++ was designed and implemented by Bjarne Stroustrup at AT&T Bell Laboratories to combine the organizational and design strengths of Simula with C’s facilities for systems programming.The initial version of C++, called ‘‘C with Classes’’ , was first used in 1980. It supported traditional system programming techniques and data abstraction . The basic facilities for object-oriented programming were added in 1983 and object-oriented design and programmingtechniques were gradually introduced into the C++ community. The language was first made commercially available in 1985 . Facilities for generic programming were added to the language in the 1987-1989 time frame . As the result of widespread use and the appearance of several independently-developed C++ implementations, formal standardization of C++ started in 1990 under the auspices of the American National Standards Institute, ANSI, and later the International Standards Organization, ISO, leading to an international standard in 1998 . During the period of standardization the standards committee acted as an important focus for the C++ community and its draft standards acted as interim definitions ofthe language.

Page 7: Tic tac toe

IOstream LibraryStandard Input / Output Streams Library The iostream library is an object-oriented library that provides input and output functionality using streams.A stream is an abstraction that represents a device on which input and ouput operations are performed. A stream can basically be represented as a source or destination of characters of indefinite length.Streams are generally associated to a physical source or destination of characters, like a disk file, the keyboard, or the console, so the characters gotten or written to/from our abstraction called stream are physically input/output to the physical device. For example, file streams are C++ objects to manipulate and interact with files; Once a file stream is used to open a file, any input or output operation performed on that stream is physically reflected in the file. 

Page 8: Tic tac toe

DATA TYPESWhile doing programming in any programming language, you need to use various variables to store various information. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.You may like to store information of various data type like character, wide character, integer, floating point, double floating point, boolean etc. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory.Type Typical Bit Width Typical Rangechar 1byte -127 to 127 or 0 to 255int 4bytes -2147483648 to 2147483647bool 1byte false or true  

Page 9: Tic tac toe

OperatorsOnce we know of the existence of variables and constants, we can begin to operate with them. For that purpose, C++ integrates operators. Unlike other languages whose operators are mainly keywords, operators in C++ are mostly made of signs that are not part of the alphabet but are available in all keyboards. This makes C++ code shorter and more international, since it relies less on English words, but requires a little of learning effort in the beginning.

1. Assignment (=)The assignment operator assigns a value to a variable.a = 5; 

2.Arithmetic operators ( +, -, *, /, % )The five arithmetical operations supported by the C++ language are: + addition, - subtraction* multiplication/ division% modulo 

3.Relational and equality operators== Equal to!= Not equal to

Page 10: Tic tac toe

4. Logical operators( !, &&)! ORERATOR!(5 == 5) // evaluates to false because the expression at its right (5 == 5) is true. !(6 <= 4) // evaluates to true because (6 <= 4) would be false. !true // evaluates to false!false // evaluates to true. && OPERATOR

a b a && btrue true truetrue false falsefalse true falsefalse false false

Page 11: Tic tac toe

Control StructuresA program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose, C++ provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

Conditional structure: if and elseThe if keyword is used to execute a statement or block only if a condition is fulfilled.syntax:if (condition) statement1 else statement2For example:if (x == 100) cout << "x is 100";Else cout << "x is not 100";

 Iteration structures (loops)The do-while loopIts format is:do statement while (condition); Its functionality is exactly the same as the while loop, except that condition in the do-while loop is evaluated after the execution of statement instead of before, granting at least one execution of statement even if condition is never fulfilled. 

Page 12: Tic tac toe

SCREEN SHOTS

Page 13: Tic tac toe

{

Page 14: Tic tac toe

2.

Page 15: Tic tac toe
Page 16: Tic tac toe
Page 17: Tic tac toe
Page 18: Tic tac toe
Page 19: Tic tac toe
Page 20: Tic tac toe
Page 21: Tic tac toe
Page 22: Tic tac toe

Various game shows have been based on Tic-Tac-Toe and its variants: On Hollywood Squares, nine celebrities filled the cells of the tic-tac-toe grid;

players put symbols on the board by correctly agreeing or disagreeing with a celebrity's answer to a question. Variations of the show include Storybook Squares and Hip Hop Squares.

In Tic-Tac-Dough, players put symbols up on the board by answering questions in various categories, which shuffle after each player's turn.

In Beat the Teacher, contestants answer questions to win a turn to influence a tic-tac-toe grid.

On The Price Is Right, several national variants feature a pricing game called "Secret X," in which players must guess prices of two small prizes to win Xs (in addition to one free X) to place on a blank board. They must place the Xs in position to guess the location of the titular "secret X" hidden in the center column of the board and form a tic-tac-toe line across or diagonally (no vertical lines allowed). There are no Os in this variant of the game.

On Minute to Win It, the game Ping Tac Toe has one contestant playing the game with nine water-filled glasses and white and orange ping-pong balls, trying to get three in a row of either color. They must alternate colors after each successful landing and must be careful not to block themselves. 

APPLICATIONS

Page 23: Tic tac toe

1. This game cannot be played by one or more than 2 players.2. It is not a high level game.3. It doesn’t contain levels.

LIMITATIONS

Page 24: Tic tac toe

THANK YOU