# Program for tic tac toe in c?

###### Wiki User

###### 2011-05-27 05:14:48

THE PROGRAM FOR TIC TAC TOE IN "C" LANGUAGE ARE:

#include <stdio.h>

#include <ctype.h>

#define String_Length 80

#define Squares 9

typedef char Square_Type;

typedef Square_Type Board_Type[Squares];

const Square_Type Empty = ' ';

const int Infinity = 10; /* Higher value than any score */

const int Maximum_Moves = Squares; /* Maximum moves in a game

*/

int Total_Nodes; /* Nodes searched with minimax */

/* Array describing the eight combinations of three squares in a

row */

#define Possible_Wins 8

const int Three_in_a_Row[Possible_Wins][3] = {

{ 0, 1, 2 },

{ 3, 4, 5 },

{ 6, 7, 8 },

{ 0, 3, 6 },

{ 1, 4, 7 },

{ 2, 5, 8 },

{ 0, 4, 8 },

{ 2, 4, 6 }

};

/* Array used in heuristic formula for each move. */

const int Heuristic_Array[4][4] = {

{ 0, -10, -100, -1000 },

{ 10, 0, 0, 0 },

{ 100, 0, 0, 0 },

{ 1000, 0, 0, 0 }

};

/* Structure to hold a move and its heuristic */

typedef struct {

int Square;

int Heuristic;

} Move_Heuristic_Type;

/* Clear the board */

void Initialize(Board_Type Board) {

int I;

for (I = 0; I < Squares; I++)

Board[I] = Empty;

}

/* If a player has won, return the winner. If the game is a

tie,

return 'C' (for cat). If the game is not over, return Empty.

*/

Square_Type Winner(Board_Type Board) {

int I;

for (I = 0; I < Possible_Wins; I++) {

Square_Type Possible_Winner = Board[Three_in_a_Row[I][0]];

if (Possible_Winner != Empty &&

Possible_Winner 'Y');

}