久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4371|回復: 1
收起左側

原創(chuàng)五子棋算法1.0

[復制鏈接]
ID:127496 發(fā)表于 2016-6-21 01:10 | 顯示全部樓層 |閱讀模式
原創(chuàng)垃圾算法,兩下子就能下贏的。
用法:在第一幀的場景外面處放置三個影片剪輯,分別命名為yn,black,white
其中yn里面放一個寛16高16的透明按鈕,實例名稱為x (小寫)
在black里面放一個黑色的棋子16*16
white放一個相同大小的白棋子。
然后再在場景里畫一個16*16的期盤,每個格子寛16.4
設定棋盤的_x=10,_y=10
把以下代碼放在第一幀幀上,運行即可
  1. var chess:Array = new Array();
  2. var hh:Number = 0;
  3. var now:Boolean = true;
  4. var mi:Number = 0;
  5. var desi:Array = new Array();
  6. var desj:Array = new Array();
  7. var comi:Array = new Array();
  8. var comj:Array = new Array();
  9. now = null;
  10. var gong = 5;
  11. var fang = 10;
  12. right_menu = new ContextMenu();
  13. right_menu.hideBuiltInItems();
  14. right_menu.customItems.push(new ContextMenuItem("悔棋", huiqi, false));
  15. right_menu.customItems.push(new ContextMenuItem("狀態(tài)", see, false));
  16. for (i=0; i<16; i++) {
  17. chess[i] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  18. for (j=0; j<16; j++) {
  19.   _root.yn.duplicateMovieClip("yn"+i+"_"+j, 9000+i*16+j, {_x:9+i*16.39, _y:9+j*16.35});
  20.   _root["yn"+i+"_"+j].x.onRelease = function() {
  21.    _root.pd();
  22.   };
  23. }
  24. }
  25. function win(who) {
  26. if (who == 1) {
  27.   _root.now = 3;
  28.   _root.xx = "您打敗了對手!共用"+hh+"回合";
  29. } else if (who == 2) {
  30.   _root.now = 3;
  31.   _root.xx = "您輸了!";
  32. }
  33. }
  34. function ifwin() {
  35. for (i=0; i<16; i++) {
  36.   for (j=0; j<16; j++) {
  37.    for (k=0; k<3; k++) {
  38.     if (chess[i][j] == k) {
  39.      for (c=0; c<5; c++) {
  40.       if (chess[i+c][j] == k) {
  41.        if (c == 4) {
  42.         _root.win(k);
  43.        }
  44.       } else {
  45.        break;
  46.       }
  47.      }
  48.      for (c=0; c<5; c++) {
  49.       if (chess[i+c][j-c] == k) {
  50.        if (c == 4) {
  51.         _root.win(k);
  52.        }
  53.       } else {
  54.        break;
  55.       }
  56.      }
  57.      for (c=0; c<5; c++) {
  58.       if (chess[i][j+c] == k) {
  59.        if (c == 4) {
  60.         _root.win(k);
  61.        }
  62.       } else {
  63.        break;
  64.       }
  65.      }
  66.      for (c=0; c<5; c++) {
  67.       if (chess[i+c][j+c] == k) {
  68.        if (c == 4) {
  69.         _root.win(k);
  70.        }
  71.       } else {
  72.        break;
  73.       }
  74.      }
  75.     }
  76.    }
  77.   }
  78. }
  79. }
  80. function cd(a, b) {
  81. if (_root.hh == 0) {
  82.   a = 8;
  83.   b = 8;
  84. }
  85. _root.comi[hh] = a;
  86. _root.comj[hh] = b;
  87. _root.chess[a][b] = 2;
  88. _root.black.duplicateMovieClip("black_"+a+"_"+b, mi-1000, {_x:10+b*16.41, _y:10+a*16.4});
  89. _root.mi++;
  90. _root.now = false;
  91. _root.ifwin();
  92. trace("cd("+a+","+b+")");
  93. }
  94. function pd() {
  95. if (_root.now == false) {
  96.   x2 = _root._xmouse;
  97.   y2 = _root._ymouse;
  98.   a = int((y2-10)/16.41+0.5);
  99.   b = int((x2-10)/16.41+0.5);
  100.   trace([a, b]);
  101.   if (_root.chess[a][b] == 0) {
  102.    _root.chess[a][b] = 1;
  103.    _root.desi[hh] = a;
  104.    _root.desj[hh] = b;
  105.    _root.white.duplicateMovieClip("white_"+a+"_"+b, mi-1000, {_x:10+b*16.41, _y:10+a*16.4});
  106.    _root.mi++;
  107.    _root.hh++;
  108.    _root.now = true;
  109.   } else {
  110.    trace(_root.chess[a][b]);
  111.   }
  112. }
  113. _root.ifwin();
  114. }
  115. this.onEnterFrame = function() {
  116. _root.js = "<b>五子棋V2.0</b>\n譚澤睿\n    VS\n       "+_root.pn+"\n\n說明:算法是原創(chuàng)的,所以電腦智商不高……作者QQ754829466有意見歡迎說明";
  117. if (_root.now == true) {
  118.   var chesses:Array = chess;
  119.   var yes = 0;
  120.   yi = 5;
  121.   yj = 5;
  122.   for (i=0; i<11; i++) {
  123.    for (j=0; j<11; j++) {
  124.     var yes2 = 0;
  125.     if (chesses[i][j] == 0) {
  126.      chesses[i][j] = 2;
  127.      for (c=-1; c<5; c++) {
  128.       if (chesses[i+c][j] == 2) {
  129.        if (chesses[i-1][j] != 1 and chesses[i+c+2][j] != 1) {
  130.         yes2 += gong;
  131.        }
  132.       }
  133.       if (chesses[i-c][j] == 2) {
  134.        if (chesses[i+1][j] != 1 and chesses[i-c+2][j] != 1) {
  135.         yes2 += gong;
  136.        }
  137.       }
  138.       if (chesses[i][j+c] == 2) {
  139.        if (chesses[i][j-1] != 1 and chesses[i][j+c+2] != 1) {
  140.         yes2 += gong;
  141.        }
  142.       }
  143.       if (chesses[i][j-c] == 2) {
  144.        if (chesses[i][j+1] != 1 and chesses[i][j-c+2] != 1) {
  145.         yes2 += gong;
  146.        }
  147.       }
  148.       if (chesses[i+c][j+c] == 2) {
  149.        if (chesses[i-1][j-1] != 1 and chesses[i+c+2][j+c+2] != 1) {
  150.         yes2 += gong;
  151.        }
  152.       }
  153.       if (chesses[i-c][j+c] == 2) {
  154.        if (chesses[i+1][j-1] != 1 and chesses[i-c+2][j+c+2] != 1) {
  155.         yes2 += gong;
  156.        }
  157.       }
  158.       if (chesses[i+c][j-c] == 2) {
  159.        if (chesses[i-1][j+1] != 1 and chesses[i-c+2][j+c+2] != 1) {
  160.         yes2 += gong;
  161.        }
  162.       }
  163.       if (chesses[i-c][j-c] == 2) {
  164.        if (chesses[i+1][j+1] != 1 and chesses[i+c+2][j-c+2] != 1) {
  165.         yes2 += gong;
  166.        }
  167.       }
  168.       for (k=0; k<3; k++) {
  169.        if (chesses[i][j] == 2) {
  170.         for (r=0; r<5; r++) {
  171.          if (chesses[i+r][j] == k) {
  172.           if (r == 4) {
  173.            yes2 += 100;
  174.           }
  175.          } else {
  176.           break;
  177.          }
  178.         }
  179.         for (r=0; r<5; r++) {
  180.          if (chesses[i-r][j] == k) {
  181.           if (r == 4) {
  182.            yes2 += 100;
  183.           }
  184.          } else {
  185.           break;
  186.          }
  187.         }
  188.         for (r=0; r<5; r++) {
  189.          if (chesses[i-r][j-r] == k) {
  190.           if (r == 4) {
  191.            yes2 += 100;
  192.           }
  193.          } else {
  194.           break;
  195.          }
  196.         }
  197.         for (r=0; r<5; r++) {
  198.          if (chesses[i][j-r] == k) {
  199.           if (r == 4) {
  200.            yes2 += 100;
  201.           }
  202.          } else {
  203.           break;
  204.          }
  205.         }
  206.         for (r=0; r<5; r++) {
  207.          if (chesses[i-r][j+r] == k) {
  208.           if (r == 4) {
  209.            yes2 += 100;
  210.           }
  211.          } else {
  212.           break;
  213.          }
  214.         }
  215.         for (r=0; r<5; r++) {
  216.          if (chesses[i][j+r] == k) {
  217.           if (r == 4) {
  218.            yes2 += 100;
  219.           }
  220.          } else {
  221.           break;
  222.          }
  223.         }
  224.         for (r=0; r<5; r++) {
  225.          if (chesses[i+r][j+r] == k) {
  226.           if (r == 4) {
  227.            yes2 += 100;
  228.           }
  229.          } else {
  230.           break;
  231.          }
  232.         }
  233.        }
  234.       }
  235.      }
  236.      for (c=1; c<5; c++) {
  237.       if (chesses[i+c][j] == 1) {
  238.        yes2 += fang;
  239.       }
  240.       if (chesses[i-c][j] == 1) {
  241.        yes2 += fang;
  242.       }
  243.       if (chesses[i][j+c] == 1) {
  244.        yes2 += fang;
  245.       }
  246.       if (chesses[i][j-c] == 1) {
  247.        yes2 += fang;
  248.       }
  249.       if (chesses[i+c][j+c] == 1) {
  250.        yes2 += fang;
  251.       }
  252.       if (chesses[i-c][j+c] == 1) {
  253.        yes2 += fang;
  254.       }
  255.       if (chesses[i+c][j-c] == 1) {
  256.        yes2 += fang;
  257.       }
  258.       if (chesses[i-c][j-c] == 1) {
  259.        yes2 += fang;
  260.       }
  261.      }
  262.      for (r=1; r<5; r++) {
  263.       if (chesses[i+r][j] == 1) {
  264.        if (r == 3) {
  265.         yes2 += 5*fang;
  266.        } else if (r == 4) {
  267.         yes2 += fang*10;
  268.        }
  269.       } else {
  270.        break;
  271.       }
  272.      }
  273.      for (r=1; r<5; r++) {
  274.       if (chesses[i+r][j+r] == 1) {
  275.        if (r == 3) {
  276.         yes2 += 5*fang;
  277.        } else if (r == 4) {
  278.         yes2 += fang*10;
  279.        }
  280.       } else {
  281.        break;
  282.       }
  283.      }
  284.      for (r=1; r<5; r++) {
  285.       if (chesses[i+r][j-r] == 1) {
  286.        if (r == 3) {
  287.         yes2 += 5*fang;
  288.        } else if (r == 4) {
  289.         yes2 += fang*10;
  290.        }
  291.       } else {
  292.        break;
  293.       }
  294.      }
  295.      for (r=1; r<5; r++) {
  296.       if (chesses[i-r][j] == 1) {
  297.        if (r == 3) {
  298.         yes2 += 5*fang;
  299.        } else if (r == 4) {
  300.         yes2 += fang*10;
  301.        }
  302.       } else {
  303.        break;
  304.       }
  305.      }
  306.      for (r=1; r<5; r++) {
  307.       if (chesses[i-r][j+r] == 1) {
  308.        if (r == 3) {
  309.         yes2 += 5*fang;
  310.        } else if (r == 4) {
  311.         yes2 += fang*10;
  312.        }
  313.       } else {
  314.        break;
  315.       }
  316.      }
  317.      for (r=1; r<5; r++) {
  318.       if (chesses[i-r][j-r] == 1) {
  319.        if (r == 3) {
  320.         yes2 += 5*fang;
  321.        } else if (r == 4) {
  322.         yes2 += fang*10;
  323.        }
  324.       } else {
  325.        break;
  326.       }
  327.      }
  328.      for (r=1; r<5; r++) {
  329.       if (chesses[i][j+r] == 1) {
  330.        if (r == 3) {
  331.         yes2 += 5*fang;
  332.        } else if (r == 4) {
  333.         yes2 += fang*10;
  334.        }
  335.       } else {
  336.        break;
  337.       }
  338.      }
  339.      for (r=1; r<5; r++) {
  340.       if (chesses[i][j-r] == 1) {
  341.        if (r == 3) {
  342.         yes2 += 5*fang;
  343.        } else if (r == 4) {
  344.         yes2 += fang*10;
  345.        }
  346.       } else {
  347.        break;
  348.       }
  349.      }
  350.      chesses[i][j] = 0;
  351.      if (yes2>yes) {
  352.       yes = yes2;
  353.       yi = i;
  354.       yj = j;
  355.      }
  356.     }
  357.    }
  358.   }
  359.   _root.cd(yi, yj);
  360. }
  361. };
  362. function huiqi() {
  363. if (_root.hh>=1) {
  364.   trace("悔棋");
  365.   ci = _root.comi[_root.hh];
  366.   cj = _root.comj[_root.hh];
  367.   di = _root.desi[_root.hh];
  368.   dj = _root.desj[_root.hh];
  369.   _root.chess[ci][cj] = 0;
  370.   _root.comi[_root.hh] = null;
  371.   _root.comj[_root.hh] = null;
  372.   _root["black_"+ci+"_"+cj].removeMovieClip();
  373.   _root.chess[di][dj] = 0;
  374.   _root.desi[_root.hh] = null;
  375.   _root.desj[_root.hh] = null;
  376.   _root["white_"+di+"_"+dj].removeMovieClip();
  377.   _root.hh--;
  378.   _root.mi--;
  379.   _root.now = false;
  380. }
  381. }
  382. function see() {
  383. for (si=0; si<_root.hh; si++) {
  384.   trace([comi[si], comj[si]]+"|"+[desi[si], desj[si]]);
  385. }
  386. trace("第"+hh+"回合,當前棋局:");
  387. for (i=0; i<16; i++) {
  388.   trace(_root.chess[i]);
  389. }
  390. }
  391. _root.menu = right_menu;
