How to use sq method in wpt

Best JavaScript code snippet using wpt

store.js

Source:store.js Github

copy

Full Screen

1export default {2 materials: [3 {4 name: "Wood",5 slug: "wood",6 image: "wood.jpg",7 types: [8 {9 name: "Ply Wood",10 slug: "ply-wood",11 image: "ply.jpg",12 type: [13 {14 name: "Hardwood",15 slug: "hardwood",16 // image: "hardwood.jpg",17 sizes:[18 {thickness: 6, priceSqM: 1.35},19 {thickness: 9, priceSqM: 2.35},20 {thickness: 12, priceSqM: 3.35},21 {thickness: 18, priceSqM: 4.35},22 {thickness: 25, priceSqM: 5.35},23 ]24 },25 {26 name: "Softwood",27 slug: "softwood",28 // image: "softwood.jpg",29 sizes:[30 {thickness: 6, priceSqM: 1.35},31 {thickness: 9, priceSqM: 2.35},32 {thickness: 12, priceSqM: 3.35},33 {thickness: 18, priceSqM: 4.35},34 {thickness: 25, priceSqM: 5.35},35 ]36 }37 ],38 },39 {40 name: "MDF",41 slug: "mdf",42 image: "mdf.jpg",43 type: [44 {45 name: "Medite",46 slug: "medite",47 // image: "medite.jpg",48 sizes:[49 {thickness: 6, priceSqM: 1.35},50 {thickness: 9, priceSqM: 2.35},51 {thickness: 12, priceSqM: 3.35},52 {thickness: 18, priceSqM: 4.35},53 {thickness: 25, priceSqM: 5.35},54 ]55 },56 {57 name: "Kronospan",58 slug: "kronospan",59 // image: "kronospan.jpg",60 sizes:[61 {thickness: 6, priceSqM: 1.35},62 {thickness: 9, priceSqM: 2.35},63 {thickness: 12, priceSqM: 3.35},64 {thickness: 18, priceSqM: 4.35},65 {thickness: 25, priceSqM: 5.35},66 ]67 },68 {69 name: "Finsa",70 slug: "finsa",71 // image: "finsa.jpg",72 sizes:[73 {thickness: 12, priceSqM: 1.35},74 {thickness: 15, priceSqM: 2.35},75 {thickness: 18, priceSqM: 3.35},76 {thickness: 25, priceSqM: 4.35},77 ]78 },79 ],80 },81 {82 name: "Chipbord",83 slug: "chipbord",84 image: "chipbord.jpg",85 type: [86 {87 name: "Standard",88 slug: "standard",89 // image: "standard.jpg",90 sizes:[91 {thickness: 12, priceSqM: 1.35},92 {thickness: 15, priceSqM: 2.35},93 {thickness: 18, priceSqM: 3.35},94 {thickness: 25, priceSqM: 4.35},95 ]96 },97 {98 name: "Furniture",99 slug: "furniture",100 // image: "furniture.jpg",101 sizes:[102 {thickness: 15, priceSqM: 1.35},103 {thickness: 18, priceSqM: 2.35},104 {thickness: 25, priceSqM: 3.35},105 {thickness: 30, priceSqM: 4.35},106 {thickness: 38, priceSqM: 5.35},107 ]108 },109 {110 name: "Flooring",111 slug: "flooring",112 // image: "flooring.jpg",113 sizes:[114 {thickness: 18, priceSqM: 1.35},115 {thickness: 22, priceSqM: 2.35},116 ]117 },118 ],119 },120 {121 name: "Particle Bord",122 slug: "particle-bord",123 image: "particle-bord.jpg",124 type: [125 {126 name: "Smartply",127 slug: "smartply",128 // image: "smartply.jpg",129 sizes:[130 {thickness: 15, priceSqM: 1.35},131 {thickness: 18, priceSqM: 2.35},132 {thickness: 25, priceSqM: 3.35},133 {thickness: 30, priceSqM: 4.35},134 {thickness: 38, priceSqM: 5.35},135 ]136 },137 {138 name: "FrBuild",139 slug: "frBuild",140 // image: "frBuild.jpg",141 sizes:[142 {thickness: 11, priceSqM: 1.35},143 {thickness: 15, priceSqM: 2.35},144 {thickness: 18, priceSqM: 3.35},145 ]146 },147 {148 name: "Propassiv",149 slug: "propassiv",150 // image: "propassiv.jpg",151 sizes:[152 {thickness: 12.5, priceSqM: 1.35},153 ]154 },155 ],156 },157 ],158 },159 {160 name: "Plastic",161 slug: "plastic",162 image: "plastic.jpg",163 types: [164 {165 name: "Acrylic",166 slug: "acrylic",167 image: "acrylic.jpg",168 type: [169 {170 name: "Clear",171 slug: "clear",172 // image: "clear.jpg",173 sizes:[174 {thickness: 6, priceSqM: 1.35},175 {thickness: 9, priceSqM: 2.35},176 {thickness: 12, priceSqM: 3.35},177 {thickness: 18, priceSqM: 4.35},178 {thickness: 25, priceSqM: 5.35},179 ]180 },181 {182 name: "Red4403",183 slug: "red4403",184 // image: "red4403.jpg",185 sizes:[186 {thickness: 3, priceSqM: 1.35},187 {thickness: 5, priceSqM: 2.35},188 ]189 },190 {191 name: "Green692",192 slug: "green692",193 // image: "green692.jpg",194 sizes:[195 {thickness: 3, priceSqM: 1.35},196 {thickness: 5, priceSqM: 2.35},197 ]198 },199 {200 name: "Blue1743",201 slug: "blue1743",202 // image: "blue1743.jpg",203 sizes:[204 {thickness: 3, priceSqM: 1.35},205 {thickness: 5, priceSqM: 2.35},206 ]207 },208 {209 name: "White069",210 slug: "white069",211 // image: "white069.jpg",212 sizes:[213 {thickness: 6, priceSqM: 1.35},214 {thickness: 9, priceSqM: 2.35},215 {thickness: 12, priceSqM: 3.35},216 {thickness: 18, priceSqM: 4.35},217 {thickness: 25, priceSqM: 5.35},218 ]219 },220 {221 name: "Black9030",222 slug: "black9030",223 // image: "black9030.jpg",224 sizes:[225 {thickness: 6, priceSqM: 1.35},226 {thickness: 9, priceSqM: 2.35},227 {thickness: 12, priceSqM: 3.35},228 {thickness: 18, priceSqM: 4.35},229 {thickness: 25, priceSqM: 5.35},230 ]231 },232 {233 name: "LEDOpal",234 slug: "LEDOpal",235 // image: "LEDOpal.jpg",236 sizes:[237 {thickness: 10, priceSqM: 1.35},238 {thickness: 30, priceSqM: 2.35},239 ]240 },241 {242 name: "LEDRed",243 slug: "LEDRed",244 // image: "LEDRed.jpg",245 sizes:[246 {thickness: 10, priceSqM: 1.35},247 {thickness: 30, priceSqM: 2.35},248 ]249 },250 ],251 },252 {253 name: "PET G",254 slug: "petg",255 image: "petg.jpg",256 type: [257 {258 name: "hardwood",259 slug: "hardwood",260 // image: "hardwood.jpg",261 sizes:[262 {thickness: 6, priceSqM: 1.35},263 {thickness: 9, priceSqM: 2.35},264 {thickness: 12, priceSqM: 3.35},265 {thickness: 18, priceSqM: 4.35},266 {thickness: 25, priceSqM: 5.35},267 ]268 },269 {270 name: "softwood",271 slug: "softwood",272 // image: "softwood.jpg",273 sizes:[274 {thickness: 6, priceSqM: 1.35},275 {thickness: 9, priceSqM: 2.35},276 {thickness: 12, priceSqM: 3.35},277 {thickness: 18, priceSqM: 4.35},278 {thickness: 25, priceSqM: 5.35},279 ]280 },281 ],282 },283 {284 name: "Polycarb",285 slug: "polycarb",286 image: "polycarb.jpg",287 type: [288 {289 name: "hardwood",290 slug: "hardwood",291 // image: "hardwood.jpg",292 sizes:[293 {thickness: 6, priceSqM: 1.35},294 {thickness: 9, priceSqM: 2.35},295 {thickness: 12, priceSqM: 3.35},296 {thickness: 18, priceSqM: 4.35},297 {thickness: 25, priceSqM: 5.35},298 ]299 },300 {301 name: "softwood",302 slug: "softwood",303 // image: "softwood.jpg",304 sizes:[305 {thickness: 6, priceSqM: 1.35},306 {thickness: 9, priceSqM: 2.35},307 {thickness: 12, priceSqM: 3.35},308 {thickness: 18, priceSqM: 4.35},309 {thickness: 25, priceSqM: 5.35},310 ]311 },312 ],313 },314 {315 name: "PVC Foam",316 slug: "pvc-foam",317 image: "pvc-foam.jpg",318 type: [319 {320 name: "hardwood",321 slug: "hardwood",322 // image: "hardwood.jpg",323 sizes:[324 {thickness: 6, priceSqM: 1.35},325 {thickness: 9, priceSqM: 2.35},326 {thickness: 12, priceSqM: 3.35},327 {thickness: 18, priceSqM: 4.35},328 {thickness: 25, priceSqM: 5.35},329 ]330 },331 {332 name: "softwood",333 slug: "softwood",334 // image: "softwood.jpg",335 sizes:[336 {thickness: 6, priceSqM: 1.35},337 {thickness: 9, priceSqM: 2.35},338 {thickness: 12, priceSqM: 3.35},339 {thickness: 18, priceSqM: 4.35},340 {thickness: 25, priceSqM: 5.35},341 ]342 },343 ],344 },345 ],346 },347 {348 name: "Metal",349 slug: "metal",350 image: "metal.jpg",351 types: [352 {353 name: "Carbon",354 slug: "carbon",355 image: "carbon.jpg",356 type: [357 {358 name: "hardwood",359 slug: "hardwood",360 // image: "hardwood.jpg",361 sizes:[362 {thickness: 6, priceSqM: 1.35},363 {thickness: 9, priceSqM: 2.35},364 {thickness: 12, priceSqM: 3.35},365 {thickness: 18, priceSqM: 4.35},366 {thickness: 25, priceSqM: 5.35},367 ]368 },369 {370 name: "softwood",371 slug: "softwood",372 // image: "softwood.jpg",373 sizes:[374 {thickness: 6, priceSqM: 1.35},375 {thickness: 9, priceSqM: 2.35},376 {thickness: 12, priceSqM: 3.35},377 {thickness: 18, priceSqM: 4.35},378 {thickness: 25, priceSqM: 5.35},379 ]380 },381 ],382 },383 {384 name: "Stainless",385 slug: "stainless",386 image: "stainless.jpg",387 type: [388 {389 name: "hardwood",390 slug: "hardwood",391 // image: "hardwood.jpg",392 sizes:[393 {thickness: 6, priceSqM: 1.35},394 {thickness: 9, priceSqM: 2.35},395 {thickness: 12, priceSqM: 3.35},396 {thickness: 18, priceSqM: 4.35},397 {thickness: 25, priceSqM: 5.35},398 ]399 },400 {401 name: "softwood",402 slug: "softwood",403 // image: "softwood.jpg",404 sizes:[405 {thickness: 6, priceSqM: 1.35},406 {thickness: 9, priceSqM: 2.35},407 {thickness: 12, priceSqM: 3.35},408 {thickness: 18, priceSqM: 4.35},409 {thickness: 25, priceSqM: 5.35},410 ]411 },412 ],413 },414 {415 name: "Aluminium",416 slug: "aluminium",417 image: "aluminium.jpg",418 type: [419 {420 name: "hardwood",421 slug: "hardwood",422 // image: "hardwood.jpg",423 sizes:[424 {thickness: 6, priceSqM: 1.35},425 {thickness: 9, priceSqM: 2.35},426 {thickness: 12, priceSqM: 3.35},427 {thickness: 18, priceSqM: 4.35},428 {thickness: 25, priceSqM: 5.35},429 ]430 },431 {432 name: "softwood",433 slug: "softwood",434 // image: "softwood.jpg",435 sizes:[436 {thickness: 6, priceSqM: 1.35},437 {thickness: 9, priceSqM: 2.35},438 {thickness: 12, priceSqM: 3.35},439 {thickness: 18, priceSqM: 4.35},440 {thickness: 25, priceSqM: 5.35},441 ]442 },443 ],444 },445 ],446 },447 {448 name: "Aluminium-Composite",449 slug: "aluminium-composite",450 image: "aluminium-composite.jpg",451 types: [452 {453 name: "Fire Retardant",454 slug: "fire-retardant",455 image: "fire-retardant.png",456 type: [457 {458 name: "hardwood",459 slug: "hardwood",460 // image: "hardwood.jpg",461 sizes:[462 {thickness: 6, priceSqM: 1.35},463 {thickness: 9, priceSqM: 2.35},464 {thickness: 12, priceSqM: 3.35},465 {thickness: 18, priceSqM: 4.35},466 {thickness: 25, priceSqM: 5.35},467 ]468 },469 {470 name: "softwood",471 slug: "softwood",472 // image: "softwood.jpg",473 sizes:[474 {thickness: 6, priceSqM: 1.35},475 {thickness: 9, priceSqM: 2.35},476 {thickness: 12, priceSqM: 3.35},477 {thickness: 18, priceSqM: 4.35},478 {thickness: 25, priceSqM: 5.35},479 ]480 },481 ],482 },483 {484 name: "A2",485 slug: "a2",486 image: "a2.png",487 type: [488 {489 name: "hardwood",490 slug: "hardwood",491 // image: "hardwood.jpg",492 sizes:[493 {thickness: 6, priceSqM: 1.35},494 {thickness: 9, priceSqM: 2.35},495 {thickness: 12, priceSqM: 3.35},496 {thickness: 18, priceSqM: 4.35},497 {thickness: 25, priceSqM: 5.35},498 ]499 },500 {501 name: "softwood",502 slug: "softwood",503 // image: "softwood.jpg",504 sizes:[505 {thickness: 6, priceSqM: 1.35},506 {thickness: 9, priceSqM: 2.35},507 {thickness: 12, priceSqM: 3.35},508 {thickness: 18, priceSqM: 4.35},509 {thickness: 25, priceSqM: 5.35},510 ]511 },512 ],513 },514 ],515 },516 ],...

Full Screen

Full Screen

Position.js

Source:Position.js Github

copy

Full Screen

1/**2 * 处理棋子移动3 */4(function(){5 var Position = window.Position = function(){6 7 }8 // 如果bDel为false,则将棋子pc添加进棋局中的sq位置;如果bDel为true,则删除sq位置的棋子。9 Position.prototype.addPiece = function(sq,pc,bDel) {10 this.squares[sq] = bDel ? 0 : pc;11 //更新红方和黑方的分值12 if(pc < 16){13 var pcAdjust = pc - 8;14 this.vlWhite += bDel ? -PIECE_VALUE[pcAdjust][sq] : PIECE_VALUE[pcAdjust][sq];15 } else {16 var pcAdjust = pc - 16;17 this.vlBlack += bDel ? -PIECE_VALUE[pcAdjust][SQUARE_FLIP(sq)] : PIECE_VALUE[pcAdjust][SQUARE_FLIP(sq)];18 }19 }20 //尝试走棋21 Position.prototype.makeMove = function(mv){22 this.movePiece(mv);23 if(this.checked()){24 this.undoMovePiece();25 return false;26 }27 this.changeSide();28 this.distance ++;29 return true;30 }31 //取消尝试走的棋32 Position.prototype.undoMakeMove = function(){33 this.changeSide();34 this.distance --;35 this.undoMovePiece();36 37 }38 //移动棋子39 Position.prototype.movePiece = function(mv){40 var sqSrc = SRC(mv);41 var pcSrc = this.squares[sqSrc];42 var sqDst = DST(mv);43 var pcDst = this.squares[sqDst];44 this.pcList.push(pcDst); //记录被吃掉的子 (没有吃子时,记录 0);45 if (pcDst > 0) {46 // 终点有棋子,需要删除该棋子47 this.addPiece(sqDst, pcDst, DEL_PIECE);48 }49 //删除起点位置棋子50 this.addPiece(sqSrc,pcSrc,DEL_PIECE);51 //将起点位置的棋子添加到终点位置52 this.addPiece(sqDst,pcSrc,ADD_PIECE);53 /*console.log("movePiece:" + "黑棋--" + this.vlBlack + "红棋--" + this.vlWhite);*/54 //记录走法55 this.mvList.push(mv);56 }57 //取消移动棋子58 Position.prototype.undoMovePiece = function(){59 //从走法表中取出最后一个走法60 var mv = this.mvList.pop();61 //获取走法的起点,终点,棋子62 var sqSrc = SRC(mv);63 var sqDst = DST(mv);64 var pcDst = this.squares[sqDst];65 // 删除终点棋子66 this.addPiece(sqDst, pcDst, DEL_PIECE); 67 //将这个棋子添加到起点68 this.addPiece(sqSrc,pcDst,ADD_PIECE);69 //取出吃掉的子70 var pc = this.pcList.pop();71 if(pc > 0){72 this.addPiece(sqDst,pc,ADD_PIECE);73 }74 /*console.log("undomovePiece:" + "黑棋--" + this.vlBlack + "红棋--" + this.vlWhite);*/75 }76 //获得分数77 Position.prototype.evaluate = function(){78 return this.sdPlayer == PLAYER ? (this.vlWhite - this.vlBlack) : (this.vlBlack - this.vlWhite);79 }80 //改变走棋方81 Position.prototype.changeSide = function(){82 this.sdPlayer = 1 - this.sdPlayer;83 }84 //判断老将是否被攻击85 Position.prototype.checked = function(){86 var pcSelfSide = SIDE_TAG(this.sdPlayer);87 var pcOppSide = OPP_SIDE_TAG(this.sdPlayer);88 for(var sq = 0 ; sq < 256 ; sq ++){89 if(this.squares[sq] - pcSelfSide != PIECE_KING){90 continue;91 }92 //对方进兵时,是否能吃到我方的帅93 if(this.squares[SQUARE_FORWARD(sq,this.sdPlayer)] == pcOppSide + PIECE_PAWN){94 return true;95 }96 //对方平兵时,是否能吃到我方的帅97 if(this.squares[sq - 1] == pcOppSide + PIECE_PAWN || this.squares[sq + 1] == pcOppSide + PIECE_PAWN){98 return true;99 }100 //对方的马能否吃到我方的帅101 for(var i = 0 ; i < 4 ; i ++){102 //马脚位置103 var sqPin = sq + ADVISOR_DELTA[i];104 //马脚位置存在棋子105 if(this.squares[sqPin] != 0){106 continue;107 }108 for (var j = 0; j < 2; j ++) {109 var pcDst = this.squares[sq + KNIGHT_CHECK_DELTA[i][j]];110 if (pcDst == pcOppSide + PIECE_KNIGHT) {111 return true;112 }113 } 114 }115 //对方的炮、车是否能吃到我方的帅,或者将帅对脸116 for(var i = 0 ; i < 4 ; i ++){117 var delta = KING_DELTA[i];118 var sqDst = sq + delta;119 while(IN_BOARD(sqDst)){120 var pcDst = this.squares[sqDst];121 //遇到了棋子122 if(pcDst > 0){123 //如果棋子是车或者对方的帅,则返回true124 if(pcDst == pcOppSide + PIECE_ROOK || pcDst == pcOppSide + PIECE_KING){125 return true;126 }127 break;128 }129 sqDst += delta;130 }131 //此时若棋子还在棋盘内,则该位置为其它棋子132 sqDst += delta;133 while(IN_BOARD(sqDst)){134 var pcDst = this.squares[sqDst];135 if(pcDst > 0){136 //此时棋子为对方的炮,则可以被将军137 if(pcDst == pcOppSide + PIECE_CANNON){138 return true;139 }140 //无论是否是对方的炮,此时都该退出循环141 break;142 }143 sqDst += delta;144 }145 }146 return false;147 }148 return false;149 }150 //判断当前局面是否会导致被将死151 Position.prototype.isMate = function(){152 var mvs = gen(this.squares);153 //尝试所有的步骤,如果每一步都会被将军,那么说明已经被将死了154 for(var i = 0 , len = mvs.length ; i < len ; i ++){155 var mv = mvs[i];156 if(this.makeMove(mv)){157 this.undoMakeMove();158 return false;159 }160 }161 return true;162 }163 //杀棋分数164 Position.prototype.mateValue = function(){165 return this.distance - MATE_VALUE;166 }167 //获取历史表的指标168 Position.prototype.historyIndex = function(mv){169 return ((this.squares[SRC(mv)] - 8) << 8) + DST(mv);170 }171 //判断走法是否合法172 Position.prototype.legalMove = function(mv){173 var sqSrc = SRC(mv);174 var pcSrc = this.squares[sqSrc];175 var pcSelfSide = SIDE_TAG(this.sdPlayer);176 //如果起点为对方棋子,或者为空子,不合法177 if((pcSrc & pcSelfSide) == 0){178 return false;179 }180 var sqDst = DST(mv);181 var pcDst = this.squares[sqDst];182 //终点位置棋子为我方棋子183 if((pcDst & pcSelfSide) != 0){184 return false;185 }186 //根据棋子类型判断187 switch(pcSrc - pcSelfSide){188 case PIECE_KING: //将(帅)189 return IN_FORT(sqDst) && KING_SPAN(sqSrc,sqDst);190 case PIECE_ADVISOR: //士191 return IN_FORT(sqDst) && ADVISOR_SPAN(sqSrc,sqDst);192 case PIECE_BISHOP: //象193 return SAME_HALF(sqSrc,sqDst) && BISHOP_SPAN(sqSrc,sqDst) 194 && this.squares[BISHOP_PIN(sqSrc,sqDst)] == 0;195 case PIECE_KNIGHT: //马196 var sqPin = KNIGHT_SPAN(sqSrc,sqDst);197 return sqPin != sqSrc && this.squares[sqPin] == 0;198 case PIECE_ROOK: //车199 case PIECE_CANNON: //炮200 //车与炮均是直线走路,判断是否是同一行或者同一列201 var delta;//移动向量202 //同一行 203 if(SAME_RANK(sqSrc,sqDst)){204 delta = sqDst > sqSrc ? 1 : -1;205 } else if(SAME_FILE(sqSrc,sqDst)){206 delta = sqDst > sqSrc ? 16 : -16;207 } else {208 return false;209 }210 var sqPin = sqSrc + delta;211 //沿着终点的方向前进,直到到达终点或者遇到了其它棋子位置212 while(sqPin != sqDst && this.squares[sqPin] == 0){213 sqPin += delta;214 }215 //如果此时到达了终点,说明中途没有遇到一个棋子,此时若终点为空,则车或炮都合法,否则只有车合法216 if(sqPin == sqDst){217 return this.squares[sqDst] == 0 || pcSrc - pcSelfSide == PIECE_ROOK;218 }219 //没有到达终点,此时sqPin对应的位置棋子不为空,此时如果是车,则不合法,如果终点为空,也不合法220 if(pcDst == 0 || pcSrc - pcSelfSide != PIECE_CANNON){221 return false;222 }223 sqPin += delta;224 while(sqPin != sqDst && this.squares[sqPin] == 0){225 sqPin += delta;226 }227 //此时再次碰到棋子,如果该位置是终点,则炮合法,否则都不合法228 return sqPin == sqDst;229 case PIECE_PAWN: //兵(卒)230 //如果已经过河,且是向左向右走的,合法231 if(AWAY_HALF(sqSrc,this.sdPlayer) && 232 (sqDst - sqSrc == 1 || sqDst - sqSrc == -1)){233 return true;234 }235 var sqPin = SQUARE_FORWARD(sqSrc,this.sdPlayer);236 return sqPin == sqDst;237 default:238 return false;239 }240 }241 Position.prototype.clearBoard = function() {242 //开始走棋方243 this.sdPlayer = game.sm.whoIsFirst;244 this.squares = []; //棋盘数组245 for(var i = 0 ; i < 256 ; i++){246 this.squares.push(0);247 }248 this.vlWhite = this.vlBlack = 0;249 };250 Position.prototype.setIrrev = function(){251 //走法数组,存储每次的走法252 this.mvList = [0];253 //吃子数组,存放每次吃子254 this.pcList = [0];255 //深度,代表每次搜索时进行的深度,配合历史表使用256 this.distance = 0;257 }258 //解析fen259 Position.prototype.fromFen = function(fen){260 this.clearBoard();261 var index = 0;262 if(index == fen.length){263 return ;264 }265 var c = fen.charAt(index);266 var x = 3,y = 3;//x 代表列 y 代表行267 while(c != " "){268 if(c == "/"){//换行269 x = 3;270 y ++;271 } else if(c >= 1 && c <= 9){ // 空格272 x += (c.charCodeAt() - ("0").charCodeAt());273 } else if(c >= "A" && c <= "Z"){274 if(x <= 11){275 var pt = CHAR_TO_PIECE(c);276 if(pt >= 0){277 this.addPiece(COORD_XY(x,y),pt + 8,ADD_PIECE);278 }279 x ++;280 }281 } else if(c >= "a" && c <= "z"){282 if(x <= 11){283 var pt = CHAR_TO_PIECE(c.toUpperCase());284 if(pt >= 0){285 this.addPiece(COORD_XY(x,y),pt + 16,ADD_PIECE);286 }287 x ++;288 }289 }290 index++;291 if(index == fen.length){292 this.setIrrev();293 return ;294 }295 c = fen.charAt(index); 296 }297 this.setIrrev();298 console.log("黑子分数:" + this.vlBlack + " 红子分数:" + this.vlWhite);299 }...

Full Screen

Full Screen

Generator.js

Source:Generator.js Github

copy

Full Screen

1/**2 * 获取所有可行的走法3 */4(function(){5 window.gen = function(squares){6 var mvs = [];7 var pcSelfSide = SIDE_TAG(game.sm.board.pos.sdPlayer);8 var pcOppside = OPP_SIDE_TAG(game.sm.board.pos.sdPlayer);9 //遍历整个棋盘10 for(var sqSrc = 0 ; sqSrc < 256 ; sqSrc++){11 //不在真实棋盘上12 if(!IN_BOARD(sqSrc)){13 continue;14 }15 //根据棋子查询可行的走法16 var pcSrc = squares[sqSrc];17 //如果棋子不是本方棋子18 if((pcSrc & pcSelfSide) == 0){19 continue;20 }21 switch(pcSrc - pcSelfSide){22 case PIECE_KING: // 将23 /*console.log("将");*/24 var delta;25 for(var i=0;i<4;i++){26 delta = KING_DELTA[i];27 //沿着方向前进28 var sqDst = sqSrc + delta;29 30 //如果棋子位置不在九宫格上31 if(!IN_FORT(sqDst)){32 continue;33 }34 var pcDst = squares[sqDst];35 //如果棋子为空子或者为对方棋子36 if((pcDst & pcSelfSide) == 0){37 mvs.push(MOVE(sqSrc,sqDst));38 /*console.log(MOVE(sqSrc,sqDst));*/39 }40 }41 break;42 case PIECE_ADVISOR: //士43 /*console.log("士");*/44 var delta;45 for(var i=0;i<4;i++){46 delta = ADVISOR_DELTA[i];47 //沿着方向前进48 var sqDst = sqSrc + delta;49 var pcDst = squares[sqDst];50 //如果棋子位置不在九宫格上51 if(!IN_FORT(sqDst)){52 continue;53 }54 //如果棋子为空子或者为对方棋子55 if((pcDst & pcSelfSide) == 0){56 mvs.push(MOVE(sqSrc,sqDst));57 /*console.log(MOVE(sqSrc,sqDst));*/58 }59 }60 break;61 case PIECE_BISHOP: //象62 /*console.log("象");*/63 var delta;64 for(var i=0;i<4;i++){65 delta = ADVISOR_DELTA[i];66 //得到可能的象眼位置67 var sqEye = sqSrc + delta;68 //如果象眼位置棋子不为空69 if(squares[sqEye] != 0){70 continue;71 }72 //得到可能的终点73 var sqDst = sqEye + delta;74 //如果终点不在真实棋盘75 if(!IN_BOARD(sqDst)){76 continue;77 }78 //如果象跨河79 if(!SAME_HALF(sqSrc,sqDst)){80 continue;81 }82 var pcDst = squares[sqDst];83 //如果终点为对方棋子或者为空84 if((pcDst & pcSelfSide) == 0){85 mvs.push(MOVE(sqSrc,sqDst));86 /*console.log(MOVE(sqSrc,sqDst));*/87 }88 }89 break;90 case PIECE_KNIGHT: //马91 /*console.log("马");*/92 for(var i=0;i<4;i++){93 //马腿94 var leg = sqSrc + KING_DELTA[i];95 //马腿位置存在棋子96 if(squares[leg] != 0){97 continue;98 }99 //马腿位置没有棋子,马腿对应的两个方向100 for(var j=0;j<2;j++){101 var sqDst = sqSrc + KNIGHT_DELTA[i][j];102 if(!IN_BOARD(sqDst)){103 continue;104 }105 var pcDst = squares[sqDst];106 if((pcDst & pcSelfSide) == 0){107 mvs.push(MOVE(sqSrc,sqDst));108 /*console.log(MOVE(sqSrc,sqDst));*/109 }110 }111 }112 break;113 case PIECE_ROOK: //车114 /*console.log("车");*/115 var delta;116 for(var i=0;i<4;i++){117 delta = KING_DELTA[i];118 //沿着该向量前进119 var sqDst = sqSrc + delta;120 while(IN_BOARD(sqDst)){121 if(squares[sqDst] == 0){122 mvs.push(MOVE(sqSrc,sqDst));123 /*console.log(MOVE(sqSrc,sqDst));*/124 } else {125 var pcDst = squares[sqDst];126 if((pcDst & pcOppside) != 0){127 mvs.push(MOVE(sqSrc,sqDst));128 /*console.log(MOVE(sqSrc,sqDst));*/129 }130 break;131 }132 sqDst += delta;133 }134 }135 break;136 case PIECE_CANNON: //炮137 /*console.log("炮");*/138 var delta;139 for(var i=0;i<4;i++){140 delta = KING_DELTA[i];141 //沿着该向量前进142 var sqDst = sqSrc + delta;143 //在棋盘内144 while(IN_BOARD(sqDst)){145 //将空棋子记录到走法中146 if(squares[sqDst] == 0){147 mvs.push(MOVE(sqSrc,sqDst));148 /*console.log(MOVE(sqSrc,sqDst));*/149 } else {150 //遇到非空棋子,退出循环151 break;152 }153 sqDst += delta;154 }155 //此时棋子位置为非空棋子,继续向前走,直到遇到对方棋子156 sqDst += delta;157 while(IN_BOARD(sqDst)){158 var pcDst = squares[sqDst];159 if(pcDst > 0){160 //如果棋子为对方棋子161 if((pcDst & pcSelfSide) == 0){162 mvs.push(MOVE(sqSrc,sqDst));163 /*console.log(MOVE(sqSrc,sqDst));*/164 }165 break;166 }167 sqDst += delta;168 }169 }170 break;171 case PIECE_PAWN:172 /*console.log("兵");*/173 //前进一步,获得对应的位置174 var sqDst = SQUARE_FORWARD(sqSrc,game.sm.board.pos.sdPlayer);175 if(IN_BOARD(sqDst)){176 var pcDst = squares[sqDst];177 if((pcDst & pcSelfSide) == 0){178 mvs.push(MOVE(sqSrc,sqDst));179 /*console.log(MOVE(sqSrc,sqDst));*/180 }181 }182 //如果兵已过河183 if(AWAY_HALF(sqSrc,game.sm.board.pos.sdPlayer)){184 for(var i=-1;i<2;i+=2){185 sqDst = sqSrc + i;186 if(IN_BOARD(sqDst)){187 var pcDst = squares[sqDst];188 if((pcDst & pcSelfSide) == 0){189 mvs.push(MOVE(sqSrc,sqDst));190 /*console.log(MOVE(sqSrc,sqDst));*/191 }192 }193 }194 }195 break;196 }197 }198 return mvs;199 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1console.log(wpt.sq(5));2console.log(wpt.sq(4));3console.log(wpt.sq(3));4console.log(wpt.sq(2));5console.log(wpt.sq(1));6console.log(wpt.sq(0));7console.log(wpt.sq(-1));8console.log(wpt.sq(-2));9console.log(wpt.sq(-3));10console.log(wpt.sq(-4));11console.log(wpt.sq(-5));12console.log(wpt.sq(0.5));13console.log(wpt.sq(0.4));14console.log(wpt.sq(0.3));15console.log(wpt.sq(0.2));16console.log(wpt.sq(0.1));17console.log(wpt.sq(0.0));18console.log(wpt.sq(-0.1));19console.log(wpt.sq(-0.2));20console.log(wpt.sq(-0.3));21console.log(wpt.sq(-0.4));22console.log(wpt.sq(-0.5));23console.log(wpt.sq(0.05));24console.log(wpt.sq(0.04));

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('API_KEY');3 if (err) {4 console.log(err);5 } else {6 console.log('Test Status: ' + data.statusText);7 console.log('Test ID: ' + data.data.testId);8 console.log('Test URL: ' + data.data.userUrl);9 }10 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt');2var wptObj = new wpt();3wptObj.sq(2);4var wpt = function(){5 this.sq = function(num){6 console.log(num*num);7 }8}9module.exports = wpt;10Node.js has a set of built-in modules which you can use without any further installation. To include a built-in module, use the require() function with the name of the module:11var http = require('http');12http.createServer(function (req, res) {13 res.writeHead(200, {'Content-Type': 'text/html'});14 res.end('Hello World!');15}).listen(8080);16To include the File System module, use the require() method:17var fs = require('fs');18var fs = require('fs');19fs.writeFile('mynewfile1.txt', 'Hello content!', function (err) {20 if (err) throw err;21 console.log('Saved!');22});23var fs = require('fs');24fs.writeFile('mynewfile1.txt', 'This is my text', function (err) {25 if (err) throw err;26 console.log('Replaced!');27});28var fs = require('fs');29fs.appendFile('mynewfile1.txt', ' This is my text.', function (err) {30 if (err) throw err;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2wp.sq('SELECT ID, post_title FROM wp_posts LIMIT 10', function(err, data) {3 console.log(data);4});5[ { ID: '1', post_title: 'Hello world!' },6 { ID: '2', post_title: 'Sample Page' },7 { ID: '3', post_title: 'About' },8 { ID: '4', post_title: 'Contact' },9 { ID: '5', post_title: 'Home' },10 { ID: '6', post_title: 'About' },11 { ID: '7', post_title: 'Contact' },12 { ID: '8', post_title: 'Home' },13 { ID: '9', post_title: 'About' },14 { ID: '10', post_title: 'Contact' } ]15var wptoolkit = require('wptoolkit');16wp.sq('SELECT ID, post_title FROM wp_posts LIMIT 10', function(err, data) {17 console.log(data);18});19[ { ID: '1', post_title: 'Hello world!' },20 { ID: '2', post_title: 'Sample Page' },21 { ID: '3', post_title: 'About' },22 { ID: '4', post_title: 'Contact' },23 { ID: '5', post_title: 'Home' },24 { ID: '6', post_title: 'About' },25 { ID: '7', post_title: 'Contact' },26 { ID: '8', post_title: 'Home' },27 { ID: '9', post_title: 'About' },28 { ID: '10', post_title: 'Contact' } ]

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful