**fig10_66.txt** /* 1*/ // Supporting types. /* 2*/ enum Value_Type { Comp_Loss, Draw, Comp_Win }; /* 3*/ enum Player_Type { Comp, Human }; /* 4*/ typedef int Board_Type[ 10 ]; /* 5*/ // Supporting routines. /* 6*/ int Full_Board( Board_Type B ); /* 7*/ int Immediate_Win( Board_Type B, int & Move, Player_Type P ); /* 8*/ void Place( Board_Type B, int Square, Player_Type P ); /* 9*/ int Is_Empty( Board_Type B, int Square ); /*10*/ void Unplace( Board_Type B, int Square ); /*11*/ void Find_Human_Move( Board_Type & B, int &, int & Value ); /* 1*/ // Recursive procedure to find best move for computer. /* 2*/ // Best_Move is a number from 1-9 indicating square. /* 3*/ // Possible evaluations satisfy Comp_Loss < Draw < Comp_Win. /* 4*/ // Complementary routine Find_Human_Move isin Fig. 10.67. . /* 5*/ // Board_Type is an array; thus Board can be changed by Place( ). /* 6*/ void /* 7*/ Find_Comp_Move( Board_Type & Board, int & Best_Move, int & Value ) /* 8*/ { /* 9*/ int Dc, i, Response; // Dc means don't care. /*10*/ if( Full_Board( Board ) ) /*11*/ Value = Draw; /*12*/ else /*13*/ if( Immediate_Win( Board, Best_Move, Comp ) ) /*14*/ Value = Comp_Win; /*15*/ else /*16*/ { /*17*/ Value = Comp_Loss; /*18*/ for( i = 1; i <= 9; i++ ) // Try each square. /*19*/ { /*20*/ if( Is_Empty( Board, i ) ) /*21*/ { /*22*/ Place( Board, i, Comp ); /*23*/ Find_Human_Move( Board, Dc, Response ); /*24*/ Unplace( Board, i ); // Restore board. /*25*/ if( Response > Value ) // Update best move. /*26*/ { /*27*/ Value = Response; /*28*/ Best_Move = i; /*29*/ } /*30*/ } /*31*/ } /*32*/ } /*33*/ }