C language Simple implementation of a 9 Gongge of the well sub-game, either side to complete the three even win!
intWinner =0; intPlayer =0; intCol =0; introw =0; intChoice =0; Charboard[3][3] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'} }; for(inti =0; I <9&& winner = =0; i++) {printf ("\ n"); printf ("%c |%c |%c \ n", board[0][0],board[0][1],board[0][2]); printf ("---+---+---\ n"); printf ("%c |%c |%c \ n", board[1][0],board[1][1],board[1][2]); printf ("---+---+---\ n"); printf ("%c |%c |%c \ n", board[2][0],board[2][1],board[2][2]); Player= i%2+1; Do{printf ("Player%d Please enter the location you want to select to place%c:", player, (player = =1)?'X':'Z'); scanf ("%d",&choice); Col=--choice%3; Row= Choice/3; } while(Choice <0|| Choice >8|| Board[row][col] > $); Board[row][col]= Player = =1?'X':'Z'; /** * * judge if someone wins * * **/ if((board[0][0]==board[1][1]&&board[0][0]==board[2][2])
|| (board[0][2]==board[1][1]&&board[0][2]==board[2][0]) {winner=player; }Else{ for(inti =0; I <3; i++) { if((board[i][0]==board[i][1]&&board[i][0]==board[i][2])
|| (board[0][i]==board[1][i]&&board[0][i]==board[2][i])) {winner=player; } }}} printf ("\ n"); printf ("%c |%c |%c \ n", board[0][0],board[0][1],board[0][2]); printf ("---+---+---\ n"); printf ("%c |%c |%c \ n", board[1][0],board[1][1],board[1][2]); printf ("---+---+---\ n"); printf ("%c |%c |%c \ n", board[2][0],board[2][1],board[2][2]); printf ("********** player%d wins!!! \ n", winner);
C Language Realization Well sub-grid game