From 7a15f24cb4d2ddc92a918721cd8fe7e4db0bc68b Mon Sep 17 00:00:00 2001 From: Tomoyi <1784954041@qq.com> Date: Wed, 27 Mar 2019 19:34:47 +0800 Subject: [PATCH 1/6] maze.c --- maze.cpp | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 maze.cpp diff --git a/maze.cpp b/maze.cpp new file mode 100644 index 00000000..a69249b3 --- /dev/null +++ b/maze.cpp @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#define Height 25 +#define Width 25 +#define Wall 1 +#define Road 0 +#define Start 2 +#define End 3 +#define Up 1 +#define Down 2 +#define Left 3 +#define Right 4 +int map[Height+2][Width+2]; +void gotoxy(int x,int y) //移动坐标函数 +{ + COORD coord; + coord.X=x; + coord.Y=y; + SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord ); +} +void hidden() //隐藏光标函数 +{ + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); + CONSOLE_CURSOR_INFO cci; + GetConsoleCursorInfo(hOut,&cci); + cci.bVisible=0; + SetConsoleCursorInfo(hOut,&cci); +} +void create(int x,int y) //生成随机迷宫 +{ + int c[4][2]={0,1,1,0,0,-1,-1,0}; + int i,j,t; + for(i=0;i<4;i++){ + j=rand()%4; + t=c[i][0];c[i][0]=c[j][0];c[j][0]=t; + t=c[i][1];c[i][1]=c[j][1];c[j][1]=t; + } + map[x][y]=Road; + for(i=0;i<4;i++){ + if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall){ + map[x+c[i][0]][y+c[i][1]]=Road; + create(x+2*c[i][0],y+2*c[i][1]); + } + } +} +int get_key() //接受按键 +{ + char c; + while(c=getch()) + { + if(c!=-32)continue; + c=getch(); + if(c==72) return Up; + if(c==80) return Down; + if(c==75) return Left; + if(c==77) return Right; + } + return 0; +} +void paint(int x,int y) //打印迷宫 +{ + gotoxy(2*y-2,x-1); + switch(map[x][y]) + { + case Start: + printf("入");break; + case End: + printf("出");break; + case Wall: + printf("▇");break; + case Road: + printf(" ");break; + } +} +void game() //移动 +{ + int x=2,y=1; + int c; + while(1) + { + gotoxy(2*y-2,x-1); + printf("●"); + if(map[x][y]==End) + { + gotoxy(50,26); + printf("到达终点,按任意键结束"); + getch(); + break; + } + c=get_key(); + switch(c) + { + case Up: + if(map[x-1][y]!=Wall) + { + paint(x,y); + x--; + } + break; + case Down: + if(map[x+1][y]!=Wall) + { + paint(x,y); + x++; + } + break; + case Left: + if(map[x][y-1]!=Wall) + { + paint(x,y); + y--; + } + break; + case Right: + if(map[x][y+1]!=Wall) + { + paint(x,y); + y++; + } + break; + } + } +} +int main() +{ + int i,j; + srand((unsigned)time(NULL)); + hidden(); + for(i=0;i<=Height+1;i++) + for(j=0;j<=Width+1;j++) + if(i==0||i==Height+1||j==0||j==Width+1) + map[i][j]=Road; + else map[i][j]=Wall; + + create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); + for(i=0;i<=Height+1;i++) + { + map[i][0]=Wall; + map[i][Width+1]=Wall; + } + + for(j=0;j<=Width+1;j++) + { + map[0][j]=Wall; + map[Height+1][j]=Wall; + } + map[2][1]=Start; + map[Height-1][Width]=End; + for(i=1;i<=Height;i++) + for(j=1;j<=Width;j++) + paint(i,j); + game(); + getch(); + return 0; +} From 022895a3f36dd8035fc4eaa24d4a32d632da601e Mon Sep 17 00:00:00 2001 From: Tomoyi <1784954041@qq.com> Date: Wed, 27 Mar 2019 20:40:44 +0800 Subject: [PATCH 2/6] next --- hanoi.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 hanoi.cpp diff --git a/hanoi.cpp b/hanoi.cpp new file mode 100644 index 00000000..80e0b269 --- /dev/null +++ b/hanoi.cpp @@ -0,0 +1,26 @@ +#include + +void move(int n,char A,char B,char C) +{ + if(n==1){ + printf("move %d from %c to %c\n",n,A,C); + }else{ + move(n-1,A,C,B); + printf("move %d from %c to %c\n",n,A,C); + move(n-1,B,A,C); + } +} +void hanoi(int n,char A,char B,char C) +{ + if(n<=0){ + return ; + } + move(n,A,B,C); +} +int main() +{ + int n; + scanf("%d",&n); + hanoi(n,'A','B','C'); + return n; +} From d835a38c00d1252b230fdf7549c5f6677cede818 Mon Sep 17 00:00:00 2001 From: Tomoyi <1784954041@qq.com> Date: Tue, 11 Jun 2019 20:27:00 +0800 Subject: [PATCH 3/6] pushboxes.cpp --- pushboxes.cpp | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 pushboxes.cpp diff --git a/pushboxes.cpp b/pushboxes.cpp new file mode 100644 index 00000000..ad75d828 --- /dev/null +++ b/pushboxes.cpp @@ -0,0 +1,215 @@ +#include +#include +#include + +int map[9][11]; +void fscan() +{ + FILE* fp=fopen("file.txt","r"); + if(fp==NULL) + { + printf("无文件"); + return ; + } + for(int i=0;i<9;i++) + { + for(int j=0;j<11;j++) + { + fscanf(fp,"%d",&map[i][j]); + } + } + fclose(fp); +} + +void fprint(int score) +{ + FILE* fp=fopen("score1.txt","w"); + if(fp==NULL){ + printf("打开文件失败."); + return; + } + fprintf(fp,"本关分数为: "); + fprintf(fp,"%d\n",score); + fclose(fp); +} + +void DrawMap() +{ + for (int i = 0; i < 9; i++) + { + for (int j = 0; j < 11; j++) + { + switch (map[i][j]) + { + case 0: + printf(" "); + break; + case 1: + printf("■"); + break; + case 3: + printf("☆"); + break; + case 4: + printf("□"); + break; + case 5: + printf("♀"); + break; + case 7: + printf("★"); + break; + case 8: + printf("♀"); + break; + } + } + printf("\n"); + } +} + + +void PlayGame() +{ + int r, c; + for (int i = 0; i < 9; i++) + { + for (int j = 0; j < 11; j++) + { + if (map[i][j] == 5||map[i][j]==8) + { + r = i; + c = j; + } + } + } + + char ch; + ch = getch(); + switch (ch) + { + case 'W': + case 'w': + case 72: + if (map[r - 1][c] == 0|| map[r - 1][c] == 3) + { + map[r - 1][c] += 5; + map[r][c] -= 5; + } + else if (map[r - 1][c] == 4 || map[r - 1][c] == 7) + { + if (map[r - 2][c] == 0 || map[r - 2][c] == 3) + { + map[r - 2][c] += 4; + map[r - 1][c] += 1; + map[r][c] -= 5; + } + } + + + + break; + + case 'S': + case 's': + case 80: + if (map[r + 1][c] == 0 || map[r + 1][c] == 3) + { + map[r + 1][c] += 5; + map[r][c] -= 5; + } + else if (map[r + 1][c] == 4 || map[r+ 1][c] == 7) + { + if (map[r + 2][c] == 0 || map[r + 2][c] == 3) + { + map[r + 2][c] += 4; + map[r + 1][c] += 1; + map[r][c] -= 5; + } + } + break; + + case 'A': + case 'a': + case 75: + if (map[r ][c - 1] == 0 || map[r ][c - 1] == 3) + { + map[r ][c - 1] += 5; + map[r][c] -= 5; + } + else if (map[r][c - 1] == 4 || map[r][c - 1] == 7) + { + if (map[r ][c - 2] == 0 || map[r ][c - 2] == 3) + { + map[r ][c - 2] += 4; + map[r ][c - 1] += 1; + map[r][c] -= 5; + } + } + break; + + case 'D': + case 'd': + case 77: + if (map[r][c + 1] == 0 || map[r][c + 1] == 3) + { + map[r][c + 1] += 5; + map[r][c] -= 5; + } + else if (map[r][c + 1] == 4 || map[r][c + 1] == 7) + { + if (map[r][c + 2] == 0 || map[r][c + 2] == 3) + { + map[r][c + 2] += 4; + map[r][c + 1] += 1; + map[r][c] -= 5; + } + } + break; + } +} + +int jug() +{ + int flag=0; + for(int q=0;q<9;q++){ + for(int w=0;w<11;w++){ + if(map[q][w]==4){ + flag++; + } + } + } + return flag; +} + +int main() +{ + int step=0,score=0; + fscan(); + while (1) + { + system("cls"); + DrawMap(); + if(jug()==0){ + printf("恭喜过关!"); + step/=2; + if(step<=15){ + score=5; + }else if(step>15&&step<=20){ + score=4; + }else if(step>20&&step<=25){ + score=3; + }else if(step>25&&step<=30){ + score=2; + }else if(step>30){ + score=1; + } + fprint(score); + break; + } + PlayGame(); + step++; + } + return 0; +} + From 942b63d4b67613f0396c91b5b832487c0ed15720 Mon Sep 17 00:00:00 2001 From: Tomoyi <1784954041@qq.com> Date: Tue, 11 Jun 2019 20:38:33 +0800 Subject: [PATCH 4/6] warehouse.cpp --- warehouse.cpp | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 warehouse.cpp diff --git a/warehouse.cpp b/warehouse.cpp new file mode 100644 index 00000000..1660ffbd --- /dev/null +++ b/warehouse.cpp @@ -0,0 +1,155 @@ +#include +#include +#include + +struct a { + char name[10]; + int count; +}; +struct a product[1000]; +int num = 0; + +void read() +{ + FILE* fp = fopen("product.txt", "r"); + if (fp == NULL) { + printf("不能打开文件!\n"); + return; + } + int i = 0; + while (!feof(fp)) { + fscanf(fp, "%s %d", product[i].name, &product[i].count); + i++; + } + num = i-1; + fclose(fp); +} + +void save() +{ + FILE* fp = fopen("product.txt", "w"); + if (fp == NULL) { + printf("不能打开文件!\n"); + return; + } + for (int i = 0; i < num; i++) { + fprintf(fp, "%s %d\n", product[i].name, product[i].count); + } + printf("\n操作已保存!\n"); + fclose(fp); +} + +void input() +{ + char t[10]; + int tnum,i; + printf("请输入存入货物的型号:"); + scanf("%s", t); + for (i = 0; i < num; i++) { + if (strcmp(product[i].name, t) == 0) { + printf("请输入商品数量:"); + scanf("%d", &tnum); + product[i].count = product[i].count + tnum; + printf("\n该商品的入库量:%d", tnum); + printf("\n入库后该商品的总量:%d", product[i].count); + save(); + break; + } + } + if (i == num) { + strcpy(product[num].name, t); + printf("\n请输入商品数量:"); + scanf("%d", &tnum); + product[num].count = tnum; + printf("\n该商品的入库量:%d", tnum); + printf("\n入库后该商品的总量:%d", tnum); + num++; + save(); + } + printf("\n是否还想继续入库商品?"); + printf("\n按y继续添加,按n不添加:"); + char choice; + scanf("\n%c", &choice); + if (choice == 'y') { + input(); + } +} + +void output() +{ + char str[10]; + int i,tnum; + printf("\n请输入想要出库商品的型号:"); + scanf("%s", str); + for (i = 0; i < num; i++) { + if (strcmp(product[i].name, str) == 0) { + printf("\n请输入出库商品的数量:"); + scanf("%d", &tnum); + printf("\n该商品原库存量为:%d", product[i].count); + if (tnum <= product[i].count) { + printf("\n出库后该商品的剩余库存量为:%d", product[i].count - tnum); + product[i].count -= tnum; + save(); + } + else { + printf("\n库存量不足!"); + break; + } + } + } + if (i == num) { + printf("\n没有该商品!"); + } + printf("\n是否还想继续出库商品?"); + printf("\n按y继续出库,按n不继续出库:"); + char choice; + scanf("\n%c", &choice); + if (choice == 'y') { + output(); + } +} + +void show() +{ + int i; + for (i = 0; i < num; i++) { + printf("商品型号:%s 数量:%d\n", product[i].name, product[i].count); + } +} + +void menu() +{ + printf("菜单功能如下:\n"); + printf(" 1.显示存货列表.\n"); + printf(" 2.入库.\n"); + printf(" 3.出库.\n"); + printf(" 4.退出程序.\n"); + printf("请选择你想进行的操作(按对应数字键):"); +} +int main() +{ + read(); + menu(); + int c; + scanf("%d", &c); + while (c != 4) { + switch (c) { + case 1: + show(); + break; + case 2: + input(); + break; + case 3: + output(); + break; + default: + break; + } + printf("\n\n"); + menu(); + scanf("%d", &c); + } + printf("数据已保存,退出程序成功!\n"); + return 0; +} \ No newline at end of file From c044fa1c8c2b89ad043dce0ff229231bb97776ee Mon Sep 17 00:00:00 2001 From: Tomoyi <1784954041@qq.com> Date: Tue, 11 Jun 2019 20:54:43 +0800 Subject: [PATCH 5/6] linkedList.cpp --- linkedList.cpp | 130 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 linkedList.cpp diff --git a/linkedList.cpp b/linkedList.cpp new file mode 100644 index 00000000..b6e5b899 --- /dev/null +++ b/linkedList.cpp @@ -0,0 +1,130 @@ +#include +#include + +typedef struct node { //定义链表 + int data; + struct node* next; +}NODE; + +NODE* create(int n) //创建链表 +{ + NODE* head, * node, * end,* info; + head = (NODE*)malloc(sizeof(NODE)); + end = head; + info = (NODE*)malloc(sizeof(NODE)); + info->data = n; + end->next = info; + end = info; + for (int i = 0; i < n; i++) { + node = (NODE*)malloc(sizeof(NODE)); + scanf("%d", &node->data); + end->next = node; + end = node; + } + end->next = NULL; + return head; +} + +void change(NODE* list, int pos, int n) //改变节点的值 +{ + NODE* t = list->next; + for (int i = 0; i < pos; i++) { + t = t->next; + if (t == NULL) { + puts("无效节点."); + return; + } + } + t->data = n; +} + +void delet(NODE* list, int pos) //删除节点 +{ + NODE* t = list->next; + for (int i = 1; i < pos; i++) { + t = t->next; + if (t->next == NULL) { + puts("该节点不存在."); + return; + } + } + list->next->data = list->next->data - 1; + NODE* p = t->next; + t->next = t->next->next; + free(p); +} + +void insert(NODE* list, int pos, int n) //插入节点 +{ + NODE* t = list->next; + for (int i = 1; i < pos; i++) { + t = t->next; + if (t == NULL) { + puts("无效节点."); + return; + } + } + NODE* p = (NODE*)malloc(sizeof(NODE)); + p->data = n; + p->next = t->next; + t->next = p; + list->next->data = list->next->data + 1; +} + +int find(NODE* list, int numth, int n) //查找特定值 +{ + int ct = 1; + NODE* t = list->next; + int i = 1; + while (t->next != NULL) { + t = t->next; + if (t->data == n) { + if (ct == numth) { + printf("%d\n", i); + return; + } + else { + ct++; + } + } + i++; + } + printf("未找到该值.\n"); +} + +void traversal(NODE* list) //遍历链表 +{ + NODE* t = list->next; + printf("链表长度为:%d\n", t->data); + while (t->next != NULL) { + t = t->next; + printf("%d ", t->data); + } +} + +void reversal(NODE* list) //链表反序 +{ + NODE* L, * cur, * p; + L = list->next; + if (L == NULL || L->next == NULL) { + return NULL; + } + cur = L->next; + while (cur->next != NULL) { + p = cur->next; + cur->next = p->next; + p->next = L->next; + L->next = p; + } + return list; +} + +int main() +{ + NODE* list = create(3); + traversal(list); + reversal(list); + find(list, 1, 5); + find(list, 2, 5); + return 0; +} From e5570683036ebe5a3050ac511f6dc52ecf2be99f Mon Sep 17 00:00:00 2001 From: Tomoyi <1784954041@qq.com> Date: Fri, 21 Jun 2019 22:59:58 +0800 Subject: [PATCH 6/6] fivechess.c --- fivechess.c | 621 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 621 insertions(+) create mode 100644 fivechess.c diff --git a/fivechess.c b/fivechess.c new file mode 100644 index 00000000..80e5ed0e --- /dev/null +++ b/fivechess.c @@ -0,0 +1,621 @@ +#include +#include +#include +#include +#include +#define H 26 +#define up 'w' +#define down 's' +#define left 'a' +#define right 'd' +#define ok 'j' +int x, y, nextx, nexty, wint, turn, now, you, maxm = 0, maxy = 0, maxmcoordx = 0, maxmcoordy = 0, maxycoordx = 0, maxycoordy = 0, map[H][H]; +void init_map_array() +{ + system("cls"); + int i, j; + for (i = 0; i < H; i++) + for (j = 0; j < H; j++) + map[i][j] = 9; + x = H / 2, y = H / 2; + for (i = 4; i < H - 4; i++) + for (j = 4; j < H - 4; j++) + map[i][j] = 4; + map[x][y] = 3; +} +void drawMap() +{ + int i, j; + for (i = 4; i < H - 4; i++) + { + for (j = 4; j < H - 4; j++) + { + if (map[i][j] == 4) + { + if (i==4&&j==4) printf("\t┏"); + else if (i == 4 && j == H - 5) printf("┓"); + else if (i == H - 5 && j == 4) printf("\t┗"); + else if (i == H - 5 && j == H - 5) printf("┛"); + else + { + switch (j) + { + case H - 5:printf("┫"); break; + case 4:printf("\t┣"); break; + default: + switch (i) + { + case 4:printf("┳"); break; + case H - 5:printf("┻"); break; + default:printf("╋"); break; + } + break; + } + } + } + if (map[i][j] == 1) + printf("●"); + if (map[i][j] == 0) + printf("○"); + if (map[i][j] == 3) + printf("Ⅹ"); + } + printf("\n"); + } + printf("══════════════════════════\n"); +} +void swap() +{ + int temp; + temp = map[nextx][nexty]; + map[nextx][nexty] = map[x][y]; + map[x][y] = temp; + x = nextx, y = nexty; +} +void playchoice() +{ + void AI(); + int t = 0; + char i; +try_again: + while (!kbhit()) + { + i = getch(); + if (i == up || i == down || i == left || i == right || i == ok) + break; + } + while (kbhit()) + { + i = getch(); + } + + + switch (i) + { + case left: + nextx = x; + if (y == 4) + goto try_again; + else + nexty = y - 1; + if (map[x][y] == 1 || map[x][y] == 0) + { + if (!(map[nextx][nexty] == 1 || map[nextx][nexty] == 0)) + map[nextx][nexty] = 3; + x = nextx, y = nexty; + break; + } + if (map[nextx][nexty] == 1 || map[nextx][nexty] == 0) + { + map[x][y] = 4; + x = nextx, y = nexty; + break; + } + swap(); break; + case right: + nextx = x; + if (y == H - 5) + goto try_again; + else + nexty = y + 1; + if (map[x][y] == 1 || map[x][y] == 0) + { + if (map[nextx][nexty] == 1 || map[nextx][nexty] == 0) + ; + else + map[nextx][nexty] = 3; + x = nextx, y = nexty; + break; + } + if (map[nextx][nexty] == 1 || map[nextx][nexty] == 0) + { + map[x][y] = 4; + x = nextx, y = nexty; + break; + } + swap(); break; + case up: + if (x == 4) + goto try_again; + else + nextx = x - 1; + nexty = y; + if (map[x][y] == 1 || map[x][y] == 0) + { + if (map[nextx][nexty] == 1 || map[nextx][nexty] == 0) + ; + else + map[nextx][nexty] = 3; + x = nextx, y = nexty; + break; + } + if (map[nextx][nexty] == 1 || map[nextx][nexty] == 0) + { + map[x][y] = 4; + x = nextx, y = nexty; + break; + } + swap(); break; + case down: + if (x == H - 5) + goto try_again; + else + nextx = x + 1; + nexty = y; + if (map[x][y] == 1 || map[x][y] == 0) + { + if (map[nextx][nexty] == 1 || map[nextx][nexty] == 0) + ; + else + map[nextx][nexty] = 3; + x = nextx, y = nexty; + break; + } + if (map[nextx][nexty] == 1 || map[nextx][nexty] == 0) + { + map[x][y] = 4; + x = nextx, y = nexty; + break; + } + swap(); + break; + case ok: + if (map[x][y] == 0 || map[x][y] == 1) + goto try_again; + else + { + map[x][y] = 1; + system("cls"); + drawMap(); + //Sleep(800); + AI(); + system("cls"); + drawMap(); + return; + } + break; + default:break; + } + system("cls"); + drawMap(); +} +int iswin() +{ + int i, j, time = 1, xi, yi; + for (i = 4; i < H - 4; i++) + for (j = 4; j < H - 4; j++) + { + if (map[i][j] == 1 || map[i][j] == 0) + { + if (map[i][j] == 0) + wint = 0; + else + wint = 1; + xi = i, yi = j; + while (yi < H - 4 && yi>3) + { + yi++; + if (map[xi][yi] == wint) + { + time++; + if (time == 5) + return 0; + } + else break; + } + time = 1; + xi = i, yi = j; + while (xi < H - 4 && xi>3) + { + yi--; + if (map[xi][yi] == wint) + { + time++; + if (time == 5) + return 0; + } + else break; + } + time = 1; + xi = i, yi = j; + while (xi < H - 4 && xi>3) + { + xi++; + if (map[xi][yi] == wint) + { + time++; + if (time == 5) + return 0; + } + else break; + } + time = 1; + xi = i, yi = j; + while (xi < H - 4 && xi>3) + { + xi--; + if (map[xi][yi] == wint) + { + time++; + if (time == 5) + return 0; + } + else break; + } + time = 1; + xi = i, yi = j; + while (xi < H - 4 && xi>3 && yi < H - 4 && yi>3) + { + xi++, yi++; + if (map[xi][yi] == wint) + { + time++; + if (time == 5) + return 0; + } + else break; + } + time = 1; + xi = i, yi = j; + while (xi < H - 4 && xi>3 && yi < H - 4 && yi>3) + { + xi++, yi--; + if (map[xi][yi] == wint) + { + time++; + if (time == 5) + return 0; + } + else break; + } + time = 1; + xi = i, yi = j; + while (xi < H - 4 && xi>3 && yi < H - 4 && yi>3) + { + xi--, yi--; + if (map[xi][yi] == wint) + { + time++; + if (time == 5) + return 0; + } + else break; + } + time = 1; + xi = i, yi = j; + while (xi < H - 4 && xi>3 && yi < H - 4 && yi>3) + { + xi--, yi++; + if (map[xi][yi] == wint) + { + time++; + if (time == 5) + return 0; + } + else break; + } + time = 1; + } + } + return 1; +} +void Evaluate() +{ + int i, j, score = 0, coord[H * H][2] = { 0 }, max = 0, t = 0; + for (i = 4; i < H - 4; i++) + { + for (j = 4; j < H - 4; j++) + { + if (map[i][j] == 4) + { + if (map[i + 1][j] == now || map[i][j + 1] == now || map[i + 1][j + 1] == now || map[i - 1][j + 1] == now || map[i + 1][j - 1] == now || map[i - 1][j - 1] == now || map[i][j - 1] == now || map[i - 1][j] == now) //这里八个方向遍历 + { + //右活一 + if (map[i][j + 1] == now && map[i][j + 2] == 4) + score += 20; + //右死一 + if (map[i][j + 1] == now && map[i][j + 2] == 9 || map[i][j + 1] == now && map[i][j + 2] == you) + score += 4; + //右活二 + if (map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == 4) + score += 400; + //右死二 + if (map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == 9 || map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == you) + score += 90; + //右活三 + if (map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == now && map[i][j + 4] == 4) + score += 6000; + //右死三 + if (map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == now && map[i][j + 4] == you || map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == now && map[i][j + 4] == 9) + score += 800; + //右活四 + if (map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == now && map[i][j + 4] == now && map[i][j + 5] == 4) + score += 20000; + //右死四 + if (map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == now && map[i][j + 4] == now && map[i][j + 5] == you || map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == now && map[i][j + 4] == now && map[i][j + 5] == 9) + score += 10000; + //左活一 + if (map[i][j - 1] == now && map[i][j - 2] == 4) + score += 20; + //左死一 + if (map[i][j - 1] == now && map[i][j - 2] == you || map[i][j - 1] == 0 && map[i][j - 2] == 9) + score += 4; + //左活二 + if (map[i][j - 1] == now && map[i][j - 2] == now && map[i][j - 3] == 4) + score += 400; + //左死二 + if (map[i][j - 1] == now && map[i][j - 2] == now && map[i][j - 3] == you || map[i][j - 1] == now && map[i][j - 2] == now && map[i][j - 3] == 9) + score += 90; + //左活三 + if (map[i][j - 1] == you && map[i][j - 2] == you && map[i][j - 3] == you && map[i][j - 4] == 4) + score += 6000; + //左死三 + if (map[i][j - 1] == 0 && map[i][j - 2] == 0 && map[i][j - 3] == 0 && map[i][j - 4] == you || map[i][j - 1] == 0 && &map[i][j - 2] == 0 && map[i][j - 3] == 0 && map[i][j - 4] == 9) + score += 800; + //左活四 + if (map[i][j - 1] == now && map[i][j - 2] == now && map[i][j - 3] == now && map[i][j - 4] == now && map[i][j - 5] == 4) + score += 20000; + //左死四 + if (map[i][j - 1] == now && map[i][j - 2] == now && map[i][j - 3] == now && map[i][j - 4] == now && map[i][j - 5] == you || map[i][j - 1] == now && map[i][j - 2] == now && map[i][j - 3] == now && map[i][j - 4] == now && map[i][j - 5] == 9) + score += 10000; + //下活一 + if (map[i + 1][j] == now && map[i + 2][j] == 4) + score += 20; + //下死一 + if (map[i + 1][j] == now && map[i + 2][j] == you || map[i + 1][j] == now && map[i + 2][j] == 9) + score += 4; + //下活二 + if (map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == 4) + score += 400; + //下死二 + if (map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == 9 || map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == you) + score += 90; + //下活三 + if (map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == now && map[i + 4][j] == 4) + score += 6000; + //下死三 + if (map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == now && map[i + 4][j] == you || map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == now && map[i + 4][j] == 9) + score += 800; + //下活四 + if (map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == now && map[i + 4][j] == now && map[i + 5][j] == 4) + score += 20000; + //下死四 + if (map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == now && map[i + 4][j] == now && map[i + 5][j] == you || map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == now && map[i + 4][j] == now && map[i + 5][j] == 9) + score += 10000; + //上活一 + if (map[i - 1][j] == now && map[i - 2][j] == 4) + score += 20; + //上死一 + if (map[i - 1][j] == now && map[i - 2][j] == you || map[i - 1][j] == now && map[i - 2][j] == 9) + score += 4; + //上活二 + if (map[i - 1][j] == now && map[i - 2][j] == now && map[i][j - 3] == 4) + score += 400; + //上死二 + if (map[i - 1][j] == now && map[i - 2][j] == now && map[i - 3][j] == 9 || map[i - 1][j] == now && map[i - 2][j] == now && map[i - 3][j] == you) + score += 90; + //上活三 + if (map[i - 1][j] == now && map[i - 2][j] == now && map[i - 3][j] == now && map[i - 4][j] == 4) + score += 6000; + //上死三 + if (map[i - 1][j] == now && map[i - 2][j] == now && map[i - 3][j] == now && map[i - 4][j] == you || map[i - 1][j] == now && map[i - 2][j] == now && map[i - 3][j] == now && map[i - 4][j] == 9) + score += 800; + //上活四 + if (map[i - 1][j] == now && map[i - 2][j] == now && map[i - 3][j] == now && map[i - 4][j] == now && map[i - 5][j] == 4) + score += 20000; + //上死四 + if (map[i - 1][j] == now && map[i - 2][j] == now && map[i - 3][j] == now && map[i - 4][j] == now && map[i - 5][j] == you || map[i - 1][j] == now && map[i - 2][j] == now && map[i - 3][j] == now && map[i - 4][j] == now && map[i - 5][j] == 9) + score += 10000; + //右下活一 + if (map[i + 1][j + 1] == now && map[i + 2][j + 2] == 4) + score += 20; + //右下死一 + if (map[i + 1][j + 1] == now && map[i + 2][j + 2] == 9 || map[i + 1][j + 1] == now && map[i + 2][j + 2] == you) + score += 4; + //右下活二 + if (map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == 4) + score += 400; + //右下死二 + if (map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == 9 || map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == you) + score += 90; + //右下活三 + if (map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == now && map[i + 4][j + 4] == 4) + score += 6000; + //右下死三 + if (map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == now && map[i + 4][j + 4] == you || map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == now && map[i + 4][j + 4] == 9) + score += 800; + //右下活四 + if (map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == now && map[i + 4][j + 4] == now && map[i + 5][j + 5] == 4) + score += 20000; + //右下死四 + if (map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == now && map[i + 4][j + 4] == now && map[i + 5][j + 5] == you || map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == now && map[i + 4][j + 4] == now && map[i + 5][j + 5] == 9) + score += 10000; + //左上活一 + if (map[i - 1][j - 1] == now && map[i - 2][j - 2] == 4) + score += 20; + //左上死一 + if (map[i - 1][j - 1] == now && map[i - 2][j - 2] == 9 || map[i - 1][j - 1] == now && map[i - 2][j - 2] == you) + score += 4; + //左上活二 + if (map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == 4) + score += 400; + //左上死二 + if (map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == 9 || map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == you) + score += 90; + //左上活三 + if (map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == now && map[i - 4][j - 4] == 4) + score += 6000; + //左上死三 + if (map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == now && map[i - 4][j - 4] == you || map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == now && map[i - 4][j - 4] == 9) + score += 800; + //左上活四 + if (map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == now && map[i - 4][j - 4] == now && map[i - 5][j - 5] == 4) + score += 20000; + //左上死四 + if (map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == now && map[i - 4][j - 4] == now && map[i - 5][j - 5] == you || map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == now && map[i - 4][j - 4] == now && map[i - 5][j - 5] == 9) + score += 10000; + //左下活一 + if (map[i + 1][j - 1] == now && map[i + 2][j - 2] == 4) + score += 20; + //左下死一 + if (map[i + 1][j - 1] == now && map[i + 2][j - 2] == you || map[i + 1][j - 1] == now && map[i + 2][j - 2] == 9) + score += 4; + //左下活二 + if (map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == 4) + score += 400; + //左下死二 + if (map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == 9 || map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == you) + score += 90; + //左下活三 + if (map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == now && map[i + 4][j - 4] == 4) + score += 6000; + //左下死三 + if (map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == now && map[i + 4][j - 4] == you || map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == now && map[i + 4][j - 4] == 9) + score += 800; + //左下活四 + if (map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == now && map[i + 4][j - 4] == now && map[i + 5][j - 5] == 4) + score += 20000; + //左下死四 + if (map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == now && map[i + 4][j - 4] == now && map[i + 5][j - 5] == you || map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == now && map[i + 4][j - 4] == now && map[i + 5][j - 5] == 9) + score += 10000; + //右上活一 + if (map[i - 1][j + 1] == now && map[i - 2][j + 2] == 4) + score += 20; + //右上死一 + if (map[i - 1][j + 1] == now && map[i - 2][j + 2] == you || map[i - 1][j + 1] == now && map[i - 2][j + 2] == 9) + score += 4; + //右上活二 + if (map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == 4) + score += 400; + //右上死二 + if (map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == 9 || map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == you) + score += 90; + //右上活三 + if (map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == now && map[i - 4][j + 4] == 4) + score += 6000; + //右上死三 + if (map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == now && map[i - 4][j + 4] == you || map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == now && map[i - 4][j + 4] == 9) + score += 800; + //右上活四 + if (map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == now && map[i - 4][j + 4] == now && map[i - 5][j + 5] == 4) + score += 20000; + //右上死四 + if (map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == now && map[i - 4][j + 4] == now && map[i - 5][j + 5] == you || map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == now && map[i - 4][j + 4] == now && map[i - 5][j + 5] == 9) + score += 10000; + if ( + map[i][j - 1] == now && map[i][j - 2] == now && map[i][j - 3] == 4 && map[i][j + 1] == now && map[i][j + 2] == 4 || + map[i][j + 1] == now && map[i][j + 2] == now && map[i][j + 3] == 4 && map[i][j - 1] == now && map[i][j - 2] == 4 || + map[i - 1][j] == now && map[i - 2][j] == now && map[i - 3][j] == 4 && map[i + 1][j] == now && map[i + 2][j] == 4 || + map[i + 1][j] == now && map[i + 2][j] == now && map[i + 3][j] == 4 && map[i - 1][j] == now && map[i - 2][j] == 4 || + map[i - 1][j - 1] == now && map[i - 2][j - 2] == now && map[i - 3][j - 3] == 4 && map[i + 1][j + 1] == now && map[i + 2][j + 2] == 4 || + map[i + 1][j + 1] == now && map[i + 2][j + 2] == now && map[i + 3][j + 3] == 4 && map[i - 1][j - 1] == now && map[i - 2][j - 2] == 4 || + map[i + 1][j - 1] == now && map[i + 2][j - 2] == now && map[i + 3][j - 3] == 4 && map[i - 1][j + 1] == now && map[i - 2][j + 2] == 4 || + map[i - 1][j + 1] == now && map[i - 2][j + 2] == now && map[i - 3][j + 3] == 4 && map[i + 1][j - 1] == now && map[i + 2][j - 2] == 4) + score += 5580; + } + } + + //下活一 + if (score < max) + score = 0; + if (score == max) + { + t++; + coord[t][0] = i, coord[t][1] = j; + score = 0; + } + if (score > max) + { + t = 0; + coord[t][0] = i, coord[t][1] = j; + max = score; + score = 0; + } + } + } + + if (turn == 1) + { + maxm = max; + i = rand() % (t + 1); + maxmcoordx = coord[i][0]; + maxmcoordy = coord[i][1]; + turn = 2; + now = 1, you = 0; + Evaluate(); + } + else + { + maxy = max; + i = rand() % (t + 1); + maxycoordx = coord[i][0]; + maxycoordy = coord[i][1]; + } + +} +void AI() +{ + now = 0, you = 1; + turn = 1; + Evaluate(); + if (maxm > maxy) + map[maxmcoordx][maxmcoordy] = 0; + if (maxm < maxy) + map[maxycoordx][maxycoordy] = 0; + if (maxm == maxy) + { + now = rand() % 1; + if (now == 1) + map[maxycoordx][maxycoordy] = 0; + else + map[maxmcoordx][maxmcoordy] = 0; + + + } + system("cls"); + drawMap(); +} +void Run() +{ + while (iswin()) + playchoice(); + if (wint == 1) + printf("\n\t\t\t白棋赢了!\n"); + else + printf("\n\t\t\t黑棋赢了!\n"); + printf("\t\t\t游戏结束!\n\t\t按任意键重新开始\n"); + x = getch(); +} +int main() +{ + printf("\n\n\n\t使用wsad移动,j落子\n"); + Sleep(800); + system("cls"); + while (!kbhit()) + { + init_map_array(); + drawMap(); + Run(); + } + return 0; +}