在VC++环境下编译会报错...求高手指点怎么修改~
#include <stdio.h>
#define P1 1
#define P2 -1
#define SIZE 3
#define WIN -1
#define UNWIN 0
#define PEACE 1
#define chkAndPutDwnRow(row, col){
for(col = 0; col < SIZE; col++){
if(chsman[row][col] == 0){
chsman[row][col] = P2;
dsply();
return;
}
}
}
#define chkAndPutDwnCol(row, col){
for(col = 0; col < SIZE; col++){
if(chsman[col][row] == 0){
chsman[col][row] = P2;
dsply();
return;
}
}
}
#define chkAndPutDwn_Slsh(row, col){
if(chsman[row][col] == 0){
chsman[row][col] = P2;
dsply();
return;
}
}
int chsman[SIZE][SIZE] = {0};
int enterChsman(int, int);
void dsply(void);
void input(void);
void judge(void);
int chkWin(void);
int chkPeace(void);
int stepFlg = 0;
int enterChsman(int row, int col)
{
if(row > = SIZE || col > = SIZE)
return 0;
if(chsman[row][col] != 0)
return 0;
chsman[row][col] = P1;
return 1;
}
void input(void)
{
int row, col;
do{
printf( "Please locate your chessman:\n ");
printf( "Location row: ");
scanf( "%d ", &row);
printf( "Location column: ");
scanf( "%d ", &col);
if(enterChsman(row - 1, col - 1) == 1){
printf( "You located chessman at [%d][%d].\n ", row, col);
dsply();
break;
}
else
printf( "Error : You put the chess to a wrong location\n ");
}while(1);
return;
}
void judge(void)
{
int row, col;
int i;
int rskAndAtkLevlRow[SIZE] = {0}, rskAndAtkLevlCol[SIZE] = {0}, rskAndAtkLevlSlsh[2] = {0};
if(stepFlg == 0){
stepFlg = 1;
if(chsman[1][1] == P1){
chsman[0][0] = P2;
printf( "The computer located chessman at [0][0].\n ");
dsply();
return;
}
else{
chsman[1][1] = P2;
printf( "The computer located chessman at [1][1].\n ");
dsply();
return;
}
}
stepFlg++;
for(row = 0; row < SIZE; row++){
for(col = 0; col < SIZE; col++){
rskAndAtkLevlRow[row] += chsman[row][col];
}
}
for(col = 0; col < SIZE; col++){
for(row = 0; row < SIZE; row++){
rskAndAtkLevlCol[col] += chsman[row][col];
}
}
rskAndAtkLevlSlsh[0] = chsman[0][0] + chsman[1][1] + chsman[2][2];
rskAndAtkLevlSlsh[1] = chsman[0][2] + chsman[1][1] + chsman[2][0];
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlRow[i] == -2){
chkAndPutDwnRow(i, col)
}
}
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlCol[i] == -2){
chkAndPutDwnCol(i, col)
}
}
if(rskAndAtkLevlSlsh[0] == -2){
for(row = 0, col = 0; row < SIZE; row++, col++){
chkAndPutDwn_Slsh(row, col)
}
}
if(rskAndAtkLevlSlsh[1] == -2){
for(row = 0, col = 2; row < SIZE; row++, col--){
chkAndPutDwn_Slsh(row, col)
}
}
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlRow[i] == 2){
chkAndPutDwnRow(i, col)
}
}
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlCol[i] == 2){
chkAndPutDwnCol(i, col)
}
}
if(rskAndAtkLevlSlsh[0] == 2){
for(row = 0, col = 0; row < SIZE; row++, col++){
chkAndPutDwn_Slsh(row, col)
}
}
if(rskAndAtkLevlSlsh[1] == 2){
for(row = 0, col = 2; row < SIZE; row++, col--){
chkAndPutDwn_Slsh(row, col)
}
}
for(row = 0; row < SIZE; row++){
for(col = 0; col < SIZE; col++){
if(chsman[row][col] == 0 && ((row == 0 && col == 0) || (row == 0 && col == 2) ||
(row == 2 && col == 0) || (row == 2 && col == 2))){
chsman[row][col] = P2;
dsply();
return;
}
}
}
}
void dsply(void)
{
int row, col, i;
for(i = 0; i < SIZE * 4 + 1; i++)
printf( "- ");
printf( "\n ");
for(row = 0; row < SIZE; row++){
printf( "| ");
for(col = 0; col < SIZE; col++){
if(chsman[row][col] == P1) printf( " o | ");
else if(chsman[row][col] == P2) printf( " x | ");
else printf( " | ");
}
printf( "\n ");
for(i = 0; i < SIZE * 4 + 1; i++)
printf( "- ");
printf( "\n ");
}
return;
}
int chkWin(void)
{
int i;
for(i = 0; i < SIZE; i++){
if(chsman[i][0] + chsman[i][1] + chsman[i][2] == -3 || chsman[0][i] + chsman[1][i] + chsman[2][i] == -3 ||
chsman[0][0] + chsman[1][1] + chsman[2][2] == -3 || chsman[0][2] + chsman[1][1] + chsman[2][0] == -3){
return WIN;
}
}
return UNWIN;
}
int chkPeace(void)
{
int row, col;
int sum = 0;
for(row = 0; row < SIZE; row++){
for(col = 0; col < SIZE; col++){
if(sum += chsman[row][col] == PEACE){
return PEACE;
}
}
}
return 0;
}
int main(char* args[])
{
dsply();
do{
input();
judge();
if(chkWin() == WIN) break;
if(stepFlg == 5 && chkPeace() == PEACE){
printf( "Peace! ");
return 0;
}
}while(1);
printf( "You Win! ");
return 0;
}
[解决办法]
不知道这个程序是你自己编写的,还是........
错误很多呀!!!
#include <stdio.h>
#define P1 1
#define P2 -1
#define SIZE 3
#define WIN -1
#define UNWIN 0
#define PEACE 1
int chsman[SIZE][SIZE] = {0};
int enterChsman(int, int);
void dsply(void);
void input(void);
void judge(void);
int chkWin(void);
int chkPeace(void);
int stepFlg = 0;
void chkAndPutDwnRow(int row,int col){
for(col = 0; col < SIZE; col++){
if(chsman[row][col] == 0){
chsman[row][col] = P2;
dsply();
return;
}
}
}
void chkAndPutDwnCol(int row,int col){
for(col = 0; col < SIZE; col++){
if(chsman[col][row] == 0){
chsman[col][row] = P2;
dsply();
return;
}
}
}
void chkAndPutDwn_Slsh(int row,int col){
if(chsman[row][col] == 0){
chsman[row][col] = P2;
dsply();
return;
}
}
int enterChsman(int row, int col)
{
if(row > = SIZE || col > = SIZE)
return 0;
if(chsman[row][col] != 0)
return 0;
chsman[row][col] = P1;
return 1;
}
void input(void)
{
int row, col;
do{
printf( "Please locate your chessman:\n ");
printf( "Location row: ");
scanf( "%d ", &row);
printf( "Location column: ");
scanf( "%d ", &col);
if(enterChsman(row - 1, col - 1) == 1){
printf( "You located chessman at [%d][%d].\n ", row, col);
dsply();
break;
}
else
printf( "Error : You put the chess to a wrong location\n ");
}while(1);
return;
}
void judge(void)
{
int row, col;
int i;
int rskAndAtkLevlRow[SIZE] = {0}, rskAndAtkLevlCol[SIZE] = {0}, rskAndAtkLevlSlsh[2] = {0};
if(stepFlg == 0){
stepFlg = 1;
if(chsman[1][1] == P1){
chsman[0][0] = P2;
printf( "The computer located chessman at [0][0].\n ");
dsply();
return;
}
else{
chsman[1][1] = P2;
printf( "The computer located chessman at [1][1].\n ");
dsply();
return;
}
}
stepFlg++;
for(row = 0; row < SIZE; row++){
for(col = 0; col < SIZE; col++){
rskAndAtkLevlRow[row] += chsman[row][col];
}
}
for(col = 0; col < SIZE; col++){
for(row = 0; row < SIZE; row++){
rskAndAtkLevlCol[col] += chsman[row][col];
}
}
rskAndAtkLevlSlsh[0] = chsman[0][0] + chsman[1][1] + chsman[2][2];
rskAndAtkLevlSlsh[1] = chsman[0][2] + chsman[1][1] + chsman[2][0];
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlRow[i] == -2){
chkAndPutDwnRow(i, col);
}
}
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlCol[i] == -2){
chkAndPutDwnCol(i, col);
}
}
if(rskAndAtkLevlSlsh[0] == -2){
for(row = 0, col = 0; row < SIZE; row++, col++){
chkAndPutDwn_Slsh(row, col);
}
}
if(rskAndAtkLevlSlsh[1] == -2){
for(row = 0, col = 2; row < SIZE; row++, col--){
chkAndPutDwn_Slsh(row, col);
}
}
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlRow[i] == 2){
chkAndPutDwnRow(i, col);
}
}
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlCol[i] == 2){
chkAndPutDwnCol(i, col);
}
}
if(rskAndAtkLevlSlsh[0] == 2){
for(row = 0, col = 0; row < SIZE; row++, col++){
chkAndPutDwn_Slsh(row, col);
}
}
if(rskAndAtkLevlSlsh[1] == 2){
for(row = 0, col = 2; row < SIZE; row++, col--){
chkAndPutDwn_Slsh(row, col);
}
}
for(row = 0; row < SIZE; row++){
for(col = 0; col < SIZE; col++){
if(chsman[row][col] == 0 && ((row == 0 && col == 0) || (row == 0 && col == 2) ||
(row == 2 && col == 0) || (row == 2 && col == 2))){
chsman[row][col] = P2;
dsply();
return;
}
}
}
}
void dsply(void)
{
int row, col, i;
for(i = 0; i < SIZE * 4 + 1; i++)
printf( "- ");
printf( "\n ");
for(row = 0; row < SIZE; row++){
printf( "| ");
for(col = 0; col < SIZE; col++){
if(chsman[row][col] == P1) printf( " o | ");
else if(chsman[row][col] == P2) printf( " x | ");
else printf( " | ");
}
printf( "\n ");
for(i = 0; i < SIZE * 4 + 1; i++)
printf( "- ");
printf( "\n ");
}
return;
}
int chkWin(void)
{
int i;
for(i = 0; i < SIZE; i++){
if(chsman[i][0] + chsman[i][1] + chsman[i][2] == -3 || chsman[0][i] + chsman[1][i] + chsman[2][i] == -3 ||
chsman[0][0] + chsman[1][1] + chsman[2][2] == -3 || chsman[0][2] + chsman[1][1] + chsman[2][0] == -3){
return WIN;
}
}
return UNWIN;
}
int chkPeace(void)
{
int row, col;
int sum = 0;
for(row = 0; row < SIZE; row++){
for(col = 0; col < SIZE; col++){
if(sum += chsman[row][col] == PEACE){
return PEACE;
}
}
}
return 0;
}
int main(char* args[])
{
dsply();
do{
input();
judge();
if(chkWin() == WIN) break;
if(stepFlg == 5 && chkPeace() == PEACE){
printf( "Peace! ");
return 0;
}
}while(1);
printf( "You Win! ");
return 0;
}
[解决办法]
修改后的代码
#include <stdio.h>
#define P1 1
#define P2 -1
#define SIZE 3
#define WIN -1
#define UNWIN 0
#define PEACE 1
int chsman[SIZE][SIZE] = {0};
int enterChsman(int, int);
void dsply(void);
void input(void);
void judge(void);
int chkWin(void);
int chkPeace(void);
int stepFlg = 0;
void chkAndPutDwnRow(int row,int col){
for(col = 0; col < SIZE; col++){
if(chsman[row][col] == 0){
chsman[row][col] = P2;
dsply();
return;
}
}
}
void chkAndPutDwnCol(int row,int col){
for(col = 0; col < SIZE; col++){
if(chsman[col][row] == 0){
chsman[col][row] = P2;
dsply();
return;
}
}
}
void chkAndPutDwn_Slsh(int row,int col){
if(chsman[row][col] == 0){
chsman[row][col] = P2;
dsply();
return;
}
}
int enterChsman(int row, int col)
{
if(row > = SIZE || col > = SIZE)
return 0;
if(chsman[row][col] != 0)
return 0;
chsman[row][col] = P1;
return 1;
}
void input(void)
{
int row, col;
do{
printf( "Please locate your chessman:\n ");
printf( "Location row: ");
scanf( "%d ", &row);
printf( "Location column: ");
scanf( "%d ", &col);
if(enterChsman(row - 1, col - 1) == 1){
printf( "You located chessman at [%d][%d].\n ", row, col);
dsply();
break;
}
else
printf( "Error : You put the chess to a wrong location\n ");
}while(1);
return;
}
void judge(void)
{
int row, col;
int i;
int rskAndAtkLevlRow[SIZE] = {0}, rskAndAtkLevlCol[SIZE] = {0}, rskAndAtkLevlSlsh[2] = {0};
if(stepFlg == 0){
stepFlg = 1;
if(chsman[1][1] == P1){
chsman[0][0] = P2;
printf( "The computer located chessman at [0][0].\n ");
dsply();
return;
}
else{
chsman[1][1] = P2;
printf( "The computer located chessman at [1][1].\n ");
dsply();
return;
}
}
stepFlg++;
for(row = 0; row < SIZE; row++){
for(col = 0; col < SIZE; col++){
rskAndAtkLevlRow[row] += chsman[row][col];
}
}
for(col = 0; col < SIZE; col++){
for(row = 0; row < SIZE; row++){
rskAndAtkLevlCol[col] += chsman[row][col];
}
}
rskAndAtkLevlSlsh[0] = chsman[0][0] + chsman[1][1] + chsman[2][2];
rskAndAtkLevlSlsh[1] = chsman[0][2] + chsman[1][1] + chsman[2][0];
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlRow[i] == -2){
chkAndPutDwnRow(i, col);
}
}
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlCol[i] == -2){
chkAndPutDwnCol(i, col);
}
}
if(rskAndAtkLevlSlsh[0] == -2){
for(row = 0, col = 0; row < SIZE; row++, col++){
chkAndPutDwn_Slsh(row, col);
}
}
if(rskAndAtkLevlSlsh[1] == -2){
for(row = 0, col = 2; row < SIZE; row++, col--){
chkAndPutDwn_Slsh(row, col);
}
}
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlRow[i] == 2){
chkAndPutDwnRow(i, col);
}
}
for(i = 0; i < SIZE; i++){
if(rskAndAtkLevlCol[i] == 2){
chkAndPutDwnCol(i, col);
}
}
if(rskAndAtkLevlSlsh[0] == 2){
for(row = 0, col = 0; row < SIZE; row++, col++){
chkAndPutDwn_Slsh(row, col);
}
}
if(rskAndAtkLevlSlsh[1] == 2){
for(row = 0, col = 2; row < SIZE; row++, col--){
chkAndPutDwn_Slsh(row, col);
}
}
for(row = 0; row < SIZE; row++){
for(col = 0; col < SIZE; col++){
if(chsman[row][col] == 0 && ((row == 0 && col == 0) || (row == 0 && col == 2) ||
(row == 2 && col == 0) || (row == 2 && col == 2))){
chsman[row][col] = P2;
dsply();
return;
}
}
}
}
void dsply(void)
{
int row, col, i;
for(i = 0; i < SIZE * 4 + 1; i++)
printf( "- ");
printf( "\n ");
for(row = 0; row < SIZE; row++){
printf( "| ");
for(col = 0; col < SIZE; col++){
if(chsman[row][col] == P1) printf( " o | ");
else if(chsman[row][col] == P2) printf( " x | ");
else printf( " | ");
}
printf( "\n ");
for(i = 0; i < SIZE * 4 + 1; i++)
printf( "- ");
printf( "\n ");
}
return;
}
int chkWin(void)
{
int i;
for(i = 0; i < SIZE; i++){
if(chsman[i][0] + chsman[i][1] + chsman[i][2] == -3 || chsman[0][i] + chsman[1][i] + chsman[2][i] == -3 ||
chsman[0][0] + chsman[1][1] + chsman[2][2] == -3 || chsman[0][2] + chsman[1][1] + chsman[2][0] == -3){
return WIN;
}
}
return UNWIN;
}
int chkPeace(void)
{
int row, col;
int sum = 0;
for(row = 0; row < SIZE; row++){
for(col = 0; col < SIZE; col++){
if(sum += chsman[row][col] == PEACE){
return PEACE;
}
}
}
return 0;
}
int main(char* args[])
{
dsply();
do{
input();
judge();
if(chkWin() == WIN) break;
if(stepFlg == 5 && chkPeace() == PEACE){
printf( "Peace! ");
return 0;
}
}while(1);
printf( "You Win! ");
return 0;
}