多应用+插件架构,代码干净,支持一键云编译,码云点赞13K star,4.8-4.12 预售价格198元 广告
**《357游戏的“必胜算法"》 Linux C++ 语言实现** 下面在 Linux C++ 编译通过180901 能Run能运行…… (待优化……) ----Author: TerryDeng(1809) **博弈论虽然可以归为数学……; 原则上归为科学就更恰当……。 我们用通俗的语言去描述博弈…… 一、所有的 **零和博弈 **原则上 只有 一条 道路 通向 成功(的王冠); (如果假设参与 博弈的人 都是 绝顶理性、绝顶并无限智慧的智者…… 的话)那么 只有 一条 唯一 理性(并且正确的道路)通向 成功! 二、通向成功的道路也许在 先下手的 所谓“先手”手中,也有可能是 在 “后手”手中…… 三、如果 持有 先机的 人(或曰 持有 权柄的人)…… 一直 按照 必胜 算法 的策略去行事…… ;(另外的一方)不具备 权柄的 人 ,是没有机会 获得 赢的 “权柄”(或赢的机会的)…… 他(无权柄者们)只能 想办法 拖延失败、以 等待 当权者 失误, 以便 有机会 抓到 “权柄”。** ~~~ #include<iostream> #include<stdlib.h> using namespace std; //int a , b , c, a1 , b2 , l; // int indexabc(int &a,int &b, int &c) { int tmpnum; if(b<a) { tmpnum=a; a=b; b=tmpnum; } //1、此处是交换 a,b ,下同... if(b>c) {tmpnum=b;b=c;c=tmpnum;} //2、比a 大的 b... if(b<a) {tmpnum=a;a=b;b=tmpnum;} //3、原来的c,现在在b,也许比a小,还得换...想想:为啥 两次(第2次) 比较 a 和b? ( 1、2只保证 最大的数 放c , 3、保证 最小的数 比如原来的 c ==1\2\3 等 放 a! // if(a<b && b<c) {get357bb(a,b,c); } // else cout<<"program Wrong12!"; } int get111bak01a(int a=1,int b=1,int c=1) { // if(1==a,1==b,1==c) { a=1-1; int b=1;int c=1; cout << a<<b<<c<<" do you know?...Computer will Lost!"; } indexabc(a,b,c); if(1==a,1==b,1==c) { a=1; int b=1;int c=1; cout<<a<<b<<c<<"Victory algorithm:[111 type]...you know? U will win...!\r\n/r/n"; return 1;} return 0; } int get123a(int a=1,int b=3,int c=2) { indexabc(a,b,c); if(1==a,2==b,3==c) { cout<<a<<b<<c<<"Victory algorithm:[123type]...you know? U will win...!"; return 1; } return 0; } int get145a(int a=1,int b=4,int c=5) { indexabc(a,b,c); // 强行排序 int tmpn=0; if(a>b) {tmpn=a;a=b;b=tmpn;} if(b>c){tmpn=b;b=c;c=tmpn;} if(a>b){tmpn=a;a=b;b=tmpn;} if(1==a,4==b,5==c) { cout<<a<<b<<c<<"Victory algorithm:[type145]...you know or not? U will win...!"; return 1; } if(1==a,5==b,4==c) { cout<<a<<b<<c<<"Victory algorithm:[type154]...you know or not? U will win...!"; return 1; } return 0; } int get111a(int a=1,int b=1,int c=1) { indexabc(a,b,c); if(1==a,1==b,1==c) { cout<<a<<b<<c<<"Victory algorithm:[111type]...you know? U will win...!"; return 1; } return 0; } // int ans(int a,int b,int c) { cout<<"\r\nAnwser is:"; cout<<a<<b<<c<<endl; } int get357bb(int a=3,int b=5,int c=7) { // indexabc(a,b,c); //此排序函数(由于局部变量问题,)排序无效 // 强行排序 int tmpn=0; if(a>b) {tmpn=a;a=b;b=tmpn;} if(b>c){tmpn=b;b=c;c=tmpn;} if(a>b){tmpn=a;a=b;b=tmpn;} int i,j,ic; //三级检测 if(3==a&&5==b&&6==c) { a=a-1; ans(a,b,c); goto lableEnd9990;} //356 回256 //被迫回156者应该是 实属无奈,应回154/145 // 因 被持有(拿到)123 必死 ,拿到145也必死 if(3==a&&4==b&&6==c) { a=a-1; ans(a,b,c); cout<<"I can send you to death with 246!"<<endl; goto lableEnd9990;} //256 回246I can send you to death with 246! // if(2==a&&5==b&&6==c) { b=b-1; ans(a,b,c); cout<<"I can send you to death with 246!"<<endl; goto lableEnd9990;} //256 回246I can send you to death with 246! //被迫回156者应该是 实属无奈,应回154/145 // 因 被持有(拿到)123 必死 ,拿到145也必死 if(1==a&&5==b&&6==c) { c=4; ans(a,b,c); goto lableEnd9990;} //被迫回156者应该是 实属无奈,应回154/145 // 因 被持有(拿到)123 必死 ,拿到145也必死 if(1==a&&4==b&&6==c) { c=5; ans(a,b,c); goto lableEnd9990;} //被迫回146者也属无奈,回145 // 因 被持有(拿到)123 必死 ,拿到145也必死 if(1==a&&3==b&&4==c) { c=2; ans(a,b,c); goto lableEnd9990;} //被迫回134者也属无奈! 应回123 // 因 被持有(拿到)123 必死 ,拿到145也必死 if(1==a&&3==b&&5==c) { c=2; ans(a,b,c); goto lableEnd9990;} //被迫回135者也属无奈! 应回132\即123 // 因 被持有(拿到)123 必死 ,拿到145也必死 if(1==a&&4==b&&5==c) { b=3; ans(a,b,c); goto lableEnd9990;} //拿到 145,不好处理(其实基本已输), 回144肯定100%蠢(会100%输),所以只好回 143(/134---- 其实(即便被迫)回了134\143,对方回应对,还是会输……此处为无奈之选(以图蒙混过关而已,对手按必胜算法形式则必胜…… if(2==a&&4==b&&7==c) { c=6; ans(a,b,c); cout<<"I can send you to death with 246!"<<endl; goto lableEnd9990;} //得到245,只能回 246(必胜算法?) //246的应对: if(2==a&&4==b&&6==c) { if(0==rand()%4 ) c=3; //回243\234 else if( 1==( rand()%4 ) ) {a=1;} //回146 属(中等)无奈,希望对手不懂回145(145有力\必胜) else c=5;//回245的情况要好些,因为 不是高手有时不懂 回必胜(有力)的 145 ans(a,b,c); goto lableEnd9990; } //得到246是死局面(败泥潭)!,可以无奈的回 245(等死一),也可以 回243 等死二;所以选择随机数,等死的状态随机!(为游戏者增加一点难道 或 增一点趣味……) if(2==a&&4==b&&5==c) { a=1; ans(a,b,c); goto lableEnd9990;} //得到245, 只能回145(必胜算法) if(2==a&&3==b&&7==c) { c=1; ans(a,b,c); goto lableEnd9990;} //得到236, 只能回231/即123(必胜算法) if(2==a&&3==b&&6==c) { c=1; ans(a,b,c); goto lableEnd9990;} //得到236, 只能回231/即123(必胜算法) if(2==a&&3==b&&5==c) { c=1; ans(a,b,c); goto lableEnd9990;} //得到235, 只能回231/即123(必胜算法) if(2==a&&3==b&&4==c) { c=1; ans(a,b,c); goto lableEnd9990;} //得到234, 只能回231/即123(必胜算法) // if(2==a&&3==b&&3==c) { c=1; ans(a,b,c); goto lableEnd9990;} //得到233, 可以回 033 或回231/即123(必胜算法) //一级检测; 0==a if(0==a) { if (1<b &&b==c) { ans(0, b-1, c); cout<<"你(无奈)给出非必胜答案,U stupid?,Computer will win!"<<endl; goto lableEnd9990; } else if(b<c) {ans(0,b,b); goto lableEnd9990;} else {ans(0,c,c); goto lableEnd9990; }// c<b and 0==a } //检测 xxY型号 并 0nn 型号 //检测当 0!=a 时候 “将来 会形成的0nn”型号 if( 1<a && a==b ) {cout<<"Type_`xxY` Victory algorithm!型号必胜"<<endl; c=0; cout<<a<<b<<c<<endl; ans(0,a,b); goto lableEnd9990; } //if(1==get0nn1(a-i,b,c) ) goto lableEnd9990; if( 1<b &&b==c ) {cout<<"Type0xx_`0nn`Victory algorithm!型号必胜"<<endl; a=0; cout<<a<<b<<c<<endl; ans(0,b,c); goto lableEnd9990; } //if(1==get0nn1(a-i,b,c) ) goto lableEnd9990; //二级检测、检测 2xy型 5==x 时 if(2==a) { //if2a if(5==b) { //if5b // for(i=0;i<=5;++i) { if(5==b&&7==c) { a=a-1;c=c; cout<<a<<b<<c;} else if(6==c) {a=a; b=b-1; cout<<a<<b<<c; cout<<"I can send you to death with 246!"<<endl;} else { for(j=7;j<0;--i) { a=2;b=5;c=c-j; cout<<a<<b<<c<<"win25x?"<<endl; } } // } }//if5b goto lableEnd9990; }//if2a //检测 0nn 型号 2、3、4、5==n 时 //失效?? // for(i=1;i<=c;++i) { if(1==get0nn1(a,b,c-i) ) {ans(a,b,c-i) ;goto lableEnd9990;} } // for(i=1;i<=b;++i) { if(1==get0nn1(a,b-i,c) ) {ans(a,b-i,c) ; goto lableEnd9990;} } //四级检测 //检测 011型 //失效! // for(i=1;i<=c;++i) { if(1==get011a(a,b,c-i) ) {ans(a,b,c-i) ;goto lableEnd9990;} } // for(i=1;i<=b;++i) { if(1==get011a(a,b-i,c) ) {ans(a,b-i,c) ;goto lableEnd9990; } } // for(i=1;i<=a;++i) { if(1==get011a(a-i,b,c) ) {ans(a-i,b,c) ;goto lableEnd9990; } } //检测 111型 有效 for(i=1;i<=c;++i) { if(1==get111a(a,b,c-i) ) {ans(a,b,c-i) ;goto lableEnd9990;} } for(i=1;i<=b;++i) { if(1==get111a(a,b-i,c) ) {ans(a,b-i,c) ;goto lableEnd9990;} } for(i=1;i<=a;++i) { if(1==get111a(a-i,b,c) ) {ans(a-i,b,c) ;goto lableEnd9990;} } //检测123型 for(i=1;i<=c;++i) { if(1==get123a(a,b,c-i) ) {ans(a,b,c-i) ;goto lableEnd9990; } } for(i=1;i<=b;++i) { if(1==get123a(a,b-i,c) ) {ans(a,b,c-i) ;goto lableEnd9990;} } for(i=1;i<=a;++i) { if(1==get123a(a-i,b,c) ) {ans(a,b,c-i) ;goto lableEnd9990;} } //检测145型 for(i=1;i<=c;++i) { if(1==get145a(a,b,c-i) ) {ans(a,b,c-i) ;goto lableEnd9990; } } for(i=1;i<=b;++i) { if(1==get145a(a,b-i,c) ) {ans(a,b,c-i) ;goto lableEnd9990;} } for(i=1;i<=a;++i) { if(1==get145a(a-i,b,c) ) {ans(a,b,c-i) ;goto lableEnd9990;} } // cout<<"Type145:"; // cout<<a<<b<<c<<endl; // //goto lableEnd9990; //检测167型(可省略) // for(i=1;i<=7;++i) { if(1==get167a(a,b,c) ) goto lableEnd9990; } // for(i=1;i<=5;++i) { if(1==get167a(a,b,c) ) goto lableEnd9990;} // for(i=1;i<=3;++i) { if(1==get167a(a,b,c) ) goto lableEnd9990;} lableUnknow990: cout<<"no anwser990"<<endl; lableEnd9990: // cout<<"End9990"<<endl; cout<<"!!"<<endl; return 0; } int get357a(int a=3,int b=5,int c=7) { indexabc(a,b,c); //此处排序,不生效,有待改进…… if(3==a&&5==b&&7==c) { cout <<"start?:"; a=a-1; cout<<a<<b<<c <<endl; } //2==a : 257 else get357bb(a,b,c); } int main() { cout << "Game 357: Please input the Number,for exam: 2 5 7 OR 3 5 6 with EnterKey...Input 000 Exit!"<< endl; //请输入三个正整数...GCD:请输入两个正整数,计算它们的最大公约数:" << endl ; int a , b , c, ans; int firstbackhand=0; int inputn=0; // cin >> a >> b >> c; do { // for (int ii0=0;ii0<15;++ii0) {//forii0 ++firstbackhand; if(1== (firstbackhand%2) ) { cout<<"First:"<<firstbackhand<<"Human?"<<endl; /*firstbackhand=0;*/} //此处先后手可为乒乓键 else { cout<<"Backhand"<<firstbackhand<<"Computer?"<<endl; /*firstbackhand=1;*/} cin>>inputn; if ( inputn<001 ) { cout<<"the Number is too small! 输入太小了!"<<endl; return 0;} if ( inputn>010 ) { c=inputn%10; b=(inputn/10)%10; a=inputn/100;} else {a=0;b=0;c=1;} // for(int i=15;i>=1;++i) { if ( 1==a && 0==b && 0==c) {goto lable110computerlost1;} if ( 0==a && 1==b && 0==c) {goto lable110computerlost1;} if ( 0==a && 0==b && 1==c) {goto lable110computerlost1;} // } get357a(a,b,c); //循环判断 对策, 找到所谓“必胜对策” //}//forii0 } while (inputn>000); goto labelEnd; lable110computerlost1: cout << "You(inputer) win! computer be bombed!Computer lost and die!" <<endl; labelEnd: return 0; } //口诀: 一0双 、二111、三123、四145、五246 (所以先手有必胜算法(简称先手必胜)! 可选257、356 或347 //后手必可以被gived雷炸(简称原则必败)...比如遇到257 回256(会死于246的…“暗”雷区); 比如遇356 回156(其实会死于145之雷) ; 347 回346(会死于246)……等,后手者(或不具备先机者、不当权者) 会被智慧的(永不犯错才可被称智慧的)先手 推入(败输的)泥潭... //1、零和博弈必有必胜策略(或称必胜算法); //2、必胜策略在于 先手者 或先机者(的手中)…… //3、游戏的核心 为 抢得先机(然后按必胜策略行事......这在围棋里面称为“弃子争先、舍地取势等”)... 而抢得先机的核心 就是 规避 雷区(规避明雷: 0xx, 111 123还要规避 暗雷:246 145等) 都属(总结出的)雷区,又叫“(不力)的定式”……围棋当中的“定式”就是这个道理…… //获得“定式”……加以练习会成智者(或高手) ~~~ 下面是(357游戏 必胜算法 的 c++程序) 运行结果 截图: ![](https://box.kancloud.cn/46921d801ced96ba564cefb718345c71_942x914.png) 246雷区 246的下一个雷区是: 1、257 2、356 3、347 所以: 357 游戏的 要领就是 357先手有先机, 上来就把后手 推入 雷区 359游戏呢?……一样 推入 356 397游戏呢?……推入347 957游戏呢?……推入257 399游戏 傻啊? 099 389游戏? 387 ->347 输 386 ->356输 379游戏 == 397 搞过了 3-7-11 游戏: 3-7-11 3-7-10 374输 5-7-11游戏: 5-7-10 257 输 所以 5-7-11 等 游戏 (开局后)马上 会 塌缩: 塌缩 为 (类似)357游戏 这种……