parameter changed

master
Your Name 7 years ago
parent 8fc85381d2
commit e782c7bcb1

Binary file not shown.

@ -31,13 +31,13 @@ void init_board(char arr[3][3]) //
}
}
}
int whom_act() //Ñ¡ÔñË­ÏÈÐж¯
int who_act() //选择谁先行动
{
int input = 0;
int input = 0;char ch=0;
printf("****************************\n");
printf("** Who goes first? **\n");
printf("** 1:Computer **\n");
printf("** 0:You **\n");
printf("** 2:You **\n");
printf("****************************\n");
while (1)
{
@ -45,10 +45,13 @@ int whom_act() //ѡ
scanf("%d", &input);
if (input == 1)
return 1;
else if (input == 0)
return 0;
else if (input == 2)
return 2;
else
{
while ((ch = getchar()) != EOF && ch != '\n');
printf("wrong input\n");
}
}
}
int check_(char arr[3][3]) //ÅÐ¶ÏÆå×ÓÊÇ·ñÏÂÂú
@ -82,9 +85,9 @@ void player_act(char arr[3][3]) //
char ch;
while (1)
{
printf("Coordinnate:(x,y) 1<=x<=3,1<=y<=3\n");
scanf("%d,%d", &x, &y);
if(arr[--x][--y] == ' ')
printf("Coordinnate: x,y (0<x<4,0<y<4)\n");
int i=scanf("%d,%d", &x, &y);
if(i==2&&arr[--x][--y] == ' ')
{
arr[x][y] = 'O';
break;
@ -122,12 +125,12 @@ void computer_act_normal(char arr[3][3])
{
int value[3][3] = {{0}};
int i = 0, j = 0, m = 0, n = 0, count_X = 0, count_O = 0, count_ = -1;
if(check_(arr) == empty)
if(check_(arr) == empty)//如果电脑先手则电脑随机选择棋盘4个角
{
do
{
srand((unsigned)time(NULL));
i=rand()%3;
i=rand()%3;//随机数012
j=rand()%3;
if((i == j && i!=1 ) || j - i == 2 || i - j == 2)
{
@ -144,8 +147,8 @@ void computer_act_normal(char arr[3][3])
{
for(m = 0; m < 3; m++)
arr[i][m] == 'O' ? count_O++ : arr[i][m] == 'X' ? count_X++ : count_++;
if(count_X == 2) value[i][j] += 6;
else if(count_O == 2) value[i][j] += 5;
if(count_X == 2) value[i][j] += 100;
else if(count_O == 2) value[i][j] += 50;
else if(count_X == 1 && count_ == 1) value[i][j] += 4;
else if(count_O == 1 && count_ == 1) value[i][j] += 3;
else if(count_ == 2) value[i][j] += 2;
@ -155,12 +158,12 @@ void computer_act_normal(char arr[3][3])
count_ = -1;
for(m = 0; m < 3; m++)
arr[m][j] == 'O' ? count_O++ : arr[m][j] == 'X' ? count_X++ : count_++;
if(count_X == 2) value[i][j] += 6;
else if(count_O == 2) value[i][j] += 5;
if(count_X == 2) value[i][j] += 100;
else if(count_O == 2) value[i][j] += 50;
else if(count_X == 1 && count_ == 1) value[i][j] += 4;
else if(count_O == 1 && count_ == 1) value[i][j] += 3;
else if(count_ == 2) value[i][j] += 2;
else value[i][j] += 1;
else value[i][j] += 0;
count_X = 0;
count_O = 0;
count_ = -1;
@ -170,8 +173,8 @@ void computer_act_normal(char arr[3][3])
{
for(m = 0; m < 3; m++)
arr[m][m] == 'O' ? count_O++ : arr[m][m] == 'X' ? count_X++ : count_++;
if(count_X == 2) value[i][j] += 6;
else if(count_O == 2) value[i][j] += 5;
if(count_X == 2) value[i][j] += 100;
else if(count_O == 2) value[i][j] += 50;
else if(count_X == 1 && count_ == 1) value[i][j] += 4;
else if(count_O == 1 && count_ == 1) value[i][j] += 3;
else if(count_ == 2) value[i][j] += 2;
@ -184,8 +187,8 @@ void computer_act_normal(char arr[3][3])
{
for(m = 0, n = 2; m < 3; m++, n--)
arr[m][n] == 'O' ? count_O++ : arr[m][n] == 'X' ? count_X++ : count_++;
if(count_X == 2) value[i][j] += 6;
else if(count_O == 2) value[i][j] += 5;
if(count_X == 2) value[i][j] += 100;
else if(count_O == 2) value[i][j] += 50;
else if(count_X == 1 && count_ == 1) value[i][j] += 4;
else if(count_O == 1 && count_ == 1) value[i][j] += 3;
else if(count_ == 2) value[i][j] += 2;

@ -4,25 +4,25 @@
#include "sanziqi.h"
int main() //Ö÷º¯Êý
{
char arr[3][3], ch;
char arr[3][3], ch=0;
while(1)
{
menu();
int i = 0;
scanf("%d", &i);
scanf("%d", &i);//Ñ¡Ôñ¿ªÊ¼»ò½áÊø
if(i == start_game)
{
int choice = 0;
mode();
init_board(arr);
again: i = scanf("%d", &choice);
again: i = scanf("%d", &choice);//Ñ¡ÔñÄѶÈ
if(i == 1)
{
switch(choice)
{
case 1:
print_board(arr);
if(whom_act() == computer_first)
if(who_act() == computer_first)
{
while(check_(arr) != full)
{
@ -61,7 +61,7 @@ int main() //
break;
case 2:
print_board(arr);
if(whom_act() == computer_first)
if(who_act() == computer_first)
{
while(check_(arr) != full)
{

Binary file not shown.

Binary file not shown.

@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#define computer_first 1
#define player_first 0
#define player_first 2
#define start_game 1
#define end_game 0
#define full 9
@ -17,7 +17,7 @@ void print_board(char arr[3][3]); //打印棋盘
void menu(); //菜单
int whom_act(); //选择谁先行动
int who_act(); //选择谁先行动
int check_(char arr[3][3]); //判断棋盘状态

Loading…
Cancel
Save