"Fun board Game" write a player-operated function and a two-person board game that the computer can manipulate, which has three connected wins

Source: Internet
Author: User

#include  <stdio.h> #include  <stdlib.h>char arr[3][3];void print () {int t; for (t=0;t<3;t++) {printf ("%c|%c|%c|", arr[t][0],arr[t][1],arr[t][2]);p rintf ("\n_|_|_|\n");}} Void init () {int i,j;for (i=0;i<3;i++) {for (j=0;j<3;j++) {arr[i][j]= '   ';}}} Void player_move () {int x,y;printf ("Please enter the coordinates of your chess!"); scanf ("%d%d", &x,&y) x--;y--;if (arr[x][y]!= '   '  ) {printf ("The location is already occupied, please reenter the!!! \ n ");p layer_move ();} else arr[x][y]= ' x ';} Int computer () {int i, j;    for  (i = 0; i <  3; i++)     {        for  (j =  0; j < 3; j++)         {             if  (arr[i][j] ==  '   '  )              {            arr[i][j]= ' 0 ';                 break;             }        }         break;    }}char check () {int i;for (i=0;i<3;i++) {if (arr[i][0 ]==arr[i][1]&&arr[i][1]==arr[i][2]) {return arr[i][0];}} for (i=0;i<3;i++) {if (Arr[0][i]==arr[1][i]&&arr[1][i]==arr[2][i]) {return arr[0][i];}} if (Arr[0][0]==arr[1][1]&&arr[1][1]==arr[2][2]) {return arr[0][0];} if (Arr[0][2]==arr[1][1]&&arr[1][1]==arr[2][0]) {return arr[0][2];} else {return  '   ';}} Int main () {char none;printf ("Welcome to board game!\n"), init ();d o{print ();p layer_move (); None=check (); if (none!= ')   ') break;computer (); if (none!= '   ') break;} while (none== '   '), if (none== ' X ') {printf ("Congratulations on winning!\ n ");} ELSE&NBSP;{PRINTF ("Computer wins!\n");} Print ();}


"Fun board Game" write a player-operated function and a two-person board game that the computer can manipulate, which has three connected wins

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.