Best JavaScript code snippet using wpt
store.js
Source:store.js
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 ],...
Position.js
Source:Position.js
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 }...
Generator.js
Source:Generator.js
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 }...
Using AI Code Generation
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));
Using AI Code Generation
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 });
Using AI Code Generation
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;
Using AI Code Generation
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' } ]
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!