├── LICENSE ├── README.md ├── audio ├── click.wav └── select.wav ├── css └── chess.css ├── favicon.ico ├── icon.png ├── img ├── btn_bg.png ├── btn_fh.png ├── init_bg.png ├── stype_1 │ ├── b_box.png │ ├── b_c.png │ ├── b_j.png │ ├── b_m.png │ ├── b_p.png │ ├── b_s.png │ ├── b_x.png │ ├── b_z.png │ ├── bg.jpg │ ├── bg.png │ ├── dot.png │ ├── r_box.png │ ├── r_c.png │ ├── r_j.png │ ├── r_m.png │ ├── r_p.png │ ├── r_s.png │ ├── r_x.png │ └── r_z.png ├── stype_2 │ ├── b_c.png │ ├── b_j.png │ ├── b_m.png │ ├── b_p.png │ ├── b_s.png │ ├── b_x.png │ ├── b_z.png │ ├── bg.jpg │ ├── bg.png │ ├── dot.png │ ├── r_box.png │ ├── r_c.png │ ├── r_j.png │ ├── r_m.png │ ├── r_p.png │ ├── r_s.png │ ├── r_x.png │ └── r_z.png └── stype_3 │ ├── b_box.png │ ├── b_c.png │ ├── b_j.png │ ├── b_m.png │ ├── b_p.png │ ├── b_s.png │ ├── b_x.png │ ├── b_z.png │ ├── bg.jpg │ ├── bg.png │ ├── bg1.jpg │ ├── bg2.jpg │ ├── dot.png │ ├── r_box.png │ ├── r_c.png │ ├── r_j.png │ ├── r_m.png │ ├── r_p.png │ ├── r_s.png │ ├── r_x.png │ └── r_z.png ├── index.html └── js ├── AI.js ├── bill.js ├── clasli.js ├── common.js ├── gambit.all.js ├── gambit.js └── play.js /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 liwei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 中国象棋 - in html5 2 | =========== 3 | 4 | 作者:一叶孤舟
5 | 联系:itlwei@163.com QQ:28701884
6 | Demo:https://itlwei.github.io/Chess/ 7 | 8 | 中国象棋 - in html5是一款使用html5 canvas开发的开源小游戏,不依赖任何类库,不依赖任何后台程序,全部原生Javascript进行AI计算,欢迎广大业内同行多多交流指正,共同完善。 9 | 10 | ##特点 11 | 12 | * 全部使用Javascript完成AI人工智能计算,不依赖任何后台程序 13 | * 不依赖任何类库,全部原生Javascript,使用html5 canvas. 14 | * 实现中不涉及任何浏览器特性,所以不存在浏览器兼容性问题. 15 | * 代码结构极其简洁明了,你可以轻易的阅读,修改成自己版本. 16 | 17 | ##Change Log 18 | ### v1.5.1 19 | * 修复BUG 20 | 21 | ### v1.5.0 22 | * 大幅度修改UI,增加风格选择 23 | 24 | ### v1.0.3 25 | * 增加历史表,提高AI计算效率 26 | 27 | ### v1.0.2 28 | * 修复了AI计算过深的资源耗尽问题 29 | 30 | ### v1.0.1 31 | * 修复了一些情况下悔棋出错的问题 32 | * 修复了长将不死的问题 33 | -------------------------------------------------------------------------------- /audio/click.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/audio/click.wav -------------------------------------------------------------------------------- /audio/select.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/audio/select.wav -------------------------------------------------------------------------------- /css/chess.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/css/chess.css -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/favicon.ico -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/icon.png -------------------------------------------------------------------------------- /img/btn_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/btn_bg.png -------------------------------------------------------------------------------- /img/btn_fh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/btn_fh.png -------------------------------------------------------------------------------- /img/init_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/init_bg.png -------------------------------------------------------------------------------- /img/stype_1/b_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/b_box.png -------------------------------------------------------------------------------- /img/stype_1/b_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/b_c.png -------------------------------------------------------------------------------- /img/stype_1/b_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/b_j.png -------------------------------------------------------------------------------- /img/stype_1/b_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/b_m.png -------------------------------------------------------------------------------- /img/stype_1/b_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/b_p.png -------------------------------------------------------------------------------- /img/stype_1/b_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/b_s.png -------------------------------------------------------------------------------- /img/stype_1/b_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/b_x.png -------------------------------------------------------------------------------- /img/stype_1/b_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/b_z.png -------------------------------------------------------------------------------- /img/stype_1/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/bg.jpg -------------------------------------------------------------------------------- /img/stype_1/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/bg.png -------------------------------------------------------------------------------- /img/stype_1/dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/dot.png -------------------------------------------------------------------------------- /img/stype_1/r_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/r_box.png -------------------------------------------------------------------------------- /img/stype_1/r_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/r_c.png -------------------------------------------------------------------------------- /img/stype_1/r_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/r_j.png -------------------------------------------------------------------------------- /img/stype_1/r_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/r_m.png -------------------------------------------------------------------------------- /img/stype_1/r_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/r_p.png -------------------------------------------------------------------------------- /img/stype_1/r_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/r_s.png -------------------------------------------------------------------------------- /img/stype_1/r_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/r_x.png -------------------------------------------------------------------------------- /img/stype_1/r_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_1/r_z.png -------------------------------------------------------------------------------- /img/stype_2/b_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/b_c.png -------------------------------------------------------------------------------- /img/stype_2/b_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/b_j.png -------------------------------------------------------------------------------- /img/stype_2/b_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/b_m.png -------------------------------------------------------------------------------- /img/stype_2/b_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/b_p.png -------------------------------------------------------------------------------- /img/stype_2/b_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/b_s.png -------------------------------------------------------------------------------- /img/stype_2/b_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/b_x.png -------------------------------------------------------------------------------- /img/stype_2/b_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/b_z.png -------------------------------------------------------------------------------- /img/stype_2/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/bg.jpg -------------------------------------------------------------------------------- /img/stype_2/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/bg.png -------------------------------------------------------------------------------- /img/stype_2/dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/dot.png -------------------------------------------------------------------------------- /img/stype_2/r_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/r_box.png -------------------------------------------------------------------------------- /img/stype_2/r_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/r_c.png -------------------------------------------------------------------------------- /img/stype_2/r_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/r_j.png -------------------------------------------------------------------------------- /img/stype_2/r_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/r_m.png -------------------------------------------------------------------------------- /img/stype_2/r_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/r_p.png -------------------------------------------------------------------------------- /img/stype_2/r_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/r_s.png -------------------------------------------------------------------------------- /img/stype_2/r_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/r_x.png -------------------------------------------------------------------------------- /img/stype_2/r_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_2/r_z.png -------------------------------------------------------------------------------- /img/stype_3/b_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/b_box.png -------------------------------------------------------------------------------- /img/stype_3/b_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/b_c.png -------------------------------------------------------------------------------- /img/stype_3/b_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/b_j.png -------------------------------------------------------------------------------- /img/stype_3/b_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/b_m.png -------------------------------------------------------------------------------- /img/stype_3/b_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/b_p.png -------------------------------------------------------------------------------- /img/stype_3/b_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/b_s.png -------------------------------------------------------------------------------- /img/stype_3/b_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/b_x.png -------------------------------------------------------------------------------- /img/stype_3/b_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/b_z.png -------------------------------------------------------------------------------- /img/stype_3/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/bg.jpg -------------------------------------------------------------------------------- /img/stype_3/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/bg.png -------------------------------------------------------------------------------- /img/stype_3/bg1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/bg1.jpg -------------------------------------------------------------------------------- /img/stype_3/bg2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/bg2.jpg -------------------------------------------------------------------------------- /img/stype_3/dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/dot.png -------------------------------------------------------------------------------- /img/stype_3/r_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/r_box.png -------------------------------------------------------------------------------- /img/stype_3/r_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/r_c.png -------------------------------------------------------------------------------- /img/stype_3/r_j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/r_j.png -------------------------------------------------------------------------------- /img/stype_3/r_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/r_m.png -------------------------------------------------------------------------------- /img/stype_3/r_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/r_p.png -------------------------------------------------------------------------------- /img/stype_3/r_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/r_s.png -------------------------------------------------------------------------------- /img/stype_3/r_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/r_x.png -------------------------------------------------------------------------------- /img/stype_3/r_z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlwei/Chess/e8b4c0fea5220e08528286b157caa8f884f62505/img/stype_3/r_z.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 中国象棋 in html5 6 | 7 | 8 | 11 | 12 | 13 |
14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 |
22 |
23 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /js/AI.js: -------------------------------------------------------------------------------- 1 | /*! 一叶孤舟 | qq:28701884 | 欢迎指教 */ 2 | 3 | var AI = AI||{}; 4 | 5 | AI.historyTable = {}; //历史表 6 | 7 | 8 | //人工智能初始化 9 | AI.init = function(pace){ 10 | var bill = AI.historyBill || com.gambit; //开局库 11 | if (bill.length){ 12 | var len=pace.length; 13 | var arr=[]; 14 | //先搜索棋谱 15 | for (var i=0;i< bill.length;i++){ 16 | if (bill[i].slice(0,len)==pace) { 17 | arr.push(bill[i]); 18 | } 19 | } 20 | if (arr.length){ 21 | var inx=Math.floor( Math.random() * arr.length ); 22 | AI.historyBill = arr ; 23 | return arr[inx].slice(len,len+4).split(""); 24 | }else{ 25 | AI.historyBill = [] ; 26 | } 27 | 28 | } 29 | //如果棋谱里面没有,人工智能开始运作 30 | var initTime = new Date().getTime(); 31 | AI.treeDepth=play.depth; 32 | //AI.treeDepth=4; 33 | 34 | AI.number=0; 35 | AI.setHistoryTable.lenght = 0 36 | 37 | var val=AI.getAlphaBeta(-99999 ,99999, AI.treeDepth, com.arr2Clone(play.map),play.my); 38 | //var val = AI.iterativeSearch(com.arr2Clone(play.map),play.my) 39 | if (!val||val.value==-8888) { 40 | AI.treeDepth=2; 41 | val=AI.getAlphaBeta(-99999 ,99999, AI.treeDepth, com.arr2Clone(play.map),play.my); 42 | } 43 | //var val = AI.iterativeSearch(com.arr2Clone(play.map),play.my); 44 | if (val&&val.value!=-8888) { 45 | var man = play.mans[val.key]; 46 | var nowTime= new Date().getTime(); 47 | console.log('最佳着法:'+ 48 | com.createMove(com.arr2Clone(play.map),man.x,man.y,val.x,val.y)+ 49 | ' 搜索深度:'+AI.treeDepth+' 搜索分支:'+ 50 | AI.number+'个 最佳着法评估:'+ 51 | val.value+'分'+ 52 | ' 搜索用时:'+ 53 | (nowTime-initTime)+'毫秒') 54 | return [man.x,man.y,val.x,val.y] 55 | }else { 56 | return false; 57 | } 58 | } 59 | 60 | //迭代加深搜索着法 61 | AI.iterativeSearch = function (map, my){ 62 | var timeOut=100; 63 | var initDepth = 1; 64 | var maxDepth = 8; 65 | AI.treeDepth=0; 66 | var initTime = new Date().getTime(); 67 | var val = {}; 68 | for (var i=initDepth; i<=maxDepth; i++){ 69 | var nowTime= new Date().getTime(); 70 | AI.treeDepth=i; 71 | AI.aotuDepth=i; 72 | var val = AI.getAlphaBeta(-99999, 99999, AI.treeDepth , map ,my) 73 | if (nowTime-initTime > timeOut){ 74 | return val; 75 | } 76 | } 77 | return false; 78 | } 79 | 80 | //取得棋盘上所有棋子 81 | AI.getMapAllMan = function (map, my){ 82 | var mans=[]; 83 | for (var i=0; i= AI.treeDepth-depth+1){ 123 | // return history.value*my; 124 | //} 125 | if (depth == 0) { 126 | return {"value":AI.evaluate(map , my)}; //局面评价函数; 127 |   } 128 |   var moves = AI.getMoves(map , my ); //生成全部走法; 129 |   //这里排序以后会增加效率 130 | 131 | for (var i=0; i < moves.length; i++) { 132 | 133 | 134 |    //走这个走法; 135 | var move= moves[i]; 136 | var key = move[4]; 137 | var oldX= move[0]; 138 | var oldY= move[1]; 139 | var newX= move[2]; 140 | var newY= move[3]; 141 | var clearKey = map[ newY ][ newX ]||""; 142 | 143 | map[ newY ][ newX ] = key; 144 | delete map[ oldY ][ oldX ]; 145 | play.mans[key].x = newX; 146 | play.mans[key].y = newY; 147 | 148 |   if (clearKey=="j0"||clearKey=="J0") {//被吃老将,撤消这个走法; 149 | play.mans[key] .x = oldX; 150 | play.mans[key] .y = oldY; 151 | map[ oldY ][ oldX ] = key; 152 | delete map[ newY ][ newX ]; 153 | if (clearKey){ 154 | map[ newY ][ newX ] = clearKey; 155 | // play.mans[ clearKey ].isShow = false; 156 | } 157 | 158 | return {"key":key,"x":newX,"y":newY,"value":8888}; 159 | //return rootKey; 160 |   }else { 161 |    var val = -AI.getAlphaBeta(-B, -A, depth - 1, map , -my).value; 162 | //val = val || val.value; 163 | 164 |    //撤消这个走法;  165 | play.mans[key] .x = oldX; 166 | play.mans[key] .y = oldY; 167 | map[ oldY ][ oldX ] = key; 168 | delete map[ newY ][ newX ]; 169 | if (clearKey){ 170 | map[ newY ][ newX ] = clearKey; 171 | //play.mans[ clearKey ].isShow = true; 172 | } 173 |    if (val >= B) { 174 | //将这个走法记录到历史表中; 175 | //AI.setHistoryTable(txtMap,AI.treeDepth-depth+1,B,my); 176 | return {"key":key,"x":newX,"y":newY,"value":B}; 177 | } 178 | if (val > A) { 179 |      A = val; //设置最佳走法; 180 | if (AI.treeDepth == depth) var rootKey={"key":key,"x":newX,"y":newY,"value":A}; 181 | } 182 | } 183 |   } 184 | //将这个走法记录到历史表中; 185 | //AI.setHistoryTable(txtMap,AI.treeDepth-depth+1,A,my); 186 | if (AI.treeDepth == depth) {//已经递归回根了 187 | if (!rootKey){ 188 | //AI没有最佳走法,说明AI被将死了,返回false 189 | return false; 190 | }else{ 191 | //这个就是最佳走法; 192 | return rootKey; 193 | } 194 | } 195 |  return {"key":key,"x":newX,"y":newY,"value":A}; 196 | } 197 | 198 | //奖着法记录到历史表 199 | AI.setHistoryTable = function (txtMap,depth,value,my){ 200 | AI.setHistoryTable.lenght ++; 201 | AI.historyTable[txtMap] = {depth:depth,value:value} 202 | } 203 | 204 | //评估棋局 取得棋盘双方棋子价值差 205 | AI.evaluate = function (map,my){ 206 | var val=0; 207 | for (var i=0; i'; 79 | var x = bl[i+0]; 80 | var y = bl[i+1]; 81 | var newX = bl[i+2]; 82 | var newY = bl[i+3]; 83 | h += com.createMove(map,x,y,newX,newY); 84 | h +='\n\r'; 85 | } 86 | com.get("billBox").innerHTML = h; 87 | 88 | var doms=com.get("billBox").getElementsByTagName("li"); 89 | 90 | for (var i=0; i=5) clearInterval(timer); 161 | },2000); 162 | }) 163 | 164 | //获取单选框选择的值 165 | function getRadioValue (name){ 166 | var obj = document.getElementsByName(name); 167 | //var obj = document.getElementsByTagName("input"); 168 | for(var i=0; i0){ 274 | start=document.cookie.indexOf(name + "=") 275 | if (start!=-1){ 276 | start=start + name.length+1 277 | end=document.cookie.indexOf(";",start) 278 | if (end==-1) end=document.cookie.length 279 | return unescape(document.cookie.substring(start,end)) 280 | } 281 | } 282 | return false; 283 | } 284 | //二维数组克隆 285 | com.arr2Clone = function (arr){ 286 | var newArr=[]; 287 | for (var i=0; i y) { 326 | h+= "退"; 327 | if (man.pater == "m" || man.pater == "s" || man.pater == "x"){ 328 | h+= mumTo[newX]; 329 | }else { 330 | h+= mumTo[newY - y -1]; 331 | } 332 | }else if (newY < y) { 333 | h+= "进"; 334 | if (man.pater == "m" || man.pater == "s" || man.pater == "x"){ 335 | h+= mumTo[newX]; 336 | }else { 337 | h+= mumTo[y - newY -1]; 338 | } 339 | }else { 340 | h+= "平"; 341 | h+= mumTo[newX]; 342 | } 343 | }else{ 344 | var mumTo=["1","2","3","4","5","6","7","8","9","10"]; 345 | h+= mumTo[x]; 346 | if (newY > y) { 347 | h+= "进"; 348 | if (man.pater == "M" || man.pater == "S" || man.pater == "X"){ 349 | h+= mumTo[newX]; 350 | }else { 351 | h+= mumTo[newY - y-1]; 352 | } 353 | }else if (newY < y) { 354 | h+= "退"; 355 | if (man.pater == "M" || man.pater == "S" || man.pater == "X"){ 356 | h+= mumTo[newX]; 357 | }else { 358 | h+= mumTo[y - newY-1]; 359 | } 360 | }else { 361 | h+= "平"; 362 | h+= mumTo[newX]; 363 | } 364 | } 365 | return h; 366 | } 367 | 368 | com.initMap = [ 369 | ['C0','M0','X0','S0','J0','S1','X1','M1','C1'], 370 | [ , , , , , , , , ], 371 | [ ,'P0', , , , , ,'P1', ], 372 | ['Z0', ,'Z1', ,'Z2', ,'Z3', ,'Z4'], 373 | [ , , , , , , , , ], 374 | [ , , , , , , , , ], 375 | ['z0', ,'z1', ,'z2', ,'z3', ,'z4'], 376 | [ ,'p0', , , , , ,'p1', ], 377 | [ , , , , , , , , ], 378 | ['c0','m0','x0','s0','j0','s1','x1','m1','c1'] 379 | ]; 380 | 381 | com.keys = { 382 | "c0":"c","c1":"c", 383 | "m0":"m","m1":"m", 384 | "x0":"x","x1":"x", 385 | "s0":"s","s1":"s", 386 | "j0":"j", 387 | "p0":"p","p1":"p", 388 | "z0":"z","z1":"z","z2":"z","z3":"z","z4":"z","z5":"z", 389 | 390 | "C0":"c","C1":"C", 391 | "M0":"M","M1":"M", 392 | "X0":"X","X1":"X", 393 | "S0":"S","S1":"S", 394 | "J0":"J", 395 | "P0":"P","P1":"P", 396 | "Z0":"Z","Z1":"Z","Z2":"Z","Z3":"Z","Z4":"Z","Z5":"Z", 397 | } 398 | 399 | //棋子能走的着点 400 | com.bylaw ={} 401 | //车 402 | com.bylaw.c = function (x,y,map,my){ 403 | var d=[]; 404 | //左侧检索 405 | for (var i=x-1; i>= 0; i--){ 406 | if (map[y][i]) { 407 | if (com.mans[map[y][i]].my!=my) d.push([i,y]); 408 | break 409 | }else{ 410 | d.push([i,y]) 411 | } 412 | } 413 | //右侧检索 414 | for (var i=x+1; i <= 8; i++){ 415 | if (map[y][i]) { 416 | if (com.mans[map[y][i]].my!=my) d.push([i,y]); 417 | break 418 | }else{ 419 | d.push([i,y]) 420 | } 421 | } 422 | //上检索 423 | for (var i = y-1 ; i >= 0; i--){ 424 | if (map[i][x]) { 425 | if (com.mans[map[i][x]].my!=my) d.push([x,i]); 426 | break 427 | }else{ 428 | d.push([x,i]) 429 | } 430 | } 431 | //下检索 432 | for (var i = y+1 ; i<= 9; i++){ 433 | if (map[i][x]) { 434 | if (com.mans[map[i][x]].my!=my) d.push([x,i]); 435 | break 436 | }else{ 437 | d.push([x,i]) 438 | } 439 | } 440 | return d; 441 | } 442 | 443 | //马 444 | com.bylaw.m = function (x,y,map,my){ 445 | var d=[]; 446 | //1点 447 | if ( y-2>= 0 && x+1<= 8 && !play.map[y-1][x] &&(!com.mans[map[y-2][x+1]] || com.mans[map[y-2][x+1]].my!=my)) d.push([x+1,y-2]); 448 | //2点 449 | if ( y-1>= 0 && x+2<= 8 && !play.map[y][x+1] &&(!com.mans[map[y-1][x+2]] || com.mans[map[y-1][x+2]].my!=my)) d.push([x+2,y-1]); 450 | //4点 451 | if ( y+1<= 9 && x+2<= 8 && !play.map[y][x+1] &&(!com.mans[map[y+1][x+2]] || com.mans[map[y+1][x+2]].my!=my)) d.push([x+2,y+1]); 452 | //5点 453 | if ( y+2<= 9 && x+1<= 8 && !play.map[y+1][x] &&(!com.mans[map[y+2][x+1]] || com.mans[map[y+2][x+1]].my!=my)) d.push([x+1,y+2]); 454 | //7点 455 | if ( y+2<= 9 && x-1>= 0 && !play.map[y+1][x] &&(!com.mans[map[y+2][x-1]] || com.mans[map[y+2][x-1]].my!=my)) d.push([x-1,y+2]); 456 | //8点 457 | if ( y+1<= 9 && x-2>= 0 && !play.map[y][x-1] &&(!com.mans[map[y+1][x-2]] || com.mans[map[y+1][x-2]].my!=my)) d.push([x-2,y+1]); 458 | //10点 459 | if ( y-1>= 0 && x-2>= 0 && !play.map[y][x-1] &&(!com.mans[map[y-1][x-2]] || com.mans[map[y-1][x-2]].my!=my)) d.push([x-2,y-1]); 460 | //11点 461 | if ( y-2>= 0 && x-1>= 0 && !play.map[y-1][x] &&(!com.mans[map[y-2][x-1]] || com.mans[map[y-2][x-1]].my!=my)) d.push([x-1,y-2]); 462 | 463 | return d; 464 | } 465 | 466 | //相 467 | com.bylaw.x = function (x,y,map,my){ 468 | var d=[]; 469 | if (my===1){ //红方 470 | //4点半 471 | if ( y+2<= 9 && x+2<= 8 && !play.map[y+1][x+1] && (!com.mans[map[y+2][x+2]] || com.mans[map[y+2][x+2]].my!=my)) d.push([x+2,y+2]); 472 | //7点半 473 | if ( y+2<= 9 && x-2>= 0 && !play.map[y+1][x-1] && (!com.mans[map[y+2][x-2]] || com.mans[map[y+2][x-2]].my!=my)) d.push([x-2,y+2]); 474 | //1点半 475 | if ( y-2>= 5 && x+2<= 8 && !play.map[y-1][x+1] && (!com.mans[map[y-2][x+2]] || com.mans[map[y-2][x+2]].my!=my)) d.push([x+2,y-2]); 476 | //10点半 477 | if ( y-2>= 5 && x-2>= 0 && !play.map[y-1][x-1] && (!com.mans[map[y-2][x-2]] || com.mans[map[y-2][x-2]].my!=my)) d.push([x-2,y-2]); 478 | }else{ 479 | //4点半 480 | if ( y+2<= 4 && x+2<= 8 && !play.map[y+1][x+1] && (!com.mans[map[y+2][x+2]] || com.mans[map[y+2][x+2]].my!=my)) d.push([x+2,y+2]); 481 | //7点半 482 | if ( y+2<= 4 && x-2>= 0 && !play.map[y+1][x-1] && (!com.mans[map[y+2][x-2]] || com.mans[map[y+2][x-2]].my!=my)) d.push([x-2,y+2]); 483 | //1点半 484 | if ( y-2>= 0 && x+2<= 8 && !play.map[y-1][x+1] && (!com.mans[map[y-2][x+2]] || com.mans[map[y-2][x+2]].my!=my)) d.push([x+2,y-2]); 485 | //10点半 486 | if ( y-2>= 0 && x-2>= 0 && !play.map[y-1][x-1] && (!com.mans[map[y-2][x-2]] || com.mans[map[y-2][x-2]].my!=my)) d.push([x-2,y-2]); 487 | } 488 | return d; 489 | } 490 | 491 | //士 492 | com.bylaw.s = function (x,y,map,my){ 493 | var d=[]; 494 | if (my===1){ //红方 495 | //4点半 496 | if ( y+1<= 9 && x+1<= 5 && (!com.mans[map[y+1][x+1]] || com.mans[map[y+1][x+1]].my!=my)) d.push([x+1,y+1]); 497 | //7点半 498 | if ( y+1<= 9 && x-1>= 3 && (!com.mans[map[y+1][x-1]] || com.mans[map[y+1][x-1]].my!=my)) d.push([x-1,y+1]); 499 | //1点半 500 | if ( y-1>= 7 && x+1<= 5 && (!com.mans[map[y-1][x+1]] || com.mans[map[y-1][x+1]].my!=my)) d.push([x+1,y-1]); 501 | //10点半 502 | if ( y-1>= 7 && x-1>= 3 && (!com.mans[map[y-1][x-1]] || com.mans[map[y-1][x-1]].my!=my)) d.push([x-1,y-1]); 503 | }else{ 504 | //4点半 505 | if ( y+1<= 2 && x+1<= 5 && (!com.mans[map[y+1][x+1]] || com.mans[map[y+1][x+1]].my!=my)) d.push([x+1,y+1]); 506 | //7点半 507 | if ( y+1<= 2 && x-1>= 3 && (!com.mans[map[y+1][x-1]] || com.mans[map[y+1][x-1]].my!=my)) d.push([x-1,y+1]); 508 | //1点半 509 | if ( y-1>= 0 && x+1<= 5 && (!com.mans[map[y-1][x+1]] || com.mans[map[y-1][x+1]].my!=my)) d.push([x+1,y-1]); 510 | //10点半 511 | if ( y-1>= 0 && x-1>= 3 && (!com.mans[map[y-1][x-1]] || com.mans[map[y-1][x-1]].my!=my)) d.push([x-1,y-1]); 512 | } 513 | return d; 514 | 515 | } 516 | 517 | //将 518 | com.bylaw.j = function (x,y,map,my){ 519 | var d=[]; 520 | var isNull=(function (y1,y2){ 521 | var y1=com.mans["j0"].y; 522 | var x1=com.mans["J0"].x; 523 | var y2=com.mans["J0"].y; 524 | for (var i=y1-1; i>y2; i--){ 525 | if (map[i][x1]) return false; 526 | } 527 | return true; 528 | })(); 529 | 530 | if (my===1){ //红方 531 | //下 532 | if ( y+1<= 9 && (!com.mans[map[y+1][x]] || com.mans[map[y+1][x]].my!=my)) d.push([x,y+1]); 533 | //上 534 | if ( y-1>= 7 && (!com.mans[map[y-1][x]] || com.mans[map[y-1][x]].my!=my)) d.push([x,y-1]); 535 | //老将对老将的情况 536 | if ( com.mans["j0"].x == com.mans["J0"].x &&isNull) d.push([com.mans["J0"].x,com.mans["J0"].y]); 537 | 538 | }else{ 539 | //下 540 | if ( y+1<= 2 && (!com.mans[map[y+1][x]] || com.mans[map[y+1][x]].my!=my)) d.push([x,y+1]); 541 | //上 542 | if ( y-1>= 0 && (!com.mans[map[y-1][x]] || com.mans[map[y-1][x]].my!=my)) d.push([x,y-1]); 543 | //老将对老将的情况 544 | if ( com.mans["j0"].x == com.mans["J0"].x &&isNull) d.push([com.mans["j0"].x,com.mans["j0"].y]); 545 | } 546 | //右 547 | if ( x+1<= 5 && (!com.mans[map[y][x+1]] || com.mans[map[y][x+1]].my!=my)) d.push([x+1,y]); 548 | //左 549 | if ( x-1>= 3 && (!com.mans[map[y][x-1]] || com.mans[map[y][x-1]].my!=my))d.push([x-1,y]); 550 | return d; 551 | } 552 | 553 | //炮 554 | com.bylaw.p = function (x,y,map,my){ 555 | var d=[]; 556 | //左侧检索 557 | var n=0; 558 | for (var i=x-1; i>= 0; i--){ 559 | if (map[y][i]) { 560 | if (n==0){ 561 | n++; 562 | continue; 563 | }else{ 564 | if (com.mans[map[y][i]].my!=my) d.push([i,y]); 565 | break 566 | } 567 | }else{ 568 | if(n==0) d.push([i,y]) 569 | } 570 | } 571 | //右侧检索 572 | var n=0; 573 | for (var i=x+1; i <= 8; i++){ 574 | if (map[y][i]) { 575 | if (n==0){ 576 | n++; 577 | continue; 578 | }else{ 579 | if (com.mans[map[y][i]].my!=my) d.push([i,y]); 580 | break 581 | } 582 | }else{ 583 | if(n==0) d.push([i,y]) 584 | } 585 | } 586 | //上检索 587 | var n=0; 588 | for (var i = y-1 ; i >= 0; i--){ 589 | if (map[i][x]) { 590 | if (n==0){ 591 | n++; 592 | continue; 593 | }else{ 594 | if (com.mans[map[i][x]].my!=my) d.push([x,i]); 595 | break 596 | } 597 | }else{ 598 | if(n==0) d.push([x,i]) 599 | } 600 | } 601 | //下检索 602 | var n=0; 603 | for (var i = y+1 ; i<= 9; i++){ 604 | if (map[i][x]) { 605 | if (n==0){ 606 | n++; 607 | continue; 608 | }else{ 609 | if (com.mans[map[i][x]].my!=my) d.push([x,i]); 610 | break 611 | } 612 | }else{ 613 | if(n==0) d.push([x,i]) 614 | } 615 | } 616 | return d; 617 | } 618 | 619 | //卒 620 | com.bylaw.z = function (x,y,map,my){ 621 | var d=[]; 622 | if (my===1){ //红方 623 | //上 624 | if ( y-1>= 0 && (!com.mans[map[y-1][x]] || com.mans[map[y-1][x]].my!=my)) d.push([x,y-1]); 625 | //右 626 | if ( x+1<= 8 && y<=4 && (!com.mans[map[y][x+1]] || com.mans[map[y][x+1]].my!=my)) d.push([x+1,y]); 627 | //左 628 | if ( x-1>= 0 && y<=4 && (!com.mans[map[y][x-1]] || com.mans[map[y][x-1]].my!=my))d.push([x-1,y]); 629 | }else{ 630 | //下 631 | if ( y+1<= 9 && (!com.mans[map[y+1][x]] || com.mans[map[y+1][x]].my!=my)) d.push([x,y+1]); 632 | //右 633 | if ( x+1<= 8 && y>=6 && (!com.mans[map[y][x+1]] || com.mans[map[y][x+1]].my!=my)) d.push([x+1,y]); 634 | //左 635 | if ( x-1>= 0 && y>=6 && (!com.mans[map[y][x-1]] || com.mans[map[y][x-1]].my!=my))d.push([x-1,y]); 636 | } 637 | 638 | return d; 639 | } 640 | 641 | com.value = { 642 | 643 | //车价值 644 | c:[ 645 | [206, 208, 207, 213, 214, 213, 207, 208, 206], 646 | [206, 212, 209, 216, 233, 216, 209, 212, 206], 647 | [206, 208, 207, 214, 216, 214, 207, 208, 206], 648 | [206, 213, 213, 216, 216, 216, 213, 213, 206], 649 | [208, 211, 211, 214, 215, 214, 211, 211, 208], 650 | 651 | [208, 212, 212, 214, 215, 214, 212, 212, 208], 652 | [204, 209, 204, 212, 214, 212, 204, 209, 204], 653 | [198, 208, 204, 212, 212, 212, 204, 208, 198], 654 | [200, 208, 206, 212, 200, 212, 206, 208, 200], 655 | [194, 206, 204, 212, 200, 212, 204, 206, 194] 656 | ], 657 | 658 | //马价值 659 | m:[ 660 | [90, 90, 90, 96, 90, 96, 90, 90, 90], 661 | [90, 96,103, 97, 94, 97,103, 96, 90], 662 | [92, 98, 99,103, 99,103, 99, 98, 92], 663 | [93,108,100,107,100,107,100,108, 93], 664 | [90,100, 99,103,104,103, 99,100, 90], 665 | 666 | [90, 98,101,102,103,102,101, 98, 90], 667 | [92, 94, 98, 95, 98, 95, 98, 94, 92], 668 | [93, 92, 94, 95, 92, 95, 94, 92, 93], 669 | [85, 90, 92, 93, 78, 93, 92, 90, 85], 670 | [88, 85, 90, 88, 90, 88, 90, 85, 88] 671 | ], 672 | 673 | //相价值 674 | x:[ 675 | [0, 0,20, 0, 0, 0,20, 0, 0], 676 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 677 | [0, 0, 0, 0,23, 0, 0, 0, 0], 678 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 679 | [0, 0,20, 0, 0, 0,20, 0, 0], 680 | 681 | [0, 0,20, 0, 0, 0,20, 0, 0], 682 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 683 | [18,0, 0, 0,23, 0, 0, 0,18], 684 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 685 | [0, 0,20, 0, 0, 0,20, 0, 0] 686 | ], 687 | 688 | //士价值 689 | s:[ 690 | [0, 0, 0,20, 0,20, 0, 0, 0], 691 | [0, 0, 0, 0,23, 0, 0, 0, 0], 692 | [0, 0, 0,20, 0,20, 0, 0, 0], 693 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 694 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 695 | 696 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 697 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 698 | [0, 0, 0,20, 0,20, 0, 0, 0], 699 | [0, 0, 0, 0,23, 0, 0, 0, 0], 700 | [0, 0, 0,20, 0,20, 0, 0, 0] 701 | ], 702 | 703 | //奖价值 704 | j:[ 705 | [0, 0, 0, 8888, 8888, 8888, 0, 0, 0], 706 | [0, 0, 0, 8888, 8888, 8888, 0, 0, 0], 707 | [0, 0, 0, 8888, 8888, 8888, 0, 0, 0], 708 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 709 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 710 | 711 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 712 | [0, 0, 0, 0, 0, 0, 0, 0, 0], 713 | [0, 0, 0, 8888, 8888, 8888, 0, 0, 0], 714 | [0, 0, 0, 8888, 8888, 8888, 0, 0, 0], 715 | [0, 0, 0, 8888, 8888, 8888, 0, 0, 0] 716 | ], 717 | 718 | //炮价值 719 | p:[ 720 | 721 | [100, 100, 96, 91, 90, 91, 96, 100, 100], 722 | [ 98, 98, 96, 92, 89, 92, 96, 98, 98], 723 | [ 97, 97, 96, 91, 92, 91, 96, 97, 97], 724 | [ 96, 99, 99, 98, 100, 98, 99, 99, 96], 725 | [ 96, 96, 96, 96, 100, 96, 96, 96, 96], 726 | 727 | [ 95, 96, 99, 96, 100, 96, 99, 96, 95], 728 | [ 96, 96, 96, 96, 96, 96, 96, 96, 96], 729 | [ 97, 96, 100, 99, 101, 99, 100, 96, 97], 730 | [ 96, 97, 98, 98, 98, 98, 98, 97, 96], 731 | [ 96, 96, 97, 99, 99, 99, 97, 96, 96] 732 | ], 733 | 734 | //卒价值 735 | z:[ 736 | [ 9, 9, 9, 11, 13, 11, 9, 9, 9], 737 | [19, 24, 34, 42, 44, 42, 34, 24, 19], 738 | [19, 24, 32, 37, 37, 37, 32, 24, 19], 739 | [19, 23, 27, 29, 30, 29, 27, 23, 19], 740 | [14, 18, 20, 27, 29, 27, 20, 18, 14], 741 | 742 | [ 7, 0, 13, 0, 16, 0, 13, 0, 7], 743 | [ 7, 0, 7, 0, 15, 0, 7, 0, 7], 744 | [ 0, 0, 0, 0, 0, 0, 0, 0, 0], 745 | [ 0, 0, 0, 0, 0, 0, 0, 0, 0], 746 | [ 0, 0, 0, 0, 0, 0, 0, 0, 0] 747 | ] 748 | } 749 | 750 | //黑子为红字价值位置的倒置 751 | com.value.C = com.arr2Clone(com.value.c).reverse(); 752 | com.value.M = com.arr2Clone(com.value.m).reverse(); 753 | com.value.X = com.value.x; 754 | com.value.S = com.value.s; 755 | com.value.J = com.value.j; 756 | com.value.P = com.arr2Clone(com.value.p).reverse(); 757 | com.value.Z = com.arr2Clone(com.value.z).reverse(); 758 | 759 | //棋子们 760 | com.args={ 761 | //红子 中文/图片地址/阵营/权重 762 | 'c':{text:"车", img:'r_c', my:1 ,bl:"c", value:com.value.c}, 763 | 'm':{text:"马", img:'r_m', my:1 ,bl:"m", value:com.value.m}, 764 | 'x':{text:"相", img:'r_x', my:1 ,bl:"x", value:com.value.x}, 765 | 's':{text:"仕", img:'r_s', my:1 ,bl:"s", value:com.value.s}, 766 | 'j':{text:"将", img:'r_j', my:1 ,bl:"j", value:com.value.j}, 767 | 'p':{text:"炮", img:'r_p', my:1 ,bl:"p", value:com.value.p}, 768 | 'z':{text:"兵", img:'r_z', my:1 ,bl:"z", value:com.value.z}, 769 | 770 | //蓝子 771 | 'C':{text:"�", img:'b_c', my:-1 ,bl:"c", value:com.value.C}, 772 | 'M':{text:"�R", img:'b_m', my:-1 ,bl:"m", value:com.value.M}, 773 | 'X':{text:"象", img:'b_x', my:-1 ,bl:"x", value:com.value.X}, 774 | 'S':{text:"士", img:'b_s', my:-1 ,bl:"s", value:com.value.S}, 775 | 'J':{text:"帅", img:'b_j', my:-1 ,bl:"j", value:com.value.J}, 776 | 'P':{text:"炮", img:'b_p', my:-1 ,bl:"p", value:com.value.P}, 777 | 'Z':{text:"卒", img:'b_z', my:-1 ,bl:"z", value:com.value.Z} 778 | }; 779 | 780 | com.class = com.class || {} //类 781 | com.class.Man = function (key, x, y){ 782 | this.pater = key.slice(0,1); 783 | var o=com.args[this.pater] 784 | this.x = x||0; 785 | this.y = y||0; 786 | this.key = key ; 787 | this.my = o.my; 788 | this.text = o.text; 789 | this.value = o.value; 790 | this.isShow = true; 791 | this.alpha = 1; 792 | this.ps = []; //着点 793 | 794 | this.show = function (){ 795 | if (this.isShow) { 796 | com.ct.save(); 797 | com.ct.globalAlpha = this.alpha; 798 | com.ct.drawImage(com[this.pater].img,com.spaceX * this.x + com.pointStartX , com.spaceY * this.y +com.pointStartY); 799 | com.ct.restore(); 800 | } 801 | } 802 | 803 | this.bl = function (map){ 804 | var map = map || play.map 805 | return com.bylaw[o.bl](this.x,this.y,map,this.my) 806 | } 807 | } 808 | 809 | com.class.Bg = function (img, x, y){ 810 | this.x = x||0; 811 | this.y = y||0; 812 | this.isShow = true; 813 | 814 | this.show = function (){ 815 | if (this.isShow) com.ct.drawImage(com.bgImg, com.spaceX * this.x,com.spaceY * this.y); 816 | } 817 | } 818 | com.class.Pane = function (img, x, y){ 819 | this.x = x||0; 820 | this.y = y||0; 821 | this.newX = x||0; 822 | this.newY = y||0; 823 | this.isShow = true; 824 | 825 | this.show = function (){ 826 | if (this.isShow) { 827 | com.ct.drawImage(com.paneImg, com.spaceX * this.x + com.pointStartX , com.spaceY * this.y + com.pointStartY) 828 | com.ct.drawImage(com.paneImg, com.spaceX * this.newX + com.pointStartX , com.spaceY * this.newY + com.pointStartY) 829 | } 830 | } 831 | } 832 | 833 | com.class.Dot = function (img, x, y){ 834 | this.x = x||0; 835 | this.y = y||0; 836 | this.isShow = true; 837 | this.dots=[] 838 | 839 | this.show = function (){ 840 | for (var i=0; i11&&p[len-1] == p[len-5] &&p[len-5] == p[len-9]){ 262 | return p[len-4].split(""); 263 | } 264 | return false; 265 | } 266 | 267 | 268 | 269 | play.AIclickMan = function (key,x,y){ 270 | var man = com.mans[key]; 271 | //吃子 272 | man.isShow = false; 273 | delete play.map[com.mans[play.nowManKey].y][com.mans[play.nowManKey].x]; 274 | play.map[y][x] = play.nowManKey; 275 | play.showPane(com.mans[play.nowManKey].x ,com.mans[play.nowManKey].y,x,y) 276 | 277 | com.mans[play.nowManKey].x = x; 278 | com.mans[play.nowManKey].y = y; 279 | play.nowManKey = false; 280 | 281 | com.show() 282 | if (key == "j0") play.showWin (-1); 283 | if (key == "J0") play.showWin (1); 284 | } 285 | 286 | play.AIclickPoint = function (x,y){ 287 | var key=play.nowManKey; 288 | var man=com.mans[key]; 289 | if (play.nowManKey){ 290 | delete play.map[com.mans[play.nowManKey].y][com.mans[play.nowManKey].x]; 291 | play.map[y][x] = key; 292 | 293 | com.showPane(man.x,man.y,x,y) 294 | 295 | man.x = x; 296 | man.y = y; 297 | play.nowManKey = false; 298 | 299 | } 300 | com.show(); 301 | } 302 | 303 | 304 | play.indexOfPs = function (ps,xy){ 305 | for (var i=0; i8 || y < 0 || y > 9) return false; 326 | return (play.map[y][x] && play.map[y][x]!="0") ? play.map[y][x] : false; 327 | } 328 | 329 | play.showWin = function (my){ 330 | play.isPlay = false; 331 | if (my===1){ 332 | alert("恭喜你,你赢了!"); 333 | }else{ 334 | alert("很遗憾,你输了!"); 335 | } 336 | } 337 | 338 | --------------------------------------------------------------------------------