復制代碼

回復

使用道具 舉報

ID:311080 發(fā)表于 2018-5-17 16:35 | 顯示全部樓層
您好,這個是個是給單片機里面寫的程序碼
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 99久久久久久 | 久久久久国产一级毛片高清网站 | 羞羞视频免费观看 | 国产精品毛片一区二区在线看 | 欧美精品网| 日日夜夜精品免费视频 | 国产我和子的乱视频网站 | 日韩精品人成在线播放 | 国产精品久久久久无码av | 91一区二区 | 国产精品视频一区二区三区四蜜臂 | 黄色片在线 | 国产日韩精品久久 | jdav视频在线观看免费 | 99国内精品| 中文字幕av亚洲精品一部二部 | 91资源在线 | zzzwww在线看片免费 | 九九99精品 | av黄色国产 | 北条麻妃99精品青青久久 | 成人激情视频免费观看 | 国产色婷婷精品综合在线播放 | 亚洲午夜视频在线观看 | www日本在线 | 欧美日韩精品中文字幕 | 美女一级a毛片免费观看97 | 天天操夜夜操免费视频 | 国产精品视频免费观看 | 成人亚洲| 羞羞网站在线观看 | 高清成人av | 日韩一区二区av | 欧美成人精品一区二区男人看 | 人操人免费视频 | 亚洲一区二区黄 | 中国xxxx性xxxx产国 | 丁香婷婷久久久综合精品国产 | 亚洲国产一区二区三区 | 精品成人免费一区二区在线播放 | 日韩精品在线免费 |