Open XiaoBaiBZS opened 10 months ago
啊这。。。QAQ
而且我不清楚如何正常打开源码编译不报错,我不清楚如何将那些.c文件连接在一起。
我是用gcc -o命令来链接的。其实可以全部粘贴到一起,就是有点麻烦。🥺
话说Bug长啥样,有截图吗帅哥
C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c In function 'add':
106 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
106 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
107 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
118 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
106 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
118 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
119 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
124 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
118 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
124 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
125 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'j'
119 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'j' was here
125 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
134 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
124 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
134 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
135 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'j'
125 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'j' was here
135 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c In function 'search':
150 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
151 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
153 5 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
154 6 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
161 8 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c In function 'ai':
229 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
231 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
229 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
231 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
236 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c In function 'checkchess':
247 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
261 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
247 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
261 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
262 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
266 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
261 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
266 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
267 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'j'
262 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'j' was here
267 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
271 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
266 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
271 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
272 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'j'
267 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'j' was here
272 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
276 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
271 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
276 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
277 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'j'
272 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'j' was here
277 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
281 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
276 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
281 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
282 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'j'
277 12 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'j' was here
282 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
283 4 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c In function 'print':
314 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
319 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
322 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
314 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
322 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
324 3 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
343 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] redefinition of 'i'
322 11 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Note] previous definition of 'i' was here
343 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c In function 'menu':
472 4 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
478 4 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] a label can only be part of a statement and a declaration is not a statement
481 5 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c In function 'save':
501 2 C:\Users\12985\Downloads\Gobang_C-dev\Gobang_C-dev\main.c [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
这个是整合粘贴到main.cpp里面编译运行的错误。如果直接执行您提供的exe文件则显示乱码(奇怪的中文汉字,类似’鈼‘)。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
typedef unsigned int _32bit;
void menu(_32bit *chessman);
int check(_32bit *chessman);
void icon(_32bit *chessman);
void save(_32bit *chessman);
int ai(_32bit *chessman);
#define DEPTH 2
#define AREA 2
typedef struct NODE {
int i, sup, inf, depth;
_32bit chessman[15];
struct NODE *parent, *sibling, *child;
} NODE;
int area(int a) {
if (a < 0) return 0;
else if (a > 14) return 14;
else return a;
}
int score(int a) {
switch (a) {
case 0x200:
case 0x80:
case 0x20:
case 0x8:
case 0x2:
return 1;
case 0x280:
case 0xA0:
case 0x28:
case 0xA:
case 0x202:
case 0x82:
case 0x22:
case 0x208:
case 0x88:
case 0x220:
return 10;
case 0xA8:
case 0x228:
case 0x288:
case 0x2A0:
case 0xA2:
case 0x222:
case 0x282:
case 0x8A:
case 0x20A:
case 0x2A:
return 100;
case 0xAA:
case 0x2A8:
case 0x2A2:
case 0x28A:
case 0x22A:
return 1000;
case 0x2AA:
return 10000;
case 0x100:
case 0x40:
case 0x10:
case 0x4:
case 0x1:
return -1;
case 0x5:
case 0x11:
case 0x41:
case 0x101:
case 0x104:
case 0x44:
case 0x14:
case 0x110:
case 0x50:
case 0x140:
return -10;
case 0x54:
return -200;
case 0x114:
case 0x144:
case 0x150:
case 0x51:
case 0x111:
case 0x141:
case 0x45:
case 0x105:
case 0x15:
return -100;
case 0x154:
case 0x55:
case 0x151:
case 0x145:
case 0x115:
return -1000;
case 0x155:
return -10000;
default :
return 0;
}
}
int add(NODE *node) {
int m = 0;
_32bit a = 0xC0000000, b = 0x3FF00000, s;
for (int i = 0; i < 11; i++) {
for (int j = 0; j < 15; j++) {
s = (((node->chessman[i + 0] & (a >> j * 2)) >> (30 - j * 2)) << 8)
+ (((node->chessman[i + 1] & (a >> j * 2)) >> (30 - j * 2)) << 6)
+ (((node->chessman[i + 2] & (a >> j * 2)) >> (30 - j * 2)) << 4)
+ (((node->chessman[i + 3] & (a >> j * 2)) >> (30 - j * 2)) << 2)
+ (((node->chessman[i + 4] & (a >> j * 2)) >> (30 - j * 2)) << 0);
m += score(s);
}
}
for (int i = 0; i < 15; i++)
for (int j = 0; j < 11; j++) {
s = ((node->chessman[i] & (b >> j * 2)) >> (20 - j * 2));
m += score(s);
}
for (int i = 0; i < 11; i++)
for (int j = 0; j < 11; j++) {
s = (((node->chessman[i + 0] & (a >> j * 2 + 0)) >> (30 - j * 2 - 0)) << 8)
+ (((node->chessman[i + 1] & (a >> j * 2 + 2)) >> (30 - j * 2 - 2)) << 6)
+ (((node->chessman[i + 2] & (a >> j * 2 + 4)) >> (30 - j * 2 - 4)) << 4)
+ (((node->chessman[i + 3] & (a >> j * 2 + 6)) >> (30 - j * 2 - 6)) << 2)
+ (((node->chessman[i + 4] & (a >> j * 2 + 8)) >> (30 - j * 2 - 8)) << 0);
m += score(s);
}
for (int i = 0; i < 11; i++)
for (int j = 0; j < 11; j++) {
s = (((node->chessman[i + 0] & (a >> j * 2 + 8)) >> (30 - j * 2 - 8)) << 8)
+ (((node->chessman[i + 1] & (a >> j * 2 + 6)) >> (30 - j * 2 - 6)) << 6)
+ (((node->chessman[i + 2] & (a >> j * 2 + 4)) >> (30 - j * 2 - 4)) << 4)
+ (((node->chessman[i + 3] & (a >> j * 2 + 2)) >> (30 - j * 2 - 2)) << 2)
+ (((node->chessman[i + 4] & (a >> j * 2 + 0)) >> (30 - j * 2 - 0)) << 0);
m += score(s);
}
return m;
}
void search(NODE *node) {
NODE *sibling = (NODE *)malloc(sizeof(NODE)), *head = sibling;
for (int i = 0; i < 15; i++)
for (int j = 0; j < 15; j++)
if (((node->chessman[i] & (0xC0000000 >> j * 2)) >> (30 - j * 2)) != 0)
for (int ii = area(i - AREA); ii <= area(i + AREA); ii++)
for (int jj = area(j - AREA); jj <= area(j + AREA); jj++)
if (((node->chessman[ii] & (0xC0000000 >> (jj * 2))) >> (30 - jj * 2)) == 0) {
sibling->sibling = (NODE *)malloc(sizeof(NODE));
sibling = sibling->sibling;
sibling->depth = node->depth + 1;
sibling->i = ii;
sibling->child = NULL;
for (int i = 0; i < 15; i++)
sibling->chessman[i] = node->chessman[i];
if (sibling->depth % 2 == 0)
sibling->chessman[ii] |= (0x40000000 >> (jj * 2));
else if (sibling->depth % 2 == 1)
sibling->chessman[ii] |= (0x80000000 >> (jj * 2));
}
sibling->sibling = NULL;
node->child = head->sibling;
free(head);
}
void nodes(NODE *node, int depth) {
if (node != NULL) {
if (node->depth == depth)
search(node);
nodes(node->sibling, depth);
nodes(node->child, depth);
}
}
void parent(NODE *node) {
if (node != NULL) {
if (node->child != NULL) node->child->parent = node;
if (node->sibling != NULL) node->sibling->parent = node->parent;
parent(node->child);
parent(node->sibling);
}
}
void evaluate(NODE *node) {
if (node != NULL) {
if (node->depth == DEPTH)
node->inf = node->sup = add(node);
evaluate(node->sibling);
evaluate(node->child);
}
}
void find(NODE *node) {
if (node != NULL) {
if (node->depth != DEPTH && node->depth != 0) {
node->inf = node->parent->inf;
node->sup = node->parent->sup;
}
find(node->child);
if (node->depth != 0) {
if (node->depth % 2 == 0 && node->inf < node->parent->sup)node->parent->sup = node->inf;
else if (node->depth % 2 == 1 && node->sup > node->parent->inf)node->parent->inf = node->sup;
if (node->parent->sup > node->parent->inf) find(node->sibling);
}
}
}
void free_tree(NODE *node) {
if (node != NULL) {
if (node->child != NULL) {
free_tree(node->child);
node->child = NULL;
}
if (node->sibling != NULL) {
free_tree(node->sibling);
node->sibling = NULL;
}
free(node);
}
}
int ai(_32bit *chessman) {
NODE *root = (NODE *)malloc(sizeof(NODE));
root->depth = 0;
root->parent = root->sibling = root->child = NULL;
root->inf = 0x80000000;
root->sup = 0x7fffffff;
for (int i = 0; i < 15; i++)
root->chessman[i] = chessman[i];
for (int i = 0; i < DEPTH; i++)
nodes(root, i);
parent(root);
evaluate(root);
find(root);
for (NODE *sibling = root->child; sibling != NULL; sibling = sibling->sibling)
if (sibling->sup == root->inf) {
chessman[sibling->i] = sibling->chessman[sibling->i];
break;
}
free_tree(root);
return -1;
}
int checkchess(_32bit *a, int c) {
char (*p)[16][16] = (char (*)[16][16])calloc(4, 16 * 16);
for (int i = 0; i < 16; i++) {
if (((a[0] & (0xC0000000 >> (i * 2))) >> (30 - i * 2)) == c) {
p[0][0][i] = 1;
p[2][0][i] = 1;
}
if (((a[i] & 0xC0000000) >> 30) == c) {
p[1][i][0] = 1;
p[2][i][0] = 1;
p[3][i][0] = 1;
}
if (((a[15] & (0xC0000000 >> (i * 2))) >> (30 - i * 2)) == c)
p[3][15][i] = 1;
}
for (int i = 1; i < 16; i++)
for (int j = 0; j < 16; j++)
if (((a[i] & (0xC0000000 >> (j * 2))) >> (30 - j * 2)) == c)
p[0][i][j] = p[0][i - 1][j] + 1;
for (int i = 0; i < 16; i++)
for (int j = 1; j < 16; j++)
if (((a[i] & (0xC0000000 >> (j * 2))) >> (30 - j * 2)) == c)
p[1][i][j] = p[1][i][j - 1] + 1;
for (int i = 1; i < 16; i++)
for (int j = 1; j < 16; j++)
if (((a[i] & (0xC0000000 >> (j * 2))) >> (30 - j * 2)) == c)
p[2][i][j] = p[2][i - 1][j - 1] + 1;
for (int i = 14; i >= 0; i--)
for (int j = 1; j < 16; j++)
if (((a[i] & (0xC0000000 >> (j * 2))) >> (30 - j * 2)) == c)
p[3][i][j] = p[3][i + 1][j - 1] + 1;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 16; j++)
for (int k = 0; k < 16; k++)
if (p[i][j][k] == 5) {
free(p);
return c;
}
free(p);
return 0;
}
int check(_32bit *chessman) {
if(checkchess(chessman, 1) == 1) {
printf("\n");
printf("| Winner: |\n");
printf("| |\n");
printf("| 鈼? |\n");
printf("| |\n");
printf("| |\n");
return 1;
} else if(checkchess(chessman, 2) == 2) {
printf("\n\n");
printf("| Winner: |\n");
printf("| |\n");
printf("| 鈼? |\n");
printf("| |\n");
printf("| |\n");
return 2;
}
return 0;
}
void print(_32bit *chessman, int a, int b, int k) {
_32bit *control = (_32bit *)calloc(15, 4);
for (int i = 0; i < 15; i++)
control[i] = chessman[i];
control[a] |= (0xC0000000 >> (b * 2));
system("cls");
printf("鈹屸攢");
for (int j = 0; j < 15; j++)
printf("鈹€鈹攢");
printf("鈹€鈹怽n");
for (int i = 0; i < 15; i++) {
printf("鈹溾攢");
for (int j = 0; j < 15; j++)
switch ((control[i] & (0xC0000000 >> (j * 2))) >> (30 - j * 2)) {
case 0:
printf("鈹€鈹尖攢");
break;
case 1:
printf("鈹€鈼?");
break;
case 2:
printf("鈹€鈼?");
break;
case 3:
printf("鈹€陇鈹€");
break;
}
printf("鈹€鈹n");
}
free(control);
printf("鈹斺攢");
for (int i = 0; i < 15; i++) printf("鈹€鈹粹攢");
printf("鈹€鈹榎n");
if (k == 1) printf("鈼?s turn\n");
else if (k == -1) printf("鈼?s turn\n");
}
void icon(_32bit *chessman) {
int ch, i = 7, j = 7, k = 1, a = 1;
while (1) {
A:
print(chessman, i, j, k);
if (check(chessman)) break;
if (k == -1 && a == 1) k *= ai(chessman);
while (1) {
ch = getch();
switch (ch) {
case 'w':
if (i == 0) i = 14;
else i--;
goto A;
case 'a':
if (j == 0) j = 14;
else j--;
goto A;
case 's':
if (i == 14) i = 0;
else i++;
goto A;
case 'd':
if (j == 14) j = 0;
else j++;
goto A;
case ' ':
if ((chessman[i] & (0xC0000000 >> (j * 2))) == 0) {
if (k == 1) chessman[i] |= (0x40000000 >> (j * 2));
else if (k == -1) chessman[i] |= (0x80000000 >> (j * 2));
k *= -1;
goto A;
} else break;
case '\x1b':
menu(chessman);
goto A;
case '`':
save(chessman);
break;
case 'i':
a *= -1;
break;
}
}
}
}
void menu(_32bit *chessman) {
printf("\033[?25l");
int i = 0, ch;
while (1) {
system("cls");
switch (i) {
case 0:
printf("| Gobang by BUGKNIFEDOGE |\n");
printf("| |\n");
printf("| \x1b[33mNew Game\x1b[0m |\n");
printf("| Continue |\n");
printf("| Load Game |\n");
printf("| Save Game |\n");
printf("| Exit |\n");
printf("| |\n");
break;
case 1:
printf("| Gobang by BUGKNIFEDOGE |\n");
printf("| |\n");
printf("| New Game |\n");
printf("| \x1b[33mContinue\x1b[0m |\n");
printf("| Load Game |\n");
printf("| Save Game |\n");
printf("| Exit |\n");
printf("| |\n");
break;
case 2:
printf("| Gobang by BUGKNIFEDOGE |\n");
printf("| |\n");
printf("| New Game |\n");
printf("| Continue |\n");
printf("| \x1b[33mLoad Game\x1b[0m |\n");
printf("| Save Game |\n");
printf("| Exit |\n");
printf("| |\n");
break;
case 3:
printf("| Gobang by BUGKNIFEDOGE |\n");
printf("| |\n");
printf("| New Game |\n");
printf("| Continue |\n");
printf("| Load Game |\n");
printf("| \x1b[33mSave Game\x1b[0m |\n");
printf("| Exit |\n");
printf("| |\n");
break;
case 4:
printf("| Gobang by BUGKNIFEDOGE |\n");
printf("| |\n");
printf("| New Game |\n");
printf("| Continue |\n");
printf("| Load Game |\n");
printf("| Save Game |\n");
printf("| \x1b[33mExit\x1b[0m |\n");
printf("| |\n");
break;
}
B:
ch = getch();
switch (ch) {
case 'w':
if (i == 0) i = 4;
else i--;
break;
case 's':
if (i == 4) i = 0;
else i++;
break;
case ' ':
goto A;
}
}
A:
switch (i) {
case 0:
for (int j = 0; j < 16; j++)
chessman[j] = 0;
break;
case 1:
break;
case 2:
FILE *fp = NULL;
if (fopen(".data.txt", "r") != NULL) {
fp = fopen(".data.txt", "r");
for (int j = 0; j < 16; j++)
fscanf(fp, "%x\n", chessman + j);
fclose(fp);
break;
} else {
printf("file don't exist!\n");
goto B;
}
case 3:
save(chessman);
break;
case 4:
free(chessman);
exit(0);
}
}
void save(_32bit *chessman) {
FILE *fp = NULL;
fp = fopen(".data.txt", "w");
for (int i = 0; i < 16; i++)
fprintf(fp, "%x\n", chessman[i]);
fclose(fp);
}
int main() {
_32bit *chessman = (_32bit *)calloc(16, 4);
do {
menu(chessman);
icon(chessman);
printf("\n>>> press any key...");
getch();
} while (1);
return 0;
}
这是我整合后的。
可能是因为我使用的是utf-8字符,感谢帅哥提醒。 话说上面的报错中是不是出现了C语言版本问题?
不清楚,懒得搜懒得改了,我大抵是。😖
话说这个程序可以在杨晨电脑上正常运行。。。
制表符和棋子无法在Windows系统下正常显示