diff --git a/CMakeLists.txt b/CMakeLists.txt index ac7a61e..10edbda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,3 +5,7 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) add_subdirectory(level1) + +add_subdirectory(level2) + +add_subdirectory(璇剧▼璁捐) diff --git a/level1/CMakeLists.txt b/level1/CMakeLists.txt index 7c004e8..a2969fa 100644 --- a/level1/CMakeLists.txt +++ b/level1/CMakeLists.txt @@ -2,7 +2,10 @@ project(level1) add_executable(p01_running_letter p01_running_letter/main.c) -add_executable(p02_is_prime p02_is_prime/main.c) +add_executable(p02_is_prime p02_is_prime/main.c + p02_is_prime/is_printf.h + p02_is_prime/is_printf.c) + add_executable(p03_all_primes p03_all_primes/main.c) diff --git a/level1/p01_running_letter/main.c b/level1/p01_running_letter/main.c index f84d224..e1574a0 100644 --- a/level1/p01_running_letter/main.c +++ b/level1/p01_running_letter/main.c @@ -1,6 +1,28 @@ -#include - -int main() { - printf("hello world!\n"); +#include +#include +#include +int getWidth() { + CONSOLE_SCREEN_BUFFER_INFO info; + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&info); + return info.srWindow.Right - info.srWindow.Left; +} +int main(void){ + int i,j=0,k,l,num=1; + for(i=0;i +#include +#include +void is_printf(){ + int i,k,f; + scanf("%d",&i); + f=0; + for(k=2;k +#include"is_printf.h" int main() { - printf("hello world!\n"); + is_printf(); return 0; } \ No newline at end of file diff --git a/level1/p03_all_primes/main.c b/level1/p03_all_primes/main.c index f84d224..69450c9 100644 --- a/level1/p03_all_primes/main.c +++ b/level1/p03_all_primes/main.c @@ -1,6 +1,28 @@ -#include - -int main() { - printf("hello world!\n"); +#include +#include +#include +#include +int main(){ + int ts,te; + ts=clock(); + int i,k,f; + for(i=2;i<1001;i++) + { + f=0; + for(k=2;k - -int main() { - printf("hello world!\n"); +#include +#include +#include +int kg(int x){ + int k,f=0; + for(k=2;k - -int main() { - printf("hello world!\n"); +#include +#include +#include +int jiami(char x){ + x=(int)x; + if(65<=x && x<=90) + { + x=(x-62)%26+65; + } + if(97<=x && x<=122) + { + x=(x-94)%26+97; + } + return x; +} +int jiemi(int x){ + if(65<=x && x<=90) + { + x=(x-68+26)%26+65; + } + if(97<=x && x<=122) + { + x=(x-100+26)%26+97; + } + return x; +} +int main(){ + char str[999]; + int i; + scanf("%s",str); + int list[strlen(str)]; + printf("原文:"); + for(i=0;i - -int main() { - printf("hello world!\n"); +#include +int yd(char x,char y,char z,int len){ + len--; + if(len==1) + { + printf("%c->%c\n",x,y); + } + else + { + yd(x,z,y,len); + printf("%c->%c\n",x,y); + yd(z,y,x,len); + } + len++; +} +int main(){ + int n; + scanf("%d",&n); + char x='A',y='B',z='C'; + yd(x,z,y,n+1); return 0; } \ No newline at end of file diff --git a/level1/p07_maze/main.c b/level1/p07_maze/main.c index f84d224..3ddaf3a 100644 --- a/level1/p07_maze/main.c +++ b/level1/p07_maze/main.c @@ -1,6 +1,63 @@ -#include - -int main() { - printf("hello world!\n"); +#include +#include +#include +int main(){ + char list[11][11]={ + {'#','#','#','#','#','#','#','#','#','#','#'}, + {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'}, + {'#',' ','#','#','#',' ',' ','#',' ',' ','#'}, + {'#',' ',' ',' ',' ','#',' ',' ','#',' ','#'}, + {'#','#','#','#',' ',' ','#',' ',' ',' ','#'}, + {'#',' ',' ',' ',' ',' ',' ',' ','#','#','#'}, + {'#',' ','#','#','#','#','#','#','#',' ','#'}, + {'#',' ','#',' ',' ',' ','#',' ',' ',' ','#'}, + {'#',' ','#',' ','#',' ','#',' ','#',' ','#'}, + {'#',' ',' ',' ','#',' ',' ',' ','#',' ','#'}, + {'#','#','#','#','#','#','#','#','#','^','#'} + }; + int i,j,f=1; + int ip=1,jp=1; + char ch; + char name='P'; + while(f==1) { + system("cls"); + for (i = 0; i < 11; i++) { + for (j = 0; j < 11; j++) { + if (i==ip && j==jp) + { + printf("%c",name); + } + else + { + printf("%c", list[i][j]); + } + } + printf("\n"); + } + ch=getch(); + if ((ch=='w') && (list[ip-1][jp]!='#')) + { + ip--; + } + else if ((ch=='s') && (list[ip+1][jp]!='#')) + { + ip++; + } + else if ((ch=='a') && (list[ip][jp-1]!='#')) + { + jp--; + } + else if ((ch=='d') && (list[ip][jp+1]!='#')) + { + jp++; + } + if(list[ip][jp]=='^') + { + f=0; + } + } + system("cls"); + printf("成功"); + system("pause"); return 0; } \ No newline at end of file diff --git a/level1/p08_push_boxes/main.c b/level1/p08_push_boxes/main.c index f84d224..cec9597 100644 --- a/level1/p08_push_boxes/main.c +++ b/level1/p08_push_boxes/main.c @@ -1,6 +1,112 @@ -#include - -int main() { - printf("hello world!\n"); +#include +#include +#include +int main(){ + char list[11][11]={ + {'#','#','#','#','#','#','#','#','#','#','#'}, + {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'}, + {'#',' ',' ',' ',' ',' ',' ','#',' ','*','#'}, + {'#',' ',' ',' ','*','#','*',' ','#',' ','#'}, + {'#','#',' ','#',' ',' ','#',' ','@',' ','#'}, + {'#',' ',' ',' ',' ',' ',' ','@',' ',' ','#'}, + {'#',' ','@',' ',' ',' ','@',' ',' ',' ','#'}, + {'#',' ','#','@',' ',' ',' ',' ',' ',' ','#'}, + {'#',' ',' ',' ','#',' ','#',' ',' ',' ','#'}, + {'#','*',' ',' ',' ',' ',' ',' ','#','*','#'}, + {'#','#','#','#','#','#','#','#','#','#','#'} + }; + int i,j,f=0,step=0; + int ip=1,jp=1; + char ch; + char name='P'; + while(f<5) { + system("cls"); + for (i = 0; i < 11; i++) { + for (j = 0; j < 11; j++) { + if (i==ip && j==jp) { + printf("%c", name); + } + else + { + printf("%c", list[i][j]); + } + printf(" "); + } + printf("\n"); + } + ch=getch(); + if ((ch=='w') && ( (list[ip-1][jp]!='#') && (list[ip-1][jp]!='@'))) + { + ip--; + step++; + } + else if ((ch=='s') && ( (list[ip+1][jp]!='#') && (list[ip+1][jp]!='@'))) + { + ip++; + step++; + } + else if ((ch=='a') && ( (list[ip][jp-1]!='#') && (list[ip][jp-1]!='@'))) + { + jp--; + step++; + } + else if ((ch=='d') && ( (list[ip][jp+1]!='#') && (list[ip][jp+1]!='@'))) + { + jp++; + step++; + } + else if((ch=='w') && (list[ip-1][jp]=='@') && (list[ip-2][jp]!='#') && (list[ip-2][jp]!='@')){ + if (list[ip-2][jp]=='*'){ + list[ip-2][jp]='#'; + list[ip-1][jp]=' '; + f++; + } + else{ + list[ip-2][jp]='@'; + list[ip-1][jp]=' '; + } + step++; + } + else if((ch=='s') && (list[ip+1][jp]=='@') && (list[ip+2][jp]!='#') && (list[ip+2][jp]!='@')){ + if (list[ip+2][jp]=='*'){ + list[ip+2][jp]='#'; + list[ip+1][jp]=' '; + f++; + } + else{ + list[ip+2][jp]='@'; + list[ip+1][jp]=' '; + } + step++; + } + else if((ch=='a') && (list[ip][jp-1]=='@') && (list[ip][jp-2]!='#') && (list[ip][jp-2]!='@')){ + if (list[ip][jp-2]=='*'){ + list[ip][jp-2]='#'; + list[ip][jp-1]=' '; + f++; + } + else{ + list[ip][jp-2]='@'; + list[ip][jp-1]=' '; + } + step++; + } + else if((ch=='d') && (list[ip][jp+1]=='@') && (list[ip][jp+2]!='#') && (list[ip][jp+2]!='@')){ + if (list[ip][jp+2]=='*'){ + list[ip][jp+2]='#'; + list[ip][jp+1]=' '; + f++; + } + else{ + list[ip][jp+2]='@'; + list[ip][jp+1]=' '; + } + step++; + } + } + system("cls"); + printf("you win!\n"); + printf("step:%d\n",step); + system("pause"); return 0; } \ No newline at end of file diff --git a/level1/p09_linked_list/main.c b/level1/p09_linked_list/main.c index f84d224..80ff177 100644 --- a/level1/p09_linked_list/main.c +++ b/level1/p09_linked_list/main.c @@ -1,6 +1,119 @@ -#include +#include +#include -int main() { - printf("hello world!\n"); +struct node +{ + int data; + struct node* next; +}; + +typedef struct node Node; + +Node* opposite(Node* head,int n,char list[]) +{ + int i; + Node* head_oppo =(Node*)malloc(sizeof(Node)); + Node *r,*s; + r = head_oppo; + for (i=0;i data = list[n - i - 1]; + r -> next = s; + r = s; + } + r -> next = NULL; + return head_oppo; +} + +Node* createlist(int n) +{ + int i; + int num; + Node *q,*p; + Node* head =(Node*)malloc(sizeof(Node)); + p = head; + for(i=0;i data = num; + p -> next = q; + p = q; + } + q -> next = NULL; + return head; +}; + +void print(Node* head) +{ + int i=0; + Node *pMove = head -> next; + if (pMove == NULL) + { + printf("璇ラ摼琛ㄤ负绌篭n"); + } + else + { + while (pMove != NULL) { + printf("鑺傜偣%d涓:%d\n", i + 1, pMove->data); + i++; + pMove = pMove->next; + } + } +} + +void Find(Node* head,int find) +{ + int i=0,j=1; + Node *pMove = head -> next; + if (pMove == NULL) + { + printf("鏌ユ壘涓虹┖\n"); + } + else + { + while (pMove != NULL) { + if (pMove -> data == find) + { + printf("绗%d涓%d鐨勫簭鍙蜂负%d\n",j,find,i + 1); + j++; + } + i++; + pMove = pMove->next; + } + if (j == 1) + { + printf("鏌ユ壘涓虹┖\n"); + } + } +} + + + +int main(){ + int n; //鑺傜偣涓暟 + int find; + printf("杈撳叆鑺傜偣涓暟:"); + scanf("%d",&n); + Node* head = createlist(n); + int i=0; + char list[n]; + Node *pMove = head -> next; + while (pMove != NULL) + { + list[i] = pMove->data; + i++; + pMove = pMove->next; + } + print(head); + printf("杈撳叆闇瑕佹煡鎵剧殑鍐呭:"); + scanf("%d",&find); + Node* head_oppo = opposite(head,n,list); + printf("棰犲掑悗:\n"); + print(head_oppo); + Find(head_oppo,find); + system("pause"); return 0; } \ No newline at end of file diff --git a/level1/p10_warehouse/main.c b/level1/p10_warehouse/main.c index f84d224..671f8e6 100644 --- a/level1/p10_warehouse/main.c +++ b/level1/p10_warehouse/main.c @@ -1,6 +1,99 @@ -#include +#include +#include +#include -int main() { - printf("hello world!\n"); +typedef struct store +{ + char name[999]; + int num; +}store; + +int Count = 0; +store list[999]; + +void show() +{ + int i; + printf("************************************\n"); + printf("id\t\t鏁伴噺\n"); + for(i=0;i +#include +#include + +int chessboard[15][15]; + +int drawline(int a , int b , int c , int d) +{ + setlinestyle(PS_SOLID,3); + setlinecolor(RED); + line(a,b,c,d); +} + +int check(int chessboard[15][15]) { + int i, j, f = 0; + for (i = 2; i < 13; i++) { + for (j = 0; j < 15; j++) { + if (chessboard[i - 2][j] + chessboard[i - 1][j] + chessboard[i][j] + chessboard[i + 1][j] + + chessboard[i + 2][j] == 5) { + f = 1; + drawline(30 + j * 40, -50 + i * 40, 30 + j * 40, 110 + i * 40); + } + } + } + for (i = 0; i < 15; i++) { + for (j = 2; j < 13; j++) { + if (chessboard[i][j - 2] + chessboard[i][j - 1] + chessboard[i][j] + chessboard[i][j + 1] + + chessboard[i][j + 2] == 5) { + f = 1; + drawline(-50 + j * 40, 30 + i * 40, 110 + j * 40, 30 + i * 40); + } + } + } + for (i = 2; i < 13; i++) { + for (j = 2; j < 13; j++) { + if (chessboard[i - 2][j - 2] + chessboard[i - 1][j - 1] + chessboard[i][j] + chessboard[i + 1][j + 1] + + chessboard[i + 2][j + 2] == 5) { + f = 1; + drawline(-50 + j * 40, -50 + i * 40, 110 + j * 40, 110 + i * 40); + } + } + } + for (i = 2; i < 13; i++) { + for (j = 2; j < 13; j++) { + if (chessboard[i + 2][j - 2] + chessboard[i + 1][j - 1] + chessboard[i][j] + chessboard[i - 1][j + 1] + + chessboard[i - 2][j + 2] == 5) { + f = 1; + drawline(-50 + j * 40, 110 + i * 40, 110 + j * 40, -50 + i * 40); + } + } + } + return f; +} + + +int check_AI(int chessboard[15][15]) +{ + int i,j,f = 0; + for (i = 2; i < 13; i++) + { + for (j = 0; j < 15; j++) + { + if (chessboard[i - 2][j] + chessboard[i - 1][j] + chessboard[i][j] + chessboard[i + 1][j] + chessboard[i + 2][j] == -5) + { + f = -1; + drawline(30 + j * 40, -50 + i * 40, 30 + j * 40, 110 + i * 40); + } + } + } + for (i = 0; i < 15; i++) + { + for (j = 2; j < 13; j++) + { + if (chessboard[i][j-2] + chessboard[i][j-1] + chessboard[i][j] + chessboard[i][j+1] + chessboard[i][j+2] == -5) + { + f = -1; + drawline(-50 + j * 40, 30 + i * 40, 110 + j * 40, 30 + i * 40); + } + } + } + for (i = 2; i < 13; i++) + { + for (j = 2; j < 13; j++) + { + if (chessboard[i-2][j-2] + chessboard[i-1][j-1] + chessboard[i][j] + chessboard[i+1][j+1] + chessboard[i+2][j+2] == -5) + { + f = -1; + drawline(-50 + j * 40, -50 + i * 40, 110 + j * 40, -50 + i * 40); + } + } + } + for (i = 2; i < 13; i++) + { + for (j = 2; j < 13; j++) + { + if (chessboard[i+2][j-2] + chessboard[i+1][j-1] + chessboard[i][j] + chessboard[i-1][j+1] + chessboard[i-2][j+2] == -5) + { + f = -1; + drawline(-50 + j * 40, 110 + i * 40, 110 + j * 40, 110 + i * 40); + } + } + } + return f; +} + + +void create() +{ + int i; + initgraph(620,640,1); + setbkcolor(RGB(230,200,170)); + cleardevice(); + setlinecolor(BLACK); + for (i = 0; i < 16; i++) + { + line(10 + i * 40,10,10 + i * 40,610); + line(10,10 + i * 40,610,10 + i * 40); + } +} + +void draw(int num) +{ + int i = 30 + num / 100 * 40; + int j = 30 + num % 100 * 40; + setfillcolor(WHITE); + solidcircle(i , j , 16); +} + +void draw_AI(int num) +{ + int p = 30 + num / 100 * 40; + int q = 30 + num % 100 * 40; + setfillcolor(BLACK); + solidcircle(p , q , 16); +} + +void action() +{ + int f = 0,i,j; + MOUSEMSG msg; + while (f == 0) + { + msg = GetMouseMsg(); + if (msg.mkLButton && msg.x > 10 && msg.x < 610 && msg.y > 10 && msg.y < 610) + { + i = (msg.x - 10) / 40; + j = (msg.y - 10) / 40; + if (chessboard[j][i] == 0) + { + chessboard[j][i] = 1; + f = 1; + } + } + } + draw(i * 100 + j); +} +int distance(int a , int b , int c , int d) { + if (a == c && (b + 1 == d || b - 1 == d)) { + return 1; + } else if (b == d && (a + 1 == c || c + 1 == a)) { + return 1; + } else { + return 2; + } +} + +int use_position_find_help(int chessboard[15][15] , int i , int j , int f , int i0 , int j0) { + if (chessboard[i][j] != 0 || f == 1 || f == 2) { + return distance(i, j, i0, j0); + } else { + return 0; + } +} +int use_position_find(int chessboard[15][15] , int i , int j) { + int f = 0; + if (i >= 1) { + f = use_position_find_help(chessboard, i - 1, j, f, i, j); + } + if (i >= 2) { + f = use_position_find_help(chessboard, i - 2, j, f, i, j); + } + if (i <= 13) { + f = use_position_find_help(chessboard, i + 1, j, f, i, j); + } + if (i <= 12) { + f = use_position_find_help(chessboard, i + 2, j, f, i, j); + } + + + if (j >= 1) { + f = use_position_find_help(chessboard, i, j - 1, f, i, j); + } + if (j >= 2) { + f = use_position_find_help(chessboard, i, j - 2, f, i, j); + } + if (j <= 13) { + f = use_position_find_help(chessboard, i, j + 1, f, i, j); + } + if (j <= 12) { + f = use_position_find_help(chessboard, i, j + 2, f, i, j); + } + + if (i >= 1 && j >= 1) { + f = use_position_find_help(chessboard, i - 1, j - 1, f, i, j); + } + if (i >= 1 && j <= 13) { + f = use_position_find_help(chessboard, i - 1, j + 1, f, i, j); + } + if (i <= 13 && j >= 1) { + f = use_position_find_help(chessboard, i + 1, j - 1, f, i, j); + } + if (i <= 13 && j <= 13) { + f = use_position_find_help(chessboard, i + 1, j + 1, f, i, j); + } + + if (chessboard[i][j] != 0) { + f = 0; + } + return f; +} + + +int score_fomular(int n , int list[15] , int target) +{ + int j; + int flag = 0; + int num=0; + for (j = 0; j < n - 1; j++) + { + if(flag == 0) { + if (j <= n - 6 && list[j] + list[j + 1] + list[j + 2] + list[j + 3] + list[j + 4] + list[j + 5]== 6 * target) { + num += 500000; flag = 6; + } + else if (j <= n - 5 && list[j] + list[j + 1] + list[j + 2] + list[j + 3] + list[j + 4] == 5 * target) { + num += 100000; flag = 5; + } else if (j <= n - 4 && list[j] + list[j + 1] + list[j + 2] + list[j + 3] == 4 * target && + j >= 1 && j <= n - 5 && list[j - 1] == 0 && list[j + 4] == 0) { + num += 50000; flag = 4; + } else if (j <= n - 4 && list[j] + list[j + 1] + list[j + 2] + list[j + 3] == 4 * target && + ((j == 0 && list[j + 4] == 0) || (j == n - 4 && list[j - 1] == 0))) { + num += 5000; flag = 4; + } else if (j <= n - 4 && list[j] + list[j + 1] + list[j + 2] + list[j + 3] == 4 * target && + j >= 1 && j <= n - 5 && (list[j - 1] + list[j + 4] == -target)) { + num += 5000; flag = 4; + } else if (j <= n - 5 && list[j] == target && list[j + 4] == target && + list[j] + list[j + 1] + list[j + 2] + list[j + 3] + list[j + 4] == 4 * target) { + num += 5000; flag = 5; + } else if (j <= n - 3 && list[j] + list[j + 1] + list[j + 2] == 3 * target && + ((j == 0 && list[j + 3] == 0 && list[j + 4] == 0) || + (j == n - 3 && list[j - 1] == 0 && list[j - 2] == 0))) { + num += 100; flag = 3; + } else if (j <= n - 3 && list[j] + list[j + 1] + list[j + 2] == 3 * target && + j >= 1 && j <= n - 4 && (list[j - 1] + list[j + 3] == -target)) { + num += 100; flag = 3; + } else if (j <= n - 3 && list[j] + list[j + 1] + list[j + 2] == 3 * target && + j >= 1 && j <= n - 4 && list[j - 1] == 0 && list[j + 3] == 0) { + num += 1000; flag = 3; + } else if (j <= n - 4 && list[j] == target && list[j + 3] == target && + list[j + 1] + list[j + 2] == target && + ((j == n - 4 && list[j - 1] == 0) || (j == 0 && list[j + 4] == 0))) { + num += 100; flag = 4; + } else if (j <= n - 4 && list[j] == target && list[j + 3] == target && + list[j + 1] + list[j + 2] == target && j <= n - 5 && j >= 1 && + list[j - 1] + list[j + 4] == -target) { + num += 100; flag = 4; + } else if (j <= n - 4 && list[j] == target && list[j + 3] == target && + list[j + 1] + list[j + 2] == target && j <= n - 5 && j >= 1 && list[j - 1] == 0 && + list[j + 4] == 0) { + num += 1000; flag = 4; + } else if (j <= n - 5 && list[j] + list[j + 4] == 2 * target && + list[j + 1] * list[j + 2] * list[j + 3] == 0 && + list[j + 1] + list[j + 2] + list[j + 3] == target) { + num += 100; flag = 4; + } else if (j < n - 2 && j > 0 && list[j] + list[j + 1] == 2 * target && list[j - 1] == 0 && + list[j + 2] == 0) { + num += 10; flag = 2; + } else if (j < n - 3 && j > 0 && list[j] + list[j + 2] == 2 * target && list[j + 1] == 0 && + list[j - 1] == 0 && list[j + 3] == 0) { + num += 10; flag = 2; + } else if (j == n - 2 && list[j] + list[j + 1] == 2 * target && list[j - 1] == 0 && list[j - 2] == 0) { + num += 1; flag = 2; + } else if (j >= 1 && j <= n - 2 && list[j - 1] == 0 && list[j + 1] == 0 && list[j] == target) { + num += 1; flag = 1; + } + } + if(flag > 0) + { + flag--; + } + } + return num; +} + +int score_count(int chessboard[15][15] , int id) +{ + int list_temporary[15]; + int i,j; + int score = 0; + for (i = 0; i < 15; i++) + { + for (j = 0; j < 15; j++) + { + list_temporary[j] = chessboard[i][j]; + } + score += score_fomular(15 , list_temporary , id); + } + for (i = 0; i < 15; i++) + { + for (j = 0; j < 15; j++) + { + list_temporary[j] = chessboard[j][i]; + } + score += score_fomular(15 , list_temporary , id); + } + for (i = 4; i < 15; i++) + { + for (j = 0; j < i + 1; j++) + { + list_temporary[j] = chessboard[i - j][j]; + } + score += score_fomular(i + 1 , list_temporary , id); + } + for (i = 13; i > 3; i--) + { + for (j = 0; j < i + 1; j++) + { + list_temporary[j] = chessboard[14 - j][j + 14 - i]; + } + score += score_fomular(i + 1 , list_temporary , id); + } + for (i = 4; i < 15; i++) + { + for (j = 0; j < i + 1; j++) + { + list_temporary[j] = chessboard[14 - i + j][j]; + } + score += score_fomular(i + 1 , list_temporary , id); + } + for (i = 13; i > 3; i--) + { + for (j = 0; j < i + 1; j++) + { + list_temporary[j] = chessboard[j][14 - i + j]; + } + score += score_fomular(i + 1 , list_temporary , id); + } + return score; +} + +int score_count_real(int cheaaboard[15][15] , int s) +{ + return score_count(chessboard , s) - score_count(chessboard , -s); +} + +int list_find_max(int list_input[15][15]) { + int i, j, temp, f=1; + int list_compare_help[15]; + int list[15][15]; + for (i = 0; i < 15; i++) { + for (j = 0; j < 15; j++) { + list[i][j] = list_input[i][j]; + } + } + for (i = 0; i < 15; i++) { + for (j = 0; j < 14; j++) { + if (list[i][j] > list[i][j + 1]) { + temp = list[i][j]; + list[i][j] = list[i][j + 1]; + list[i][j + 1] = temp; + } + } + list_compare_help[i] = list[i][14]; + } + for (i = 0; i < 14; i++) { + if (list_compare_help[i] > list_compare_help[i + 1]) { + temp = list_compare_help[i]; + list_compare_help[i] = list_compare_help[i + 1]; + list_compare_help[i + 1] = temp; + } + } + if (list_compare_help[14] < 0) + { + f = -1; + } + for (i = 0; i < 15; i++) { + for (j = 0; j < 15; j++) { + if (list_input[i][j] == list_compare_help[14]) { + return f * (abs(list_compare_help[14]) * 10000 + j * 100 + i); + } + } + } +} + +int list_find_min(int list_input[15][15]) { + int i, j, temp ,f=1; + int list_compare_help[15]; + int list[15][15]; + for (i = 0; i < 15; i++) { + for (j = 0; j < 15; j++) { + list[i][j] = list_input[i][j]; + } + } + for (i = 0; i < 15; i++) { + for (j = 0; j < 14; j++) { + if (list[i][j] < list[i][j + 1]) { + temp = list[i][j]; + list[i][j] = list[i][j + 1]; + list[i][j + 1] = temp; + } + } + list_compare_help[i] = list[i][14]; + } + for (i = 0; i < 14; i++) { + if (list_compare_help[i] < list_compare_help[i + 1]) { + temp = list_compare_help[i]; + list_compare_help[i] = list_compare_help[i + 1]; + list_compare_help[i + 1] = temp; + } + } + if (list_compare_help[14] < 0) + { + f = -1; + } + for (i = 0; i < 15; i++) { + for (j = 0; j < 15; j++) { + if (list_input[i][j] == list_compare_help[14]) { + return f * (abs(list_compare_help[14]) * 10000 + j * 100 + i); + } + } + } +} + + +void action_AI() +{ + int i,j,k,l,p,q,k1,l1,p1,q1; + int i1,j1,i2,j2; + int f,f1,f2; + int s1=0,s2; + int temp , f_line; + int list_use_position[225]; + int list_use_position1[225]; + int list_use_position2[15][15]; + int list_use_position3[15][15]; + int list_score[15][15]; + int list_score1[15][15]; + int list_score2[15][15]; + int list_score0[15][15]; + int list_score_another1[15][15]; + int max = -999999, min = 999999, max1 = -999999; + int result; + + + for (i = 0; i < 15; i++) + { + for (j = 0; j < 15; j++) + { + list_use_position[i * 15 + j] = use_position_find(chessboard , i , j) * 10000 + i * 100 + j; + } + } + for (i = 224; i > 0; i--) + { + f_line = 0; + for (j = i; j > 0; j--) + { + if ((list_use_position[j] >= 10000 && list_use_position[j] < list_use_position[j - 1]) || (list_use_position[j] >= 10000 && list_use_position[j - 1] < 10000)) + { + temp = list_use_position[j]; + list_use_position[j] = list_use_position[j - 1]; + list_use_position[j - 1] = temp; + f_line = 1; + } + } + if(f_line == 0) + { + break; + } + } + while (list_use_position[s1] >= 10000) + { + + f = 1; + min = 999999; + l = list_use_position[s1] % 10000 / 100; + k = list_use_position[s1] % 100; + if(chessboard[l][k] == 0) + { + chessboard[l][k] = -1; + + for (i = 0; i < 15; i++) { + for (j = 0; j < 15; j++) { + list_use_position1[i * 15 + j] = use_position_find(chessboard, i, j) * 10000 + i * 100 + j; + } + } + for (i = 224; i > 0; i--) { + f_line = 0; + for (j = i; j > 0; j--) { + if (list_use_position1[j] > list_use_position1[j - 1]) { + temp = list_use_position1[j]; + list_use_position1[j] = list_use_position1[j - 1]; + list_use_position1[j - 1] = temp; + f_line = 1; + } + } + if (f_line == 0) { + break; + } + } + s2 = 0; + while (list_use_position1[s2] >= 10000) + { + f1 = 1; + max1 = -999999; + p = list_use_position1[s2] % 10000 / 100; + q = list_use_position1[s2] % 100; + if(chessboard[p][q] == 0) + { + chessboard[p][q] = 1; + + for (i1 = 0; i1 < 15; i1++) + { + for (j1 = 0; j1 < 15; j1++) + { + list_use_position2[i1][j1] = use_position_find(chessboard , i1 , j1); + } + } + + + + for (l1 = 0; l1 < 15; l1++) { + for (k1 = 0; k1 < 15; k1++) { + f2 = 1; + if (chessboard[l1][k1] == 0 && list_use_position2[l1][k1] != 0) { + chessboard[l1][k1] = -1; + + for (i2 = 0; i2 < 15; i2++) { + for (j2 = 0; j2 < 15; j2++) { + list_use_position3[i2][j2] = use_position_find(chessboard, i2, j2); + } + } + + for (p1 = 0; p1 < 15; p1++) { + for (q1 = 0; q1 < 15; q1++) { + if (chessboard[p1][q1] == 0 && list_use_position3[p1][q1] != 0) { + chessboard[p1][q1] = 1; + list_score0[p1][q1] = score_count_real(chessboard, -1); + chessboard[p1][q1] = 0; + } else { + list_score0[p1][q1] = 1000000; + } + if (list_score0[p1][q1] < max1) { + f2 = 0; + } + if (f2 == 0) break; + } + if (f2 == 0) break; + } + list_score1[l1][k1] = abs(list_find_min(list_score0)) / 10000; + if (list_find_min(list_score0) < 0) { + list_score1[l1][k1] *= -1; + } + chessboard[l1][k1] = 0; + if (list_score1[l1][k1] > max1) { + max1 = list_score1[l1][k1]; + } + if (list_score1[l1][k1] > min) { + f1 = 0; + } + } else { + list_score1[l1][k1] = -1000000; + } + if (f1 == 0) break; + } + if (f1 == 0) break; + } + list_score2[p][q] = abs(list_find_max(list_score1))/10000; + if (list_find_max(list_score1) < 0) { + list_score2[p][q] *= -1; + } + chessboard[p][q] = 0; + if (list_score2[p][q] < min) { + min = list_score2[p][q]; + } + if (list_score2[p][q] < max) { + f = 0; + } + + + + + + } + else + { + list_score2[p][q] = 1000000; + } + s2++; + if (f == 0) break; + } + while (s2 < 225) + { + list_score2[list_use_position1[s2] % 10000 / 100][list_use_position1[s2] % 100] = 1000000; + s2++; + } + list_score[l][k] = abs(list_find_min(list_score2))/10000; + if(list_find_min(list_score2) < 0) + { + list_score[l][k] *= -1; + } + chessboard[l][k] = 0; + + if (list_score[l][k] > max) + { + max = list_score[l][k]; + } + } + else + { + list_score[l][k] = -10000; + } + s1++; + } + while (s1 < 225) + { + list_score[list_use_position[s1] % 10000 / 100][list_use_position[s1] % 100] = -10000; + s1++; + } + result = abs(list_find_max(list_score)); + chessboard[result % 100][result / 100 % 100] = -1; + draw_AI(result % 10000); +} + + + + + +int main() +{ + int i,j; + for (i = 0; i < 15; i++) + { + for(j = 0; j < 15; j++) + { + chessboard[i][j] = 0; + } + } + create(); + int win = 0; + while (win == 0) + { + action(); + win = check(chessboard); + if (win != 0) + { + break; + } + action_AI(); + win = check_AI(chessboard); + } + printf("%d",win); + if (win == 1) + { + wchar_t print[50] = L"player win !"; + settextcolor(BLACK); + outtextxy(260,630,print[50]); + } + else + { + wchar_t print[50] = L"AI win !"; + settextcolor(BLACK); + outtextxy(260,630,print[50]); + } + system("pause"); + return 0; +} \ No newline at end of file diff --git "a/\350\257\276\347\250\213\350\256\276\350\256\241/\345\237\272\344\272\216\350\257\204\344\274\260\345\207\275\346\225\260\344\270\216Alpha Beta\345\211\252\346\236\235\347\232\204\344\272\224\345\255\220\346\243\213AI\347\256\227\346\263\225\350\256\276\350\256\241.docx" "b/\350\257\276\347\250\213\350\256\276\350\256\241/\345\237\272\344\272\216\350\257\204\344\274\260\345\207\275\346\225\260\344\270\216Alpha Beta\345\211\252\346\236\235\347\232\204\344\272\224\345\255\220\346\243\213AI\347\256\227\346\263\225\350\256\276\350\256\241.docx" new file mode 100644 index 0000000..e067f0b Binary files /dev/null and "b/\350\257\276\347\250\213\350\256\276\350\256\241/\345\237\272\344\272\216\350\257\204\344\274\260\345\207\275\346\225\260\344\270\216Alpha Beta\345\211\252\346\236\235\347\232\204\344\272\224\345\255\220\346\243\213AI\347\256\227\346\263\225\350\256\276\350\256\241.docx" differ diff --git "a/\350\257\276\347\250\213\350\256\276\350\256\241/\345\237\272\344\272\216\350\257\204\344\274\260\345\207\275\346\225\260\344\270\216Alpha Beta\345\211\252\346\236\235\347\232\204\344\272\224\345\255\220\346\243\213AI\347\256\227\346\263\225\350\256\276\350\256\241.pptx" "b/\350\257\276\347\250\213\350\256\276\350\256\241/\345\237\272\344\272\216\350\257\204\344\274\260\345\207\275\346\225\260\344\270\216Alpha Beta\345\211\252\346\236\235\347\232\204\344\272\224\345\255\220\346\243\213AI\347\256\227\346\263\225\350\256\276\350\256\241.pptx" new file mode 100644 index 0000000..eeadc24 Binary files /dev/null and "b/\350\257\276\347\250\213\350\256\276\350\256\241/\345\237\272\344\272\216\350\257\204\344\274\260\345\207\275\346\225\260\344\270\216Alpha Beta\345\211\252\346\236\235\347\232\204\344\272\224\345\255\220\346\243\213AI\347\256\227\346\263\225\350\256\276\350\256\241.pptx" differ