How to use makeMove method in Playwright Internal

Best JavaScript code snippet using playwright-internal

fiverow.js

Source:fiverow.js Github

copy

Full Screen

1// Original code (c) Ben Chenoweth2// Initial version: Dec. 20103// HISTORY:4// 2010-12-09 Ben Chenoweth - Fixed "Player 2 won!" message was not appearing5// 2010-12-11 Mark Nord - temporary fix for use with PRS+v1.1.3 on PRS-505; 6// part.key = character on device -> typecast to number7// 2010-12-12 Mark Nord - try catch block around prsp.compile and newEvent (not needed for PRS-505) 8// 2011-02-07 Ben Chenoweth - HOME button how quits game; force screen update before reader's move.9// 2011-02-10 Ben Chenoweth - Replaced small menu with buttons (touch version).10// 2011-03-01 kartu - Moved into a function, to allow variable name optimizations11// 2011-03-20 Ben Chenoweth - Moved all labels out of the status bar.12// 2011-03-25 Ben Chenoweth - Skins changed over to use common AppAssests.1314var tmp = function () {15 var Exiting;16 var gameover;17 var players = 1;18 var player1turn;19 var firstX = 15;20 var curDX = 50;21 var firstY = 0;22 var curDY = 50;23 var posX;24 var posY;25 var maxX = 11;26 var maxY = 13;27 var col10m = [];28 var oMovesX = [];29 var oMovesY = [];30 var oMoves;31 var xMovesX = [];32 var xMovesY = [];33 var xMoves;34 var xFirstX;35 var xFirstY;36 var isTouch;37 38 /* Mark Nord - Core workaround 39 var newEvent = prsp.compile("param", "return new Event(param)");40 var hasNumericButtons = kbook.autoRunRoot.hasNumericButtons;41 var getSoValue = kbook.autoRunRoot.getSoValue; */42 var getSoValue, hasNumericButtons, newEvent;43 44 //this.bubble("tracelog","id="+id);45 46 target.resetButtons = function () {47 for (x = 0; x < maxX; x++) {48 for (y = 0; y < maxY; y++) {49 if (x < 10) {50 if (y < 10) {51 id = "3Buttons0" + x + '0' + y;52 } else {53 id = "3Buttons0" + x + '' + y;54 }55 } else {56 if (y < 10) {57 id = "3Buttons" + x + '0' + y;58 } else {59 id = "3Buttons" + x + '' + y;60 }61 }62 col10m[x][y] = 0;63 this[id].u = 0;64 }65 }66 }67 68 target.drawgrid1Cursor = function (x, y) {69 this.grid1Cursor.changeLayout(firstX + x * curDX, undefined, undefined, firstY + y * curDY, undefined, undefined);70 }71 72 target.drawgrid2Cursor = function (x, y) {73 this.grid2Cursor.changeLayout(firstX + x * curDX, undefined, undefined, firstY + y * curDY, undefined, undefined);74 }75 76 target.startPlay = function () { 77 posX = 5;78 posY = 6;79 gameover = false;80 firstmove = true;81 oMoves = 0;82 xMoves = 0;83 84 // Reset the board - note that the col10m array needs to be initialised to be one column and row larger than the button array (for board-searching purposes)85 for (var x = 0; x <= maxX; x++) {86 for (var y = 0; y <= maxY; y++) {87 col10m[x][y] = 0;88 if ((x < maxX) && (y < maxY)) {89 if (x < 10) {90 if (y < 10) {91 id = "3Buttons0" + x + '0' + y;92 } else {93 id = "3Buttons0" + x + '' + y;94 }95 } else {96 if (y < 10) {97 id = "3Buttons" + x + '0' + y;98 } else {99 id = "3Buttons" + x + '' + y;100 }101 }102 this[id].u = 0;103 }104 }105 }106 //this.setButtons();107 this.drawgrid1Cursor(posX, posY);108 this.drawgrid2Cursor(posX, posY);109 if (players == 2) {110 this.showTurn.setValue("Player 1's turn...");111 player1turn = true;112 if (!isTouch) {113 this.grid1Cursor.show(true);114 this.grid2Cursor.show(false);115 }116 } else {117 this.showTurn.setValue("Your turn...");118 player1turn = true;119 if (!isTouch) {120 this.grid1Cursor.show(true);121 this.grid2Cursor.show(false);122 }123 }124 }125 126 target.init = function () {127 this.appIcon.u = kbook.autoRunRoot._icon;128 129 /* Mark Nord - temporary Core workaround for PRS+ v1.1.3 */130 131 if(!kbook || !kbook.autoRunRoot || !kbook.autoRunRoot.getSoValue){ 132 if (kbook.simEnviro) { /*Sim without handover code */133 getSoValue = _Core.system.getSoValue;134 hasNumericButtons = _Core.config.compat.hasNumericButtons;135 } else {/* PRS-505 */136 getSoValue = function (obj, propName) {137 return FskCache.mediaMaster.getInstance.call(obj, propName);};138 hasNumericButtons = true;139 }140 try{141 var compile = getSoValue(prsp,"compile");142 newEvent = compile("param", "return new Event(param)");143 } catch(ignore) {} 144 }else { /* code is ok with PRS-600 */145 getSoValue = kbook.autoRunRoot.getSoValue;146 newEvent = prsp.compile("param", "return new Event(param)");147 hasNumericButtons = kbook.autoRunRoot.hasNumericButtons;148 }149 150 if (!hasNumericButtons) {151 isTouch = true;152 this.grid1Cursor.show(false);153 this.grid2Cursor.show(false);154 this.instr1.show(false);155 this.instr2.show(false);156 this.instr3.show(false);157 this.instr4.setValue("HOME: Quit");158 //this.Touch.MENUBAR.show(true);159 160 } else {161 isTouch = false;162 this.grid1Cursor.show(true);163 this.grid2Cursor.show(false);164 this.instr1.show(true);165 this.instr2.show(true);166 this.instr3.show(true);167 this.instr4.setValue("0: Quit");168 //this.Touch.MENUBAR.show(false);169 // this.BUTTON_EXT.show(false);170 this.BUTTON_ONE.show(false);171 this.BUTTON_TWO.show(false);172 }173 // note that the col10m array needs to be initialised to be one column and row larger than the button array (for board-searching purposes)174 for (var a = 0; a <= maxX; a++) {175 col10m[a] = [];176 }177 this.startPlay();178 }179 180 target.placeO = function () {181 var tempX, tempY;182 var prevX, prevY;183 var id, n, cnt;184 var makemove = false;185 var distance, direction, choices;186 187 // Step 1: Try to complete a win: look for 4 "O"s in a row188 for (n = 1; n <= oMoves ; n++) {189 //this.bubble("tracelog","Trying step 1...");190 prevX = oMovesX[n];191 prevY = oMovesY[n];192 193 // top left to bottom right diagonal194 cnt = 0;195 // look in the next 3 spaces196 for (m = 1; m <=3; m++) {197 if ((prevX + m < maxX) && (prevY + m < maxY)) {198 if (col10m[prevX + m][prevY + m] == 2) {199 cnt++;200 }201 }202 }203 if (cnt == 3) {204 // found OOOO, so check if next space is available205 if ((prevX + 4 < maxX) && (prevY + 4 < maxY)) {206 if (col10m[prevX + 4][prevY + 4] == 0) {207 tempX = prevX + 4;208 tempY = prevY + 4;209 makemove = true;210 break;211 }212 }213 // if not, try the previous space214 if ((prevX - 1 >= 0) && (prevY - 1 >= 0)) {215 if (col10m[prevX - 1][prevY - 1] == 0) {216 tempX = prevX - 1;217 tempY = prevY - 1;218 makemove = true;219 break;220 }221 } 222 }223 if (cnt == 2) {224 // found O-OO, OO-O, or OOO-, so look for O-OOO, OO-OO and OOO-O225 if ((prevX + 4 < maxX) && (prevY + 4 < maxY)) {226 // first check for that fifth O227 if (col10m[prevX + 4][prevY + 4] == 2) {228 // then check the spaces inbetween229 if (col10m[prevX + 1][prevY + 1] == 0) {230 tempX = prevX + 1;231 tempY = prevY + 1;232 makemove = true;233 break;234 } else if (col10m[prevX + 2][prevY + 2] == 0) {235 tempX = prevX + 2;236 tempY = prevY + 2;237 makemove = true;238 break;239 } else if (col10m[prevX + 3][prevY + 3] == 0) {240 tempX = prevX + 3;241 tempY = prevY + 3;242 makemove = true;243 break;244 }245 }246 }247 }248 249 // up and down250 cnt = 0;251 // look in the next 3 spaces252 for (m = 1; m <=3; m++) {253 if (prevY + m < maxY) {254 if (col10m[prevX][prevY + m] == 2) {255 cnt++;256 }257 }258 }259 if (cnt == 3) {260 // found OOOO, so check if next space is available261 if (prevY + 4 < maxY) {262 if (col10m[prevX][prevY + 4] == 0) {263 tempX = prevX;264 tempY = prevY + 4;265 makemove = true;266 break;267 }268 }269 // if not, try the previous space270 if (prevY - 1 >= 0) {271 if (col10m[prevX][prevY - 1] == 0) {272 tempX = prevX;273 tempY = prevY - 1;274 makemove = true;275 break;276 }277 } 278 }279 if (cnt == 2) {280 // found O-OO, OO-O, or OOO-, so look for O-OOO, OO-OO and OOO-O281 if (prevY + 4 < maxY) {282 // first check for that fifth O283 if (col10m[prevX][prevY + 4] == 2) {284 // then check the spaces inbetween285 if (col10m[prevX][prevY + 1] == 0) {286 tempX = prevX;287 tempY = prevY + 1;288 makemove = true;289 break;290 } else if (col10m[prevX][prevY + 2] == 0) {291 tempX = prevX;292 tempY = prevY + 2;293 makemove = true;294 break;295 } else if (col10m[prevX][prevY + 3] == 0) {296 tempX = prevX;297 tempY = prevY + 3;298 makemove = true;299 break;300 }301 }302 }303 }304 305 // top right to bottom left diagonal306 cnt = 0;307 // look in the next 3 spaces308 for (m = 1; m <=3; m++) {309 if ((prevX - m >= 0) && (prevY + m < maxY)) {310 if (col10m[prevX - m][prevY + m] == 2) {311 cnt++;312 }313 }314 }315 if (cnt == 3) {316 // found OOOO, so check if next space is available317 if ((prevX - 4 >= 0) && (prevY + 4 < maxY)) {318 if (col10m[prevX - 4][prevY + 4] == 0) {319 tempX = prevX - 4;320 tempY = prevY + 4;321 makemove = true;322 break;323 }324 }325 // if not, try the previous space326 if ((prevX + 1 < maxX) && (prevY - 1 >= 0)) {327 if (col10m[prevX + 1][prevY - 1] == 0) {328 tempX = prevX + 1;329 tempY = prevY - 1;330 makemove = true;331 break;332 }333 } 334 }335 if (cnt == 2) {336 // found O-OO, OO-O, or OOO-, so look for O-OOO, OO-OO and OOO-O337 if ((prevX - 4 >= 0) && (prevY + 4 < maxY)) {338 // first check for that fifth O339 if (col10m[prevX - 4][prevY + 4] == 2) {340 // then check the spaces inbetween341 if (col10m[prevX - 1][prevY + 1] == 0) {342 tempX = prevX - 1;343 tempY = prevY + 1;344 makemove = true;345 break;346 } else if (col10m[prevX - 2][prevY + 2] == 0) {347 tempX = prevX - 2;348 tempY = prevY + 2;349 makemove = true;350 break;351 } else if (col10m[prevX - 3][prevY + 3] == 0) {352 tempX = prevX - 3;353 tempY = prevY + 3;354 makemove = true;355 break;356 }357 }358 }359 }360 361 // left to right362 cnt = 0;363 // look in the next 3 spaces364 for (m = 1; m <=3; m++) {365 if (prevX + m < maxX) {366 if (col10m[prevX + m][prevY] == 2) {367 cnt++;368 }369 }370 }371 if (cnt == 3) {372 // found OOOO, so check if next space is available373 if (prevX + 4 < maxX) {374 if (col10m[prevX + 4][prevY] == 0) {375 tempX = prevX + 4;376 tempY = prevY;377 makemove = true;378 break;379 }380 }381 // if not, try the previous space382 if (prevX - 1 >= 0) {383 if (col10m[prevX - 1][prevY] == 0) {384 tempX = prevX - 1;385 tempY = prevY;386 makemove = true;387 break;388 }389 } 390 }391 if (cnt == 2) {392 // found O-OO, OO-O, or OOO-, so look for O-OOO, OO-OO and OOO-O393 if (prevX + 4 < maxX) {394 // first check for that fifth O395 if (col10m[prevX + 4][prevY] == 2) {396 // then check the spaces inbetween397 if (col10m[prevX + 1][prevY] == 0) {398 tempX = prevX + 1;399 tempY = prevY;400 makemove = true;401 break;402 } else if (col10m[prevX + 2][prevY] == 0) {403 tempX = prevX + 2;404 tempY = prevY;405 makemove = true;406 break;407 } else if (col10m[prevX + 3][prevY] == 0) {408 tempX = prevX + 3;409 tempY = prevY;410 makemove = true;411 break;412 }413 }414 }415 }416 }417 418 // Step 2: Try to block X winning: look for 4 "X"s in a row419 if ((!makemove) && (xMoves > 3)) {420 //this.bubble("tracelog","Trying step 2...");421 for (n = 1; n <= xMoves; n++) {422 prevX = xMovesX[n];423 prevY = xMovesY[n];424 425 // top left to bottom right diagonal426 cnt = 0;427 // look in the next 3 spaces428 for (m = 1; m <=3; m++) {429 if ((prevX + m < maxX) && (prevY + m < maxY)) {430 if (col10m[prevX + m][prevY + m] == 1) {431 cnt++;432 }433 }434 }435 if (cnt == 3) {436 // found XXXX, so check if next space is available437 if ((prevX + 4 < maxX) && (prevY + 4 < maxY)) {438 if (col10m[prevX + 4][prevY + 4] == 0) {439 tempX = prevX + 4;440 tempY = prevY + 4;441 makemove = true;442 break;443 }444 }445 // if not, try the previous space446 if ((prevX - 1 >= 0) && (prevY - 1 >= 0)) {447 if (col10m[prevX - 1][prevY - 1] == 0) {448 tempX = prevX - 1;449 tempY = prevY - 1;450 makemove = true;451 break;452 }453 } 454 }455 if (cnt == 2) {456 // found X-XX, XX-X, or XXX-, so look for X-X, XX-XX and XXX-X457 if ((prevX + 4 < maxX) && (prevY + 4 < maxY)) {458 // first check for that fifth X459 if (col10m[prevX + 4][prevY + 4] == 1) {460 // then check the spaces inbetween461 if (col10m[prevX + 1][prevY + 1] == 0) {462 tempX = prevX + 1;463 tempY = prevY + 1;464 makemove = true;465 break;466 } else if (col10m[prevX + 2][prevY + 2] == 0) {467 tempX = prevX + 2;468 tempY = prevY + 2;469 makemove = true;470 break;471 } else if (col10m[prevX + 3][prevY + 3] == 0) {472 tempX = prevX + 3;473 tempY = prevY + 3;474 makemove = true;475 break;476 }477 }478 }479 }480 481 // up and down482 cnt = 0;483 // look in the next 3 spaces484 for (m = 1; m <=3; m++) {485 if (prevY + m < maxY) {486 if (col10m[prevX][prevY + m] == 1) {487 cnt++;488 }489 }490 }491 if (cnt == 3) {492 // found XXXX, so check if next space is available493 if (prevY + 4 < maxY) {494 if (col10m[prevX][prevY + 4] == 0) {495 tempX = prevX;496 tempY = prevY + 4;497 makemove = true;498 break;499 }500 }501 // if not, try the previous space502 if (prevY - 1 >= 0) {503 if (col10m[prevX][prevY - 1] == 0) {504 tempX = prevX;505 tempY = prevY - 1;506 makemove = true;507 break;508 }509 } 510 }511 if (cnt == 2) {512 // found X-XX, XX-X, or XXX-, so look for X-X, XX-XX and XXX-X513 if (prevY + 4 < maxY) {514 // first check for that fifth X515 if (col10m[prevX][prevY + 4] == 1) {516 // then check the spaces inbetween517 if (col10m[prevX][prevY + 1] == 0) {518 tempX = prevX;519 tempY = prevY + 1;520 makemove = true;521 break;522 } else if (col10m[prevX][prevY + 2] == 0) {523 tempX = prevX;524 tempY = prevY + 2;525 makemove = true;526 break;527 } else if (col10m[prevX][prevY + 3] == 0) {528 tempX = prevX;529 tempY = prevY + 3;530 makemove = true;531 break;532 }533 }534 }535 }536 537 // top right to bottom left diagonal538 cnt = 0;539 // look in the next 3 spaces540 for (m = 1; m <=3; m++) {541 if ((prevX - m >= 0) && (prevY + m < maxY)) {542 if (col10m[prevX - m][prevY + m] == 1) {543 cnt++;544 }545 }546 }547 if (cnt == 3) {548 // found XXXX, so check if next space is available549 if ((prevX - 4 >= 0) && (prevY + 4 < maxY)) {550 if (col10m[prevX - 4][prevY + 4] == 0) {551 tempX = prevX - 4;552 tempY = prevY + 4;553 makemove = true;554 break;555 }556 }557 // if not, try the previous space558 if ((prevX + 1 < maxX) && (prevY - 1 >= 0)) {559 if (col10m[prevX + 1][prevY - 1] == 0) {560 tempX = prevX + 1;561 tempY = prevY - 1;562 makemove = true;563 break;564 }565 } 566 }567 if (cnt == 2) {568 // found X-XX, XX-X, or XXX-, so look for X-X, XX-XX and XXX-X569 if ((prevX - 4 >= 0) && (prevY + 4 < maxY)) {570 // first check for that fifth X571 if (col10m[prevX - 4][prevY + 4] == 1) {572 // then check the spaces inbetween573 if (col10m[prevX - 1][prevY + 1] == 0) {574 tempX = prevX - 1;575 tempY = prevY + 1;576 makemove = true;577 break;578 } else if (col10m[prevX - 2][prevY + 2] == 0) {579 tempX = prevX - 2;580 tempY = prevY + 2;581 makemove = true;582 break;583 } else if (col10m[prevX - 3][prevY + 3] == 0) {584 tempX = prevX - 3;585 tempY = prevY + 3;586 makemove = true;587 break;588 }589 }590 }591 }592 593 // left to right594 cnt = 0;595 // look in the next 3 spaces596 for (m = 1; m <=3; m++) {597 if (prevX + m < maxX) {598 if (col10m[prevX + m][prevY] == 1) {599 cnt++;600 }601 }602 }603 if (cnt == 3) {604 // found XXXX, so check if next space is available605 if (prevX + 4 < maxX) {606 if (col10m[prevX + 4][prevY] == 0) {607 tempX = prevX + 4;608 tempY = prevY;609 makemove = true;610 break;611 }612 }613 // if not, try the previous space614 if (prevX - 1 >= 0) {615 if (col10m[prevX - 1][prevY] == 0) {616 tempX = prevX - 1;617 tempY = prevY;618 makemove = true;619 break;620 }621 } 622 }623 if (cnt == 2) {624 // found X-XX, XX-X, or XXX-, so look for X-X, XX-XX and XXX-X625 if (prevX + 4 < maxX) {626 // first check for that fifth X627 if (col10m[prevX + 4][prevY] == 1) {628 // then check the spaces inbetween629 if (col10m[prevX + 1][prevY] == 0) {630 tempX = prevX + 1;631 tempY = prevY;632 makemove = true;633 break;634 } else if (col10m[prevX + 2][prevY] == 0) {635 tempX = prevX + 2;636 tempY = prevY;637 makemove = true;638 break;639 } else if (col10m[prevX + 3][prevY] == 0) {640 tempX = prevX + 3;641 tempY = prevY;642 makemove = true;643 break;644 }645 }646 }647 }648 }649 }650 651 // Step 3: Try to make 4 "O"s in a row: look for 3 "O"s in a row (with appropriate spaces - at least 2 on one side and 1 on the other)652 if (!makemove) {653 //this.bubble("tracelog","Trying step 3...");654 for (n = 1; n <= oMoves ; n++) {655 prevX = oMovesX[n];656 prevY = oMovesY[n];657 658 // top left to bottom right diagonal659 cnt = 0;660 // look in the next 2 spaces661 for (m = 1; m <=2; m++) {662 if ((prevX + m < maxX) && (prevY + m < maxY)) {663 if (col10m[prevX + m][prevY + m] == 2) {664 cnt++;665 }666 }667 }668 if (cnt == 2) {669 // found OOO, so check if appropriate spaces exist670 // look for --OOO-671 if ((prevX - 2 >= 0) && (prevY - 2 >= 0) && (prevX + 3 < maxX) && (prevY + 3 < maxY)) {672 if ((col10m[prevX - 2][prevY - 2] == 0) && (col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 3][prevY + 3] == 0)) {673 tempX = prevX - 1;674 tempY = prevY - 1;675 makemove = true;676 break;677 }678 }679 // look for -OOO--680 if ((prevX - 1 >= 0) && (prevY - 1 >= 0) && (prevX + 4 < maxX) && (prevY + 4 < maxY)) {681 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 3][prevY + 3] == 0) && (col10m[prevX + 4][prevY + 4] == 0)) {682 tempX = prevX + 3;683 tempY = prevY + 3;684 makemove = true;685 break;686 }687 }688 }689 690 // up and down691 cnt = 0;692 // look in the next 2 spaces693 for (m = 1; m <=2; m++) {694 if (prevY + m < maxY) {695 if (col10m[prevX][prevY + m] == 2) {696 cnt++;697 }698 }699 }700 if (cnt == 2) {701 // found OOO, so check if appropriate spaces exist702 // look for --OOO-703 if ((prevY - 2 >= 0) && (prevY + 3 < maxY)) {704 if ((col10m[prevX][prevY - 2] == 0) && (col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 3] == 0)) {705 tempX = prevX;706 tempY = prevY - 1;707 makemove = true;708 break;709 }710 }711 // look for -OOO--712 if ((prevY - 1 >= 0) && (prevY + 4 < maxY)) {713 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 3] == 0) && (col10m[prevX][prevY + 4] == 0)) {714 tempX = prevX;715 tempY = prevY + 3;716 makemove = true;717 break;718 }719 }720 }721 722 // top right to bottom left diagonal723 cnt = 0;724 // look in the next 2 spaces725 for (m = 1; m <=2; m++) {726 if ((prevX - m >= 0) && (prevY + m < maxY)) {727 if (col10m[prevX - m][prevY + m] == 2) {728 cnt++;729 }730 }731 }732 if (cnt == 2) {733 // found OOO, so check if appropriate spaces exist734 // look for --OOO-735 if ((prevX + 2 < maxX) && (prevY - 2 >= 0) && (prevX - 3 >= 0) && (prevY + 3 < maxY)) {736 if ((col10m[prevX + 2][prevY - 2] == 0) && (col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 3][prevY + 3] == 0)) {737 tempX = prevX + 1;738 tempY = prevY - 1;739 makemove = true;740 break;741 }742 }743 // look for -OOO--744 if ((prevX + 1 < maxX) && (prevY - 1 >= 0) && (prevX - 4 >= 0) && (prevY + 4 < maxY)) {745 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 3][prevY + 3] == 0) && (col10m[prevX - 4][prevY + 4] == 0)) {746 tempX = prevX - 3;747 tempY = prevY + 3;748 makemove = true;749 break;750 }751 }752 }753 754 // left to right755 cnt = 0;756 // look in the next 2 spaces757 for (m = 1; m <=2; m++) {758 if (prevX + m < maxX) {759 if (col10m[prevX + m][prevY] == 2) {760 cnt++;761 }762 }763 }764 if (cnt == 2) {765 // found OOO, so check if appropriate spaces exist766 // look for --OOO-767 if ((prevX - 2 >= 0) && (prevX + 3 < maxX)) {768 if ((col10m[prevX - 2][prevY] == 0) && (col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 3][prevY] == 0)) {769 tempX = prevX - 1;770 tempY = prevY;771 makemove = true;772 break;773 }774 }775 // look for -OOO--776 if ((prevX - 1 >= 0) && (prevX + 4 < maxX)) {777 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 3][prevY] == 0) && (col10m[prevX + 4][prevY] == 0)) {778 tempX = prevX + 3;779 tempY = prevY;780 makemove = true;781 break;782 }783 }784 } 785 }786 }787 788 // Step 4: Handle special cases: look for -O-OO- and -OO-O-789 if (!makemove) {790 //this.bubble("tracelog","Trying step 4...");791 for (n = 1; n <= oMoves ; n++) {792 prevX = oMovesX[n];793 prevY = oMovesY[n];794 795 // top left to bottom right diagonal796 if ((prevX - 1 >= 0) && (prevY - 1 >= 0) && (prevX + 4 < maxX) && (prevY + 4 < maxY)) {797 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 1][prevY + 1] == 0) && (col10m[prevX + 2][prevY + 2] == 2) && (col10m[prevX + 3][prevY + 3] == 2) && (col10m[prevX + 4][prevY + 4] == 0)) {798 tempX = prevX + 1;799 tempY = prevY + 1;800 makemove = true;801 break;802 }803 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 1][prevY + 1] == 2) && (col10m[prevX + 2][prevY + 2] == 0) && (col10m[prevX + 3][prevY + 3] == 2) && (col10m[prevX + 4][prevY + 4] == 0)) {804 tempX = prevX + 2;805 tempY = prevY + 2;806 makemove = true;807 break;808 }809 }810 811 // up and down812 if ((prevY - 1 >= 0) && (prevY + 4 < maxY)) {813 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 1] == 0) && (col10m[prevX][prevY + 2] == 2) && (col10m[prevX][prevY + 3] == 2) && (col10m[prevX][prevY + 4] == 0)) {814 tempX = prevX;815 tempY = prevY + 1;816 makemove = true;817 break;818 }819 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 1] == 2) && (col10m[prevX][prevY + 2] == 0) && (col10m[prevX][prevY + 3] == 2) && (col10m[prevX][prevY + 4] == 0)) {820 tempX = prevX;821 tempY = prevY + 2;822 makemove = true;823 break;824 }825 }826 827 // top right to bottom left diagonal828 if ((prevX + 1 < maxX) && (prevY - 1 >= 0) && (prevX - 4 >= 0) && (prevY + 4 < maxY)) {829 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 1][prevY + 1] == 0) && (col10m[prevX - 2][prevY + 2] == 2) && (col10m[prevX - 3][prevY + 3] == 2) && (col10m[prevX - 4][prevY + 4] == 0)) {830 tempX = prevX - 1;831 tempY = prevY + 1;832 makemove = true;833 break;834 }835 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 1][prevY + 1] == 2) && (col10m[prevX - 2][prevY + 2] == 0) && (col10m[prevX - 3][prevY + 3] == 2) && (col10m[prevX - 4][prevY + 4] == 0)) {836 tempX = prevX - 2;837 tempY = prevY + 2;838 makemove = true;839 break;840 }841 }842 843 // left to right844 if ((prevX - 1 >= 0) && (prevX + 4 < maxX)) {845 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 1][prevY] == 0) && (col10m[prevX + 2][prevY] == 2) && (col10m[prevX + 3][prevY] == 2) && (col10m[prevX + 4][prevY] == 0)) {846 tempX = prevX + 1;847 tempY = prevY;848 makemove = true;849 break;850 }851 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 1][prevY] == 2) && (col10m[prevX + 2][prevY] == 0) && (col10m[prevX + 3][prevY] == 2) && (col10m[prevX + 4][prevY] == 0)) {852 tempX = prevX + 2;853 tempY = prevY;854 makemove = true;855 break;856 }857 }858 }859 }860 861 // Step 5: Look for 3 "O"s in a row with only 1 space on each side862 if (!makemove) {863 //this.bubble("tracelog","Trying step 5...");864 for (n = 1; n <= oMoves ; n++) {865 prevX = oMovesX[n];866 prevY = oMovesY[n];867 868 // top left to bottom right diagonal869 cnt = 0;870 // look in the next 2 spaces871 for (m = 1; m <=2; m++) {872 if ((prevX + m < maxX) && (prevY + m < maxY)) {873 if (col10m[prevX + m][prevY + m] == 2) {874 cnt++;875 }876 }877 }878 if (cnt == 2) {879 // found OOO, so check if appropriate spaces exist880 // look for -OOO-881 if ((prevX - 1 >= 0) && (prevY - 1 >= 0) && (prevX + 3 < maxX) && (prevY + 3 < maxY)) {882 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 3][prevY + 3] == 0)) {883 tempX = prevX - 1;884 tempY = prevY - 1;885 makemove = true;886 break;887 }888 }889 }890 891 // up and down892 cnt = 0;893 // look in the next 2 spaces894 for (m = 1; m <=2; m++) {895 if (prevY + m < maxY) {896 if (col10m[prevX][prevY + m] == 2) {897 cnt++;898 }899 }900 }901 if (cnt == 2) {902 // found OOO, so check if appropriate spaces exist903 // look for -OOO-904 if ((prevY - 1 >= 0) && (prevY + 3 < maxY)) {905 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 3] == 0)) {906 tempX = prevX;907 tempY = prevY - 1;908 makemove = true;909 break;910 }911 }912 }913 914 // top right to bottom left diagonal915 cnt = 0;916 // look in the next 2 spaces917 for (m = 1; m <=2; m++) {918 if ((prevX - m >= 0) && (prevY + m < maxY)) {919 if (col10m[prevX - m][prevY + m] == 2) {920 cnt++;921 }922 }923 }924 if (cnt == 2) {925 // found OOO, so check if appropriate spaces exist926 // look for -OOO-927 if ((prevX + 1 < maxX) && (prevY - 1 >= 0) && (prevX - 3 >= 0) && (prevY + 3 < maxY)) {928 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 3][prevY + 3] == 0)) {929 tempX = prevX + 1;930 tempY = prevY - 1;931 makemove = true;932 break;933 }934 }935 }936 937 // left to right938 cnt = 0;939 // look in the next 2 spaces940 for (m = 1; m <=2; m++) {941 if (prevX + m < maxX) {942 if (col10m[prevX + m][prevY] == 2) {943 cnt++;944 }945 }946 }947 if (cnt == 2) {948 // found OOO, so check if appropriate spaces exist949 // look for -OOO-950 if ((prevX - 1 >= 0) && (prevX + 3 < maxX)) {951 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 3][prevY] == 0)) {952 tempX = prevX - 1;953 tempY = prevY;954 makemove = true;955 break;956 }957 }958 } 959 } 960 }961 962 // Step 6: Handle special cases: Look for O--OO and OO--O963 if (!makemove) {964 //this.bubble("tracelog","Trying step 6...");965 for (n = 1; n <= oMoves ; n++) {966 prevX = oMovesX[n];967 prevY = oMovesY[n];968 969 // top left to bottom right diagonal970 if ((prevX + 4 < maxX) && (prevY + 4 < maxY)) {971 if ((col10m[prevX + 1][prevY + 1] == 0) && (col10m[prevX + 2][prevY + 2] == 0) && (col10m[prevX + 3][prevY + 3] == 2) && (col10m[prevX + 4][prevY + 4] == 2)) {972 tempX = prevX + 2;973 tempY = prevY + 2;974 makemove = true;975 break;976 }977 if ((col10m[prevX + 1][prevY + 1] == 2) && (col10m[prevX + 2][prevY + 2] == 0) && (col10m[prevX + 3][prevY + 3] == 0) && (col10m[prevX + 4][prevY + 4] == 2)) {978 tempX = prevX + 2;979 tempY = prevY + 2;980 makemove = true;981 break;982 } 983 }984 985 // up and down986 if (prevY + 4 < maxY) {987 if ((col10m[prevX][prevY + 1] == 0) && (col10m[prevX][prevY + 2] == 0) && (col10m[prevX][prevY + 3] == 2) && (col10m[prevX][prevY + 4] == 2)) {988 tempX = prevX;989 tempY = prevY + 2;990 makemove = true;991 break;992 }993 if ((col10m[prevX][prevY + 1] == 2) && (col10m[prevX][prevY + 2] == 0) && (col10m[prevX][prevY + 3] == 0) && (col10m[prevX][prevY + 4] == 2)) {994 tempX = prevX;995 tempY = prevY + 2;996 makemove = true;997 break;998 }999 }1000 1001 // top right to bottom left diagonal1002 if ((prevX - 4 >= 0) && (prevY + 4 < maxY)) {1003 if ((col10m[prevX - 1][prevY + 1] == 0) && (col10m[prevX - 2][prevY + 2] == 0) && (col10m[prevX - 3][prevY + 3] == 2) && (col10m[prevX - 4][prevY + 4] == 2)) {1004 tempX = prevX - 2;1005 tempY = prevY + 2;1006 makemove = true;1007 break;1008 }1009 if ((col10m[prevX - 1][prevY + 1] == 2) && (col10m[prevX - 2][prevY + 2] == 0) && (col10m[prevX - 3][prevY + 3] == 0) && (col10m[prevX - 4][prevY + 4] == 2)) {1010 tempX = prevX - 2;1011 tempY = prevY + 2;1012 makemove = true;1013 break;1014 }1015 }1016 1017 // left to right1018 if (prevX + 3 < maxX) {1019 if ((col10m[prevX + 1][prevY] == 0) && (col10m[prevX + 2][prevY] == 0) && (col10m[prevX + 3][prevY] == 2) && (col10m[prevX + 4][prevY] == 2)) {1020 tempX = prevX + 2;1021 tempY = prevY;1022 makemove = true;1023 break;1024 }1025 if ((col10m[prevX + 1][prevY] == 2) && (col10m[prevX + 2][prevY] == 0) && (col10m[prevX + 3][prevY] == 0) && (col10m[prevX + 4][prevY] == 2)) {1026 tempX = prevX + 2;1027 tempY = prevY;1028 makemove = true;1029 break;1030 }1031 }1032 } 1033 }1034 1035 // Step 7: Handle special cases: Look for -X-XX- and -XX-X-1036 if (!makemove) {1037 //this.bubble("tracelog","Trying step 7...");1038 for (n = 1; n <= xMoves ; n++) {1039 prevX = xMovesX[n];1040 prevY = xMovesY[n];1041 1042 // top left to bottom right diagonal1043 if ((prevX - 1 >= 0) && (prevY - 1 >= 0) && (prevX + 4 < maxX) && (prevY + 4 < maxY)) {1044 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 1][prevY + 1] == 0) && (col10m[prevX + 2][prevY + 2] == 1) && (col10m[prevX + 3][prevY + 3] == 1) && (col10m[prevX + 4][prevY + 4] == 0)) {1045 tempX = prevX + 1;1046 tempY = prevY + 1;1047 makemove = true;1048 break;1049 }1050 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 1][prevY + 1] == 1) && (col10m[prevX + 2][prevY + 2] == 0) && (col10m[prevX + 3][prevY + 3] == 1) && (col10m[prevX + 4][prevY + 4] == 0)) {1051 tempX = prevX + 2;1052 tempY = prevY + 2;1053 makemove = true;1054 break;1055 }1056 }1057 1058 // up and down1059 if ((prevY - 1 >= 0) && (prevY + 4 < maxY)) {1060 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 1] == 0) && (col10m[prevX][prevY + 2] == 1) && (col10m[prevX][prevY + 3] == 1) && (col10m[prevX][prevY + 4] == 0)) {1061 tempX = prevX;1062 tempY = prevY + 1;1063 makemove = true;1064 break;1065 }1066 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 1] == 1) && (col10m[prevX][prevY + 2] == 0) && (col10m[prevX][prevY + 3] == 1) && (col10m[prevX][prevY + 4] == 0)) {1067 tempX = prevX;1068 tempY = prevY + 2;1069 makemove = true;1070 break;1071 }1072 }1073 1074 // top right to bottom left diagonal1075 if ((prevX + 1 < maxX) && (prevY - 1 >= 0) && (prevX - 4 >= 0) && (prevY + 4 < maxY)) {1076 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 1][prevY + 1] == 0) && (col10m[prevX - 2][prevY + 2] == 1) && (col10m[prevX - 3][prevY + 3] == 1) && (col10m[prevX - 4][prevY + 4] == 0)) {1077 tempX = prevX - 1;1078 tempY = prevY + 1;1079 makemove = true;1080 break;1081 }1082 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 1][prevY + 1] == 1) && (col10m[prevX - 2][prevY + 2] == 0) && (col10m[prevX - 3][prevY + 3] == 1) && (col10m[prevX - 4][prevY + 4] == 0)) {1083 tempX = prevX - 2;1084 tempY = prevY + 2;1085 makemove = true;1086 break;1087 }1088 }1089 1090 // left to right1091 if ((prevX - 1 >= 0) && (prevX + 4 < maxX)) {1092 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 1][prevY] == 0) && (col10m[prevX + 2][prevY] == 1) && (col10m[prevX + 3][prevY] == 1) && (col10m[prevX + 4][prevY] == 0)) {1093 tempX = prevX + 1;1094 tempY = prevY;1095 makemove = true;1096 break;1097 }1098 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 1][prevY] == 1) && (col10m[prevX + 2][prevY] == 0) && (col10m[prevX + 3][prevY] == 1) && (col10m[prevX + 4][prevY] == 0)) {1099 tempX = prevX + 2;1100 tempY = prevY;1101 makemove = true;1102 break;1103 }1104 }1105 }1106 } 1107 1108 // Step 8: Block X getting four in a row: look for 3 "X"s in a row (with appropriate spaces - at least 2 on one side and 1 on the other)1109 if (!makemove) {1110 //this.bubble("tracelog","Trying step 8...");1111 for (n = 1; n <= xMoves ; n++) {1112 prevX = xMovesX[n];1113 prevY = xMovesY[n];1114 1115 // top left to bottom right diagonal1116 cnt = 0;1117 // look in the next 2 spaces1118 for (m = 1; m <=2; m++) {1119 if ((prevX + m < maxX) && (prevY + m < maxY)) {1120 if (col10m[prevX + m][prevY + m] == 1) {1121 cnt++;1122 }1123 }1124 }1125 if (cnt == 2) {1126 // found XXX, so check if appropriate spaces exist1127 // look for --XXX-1128 if ((prevX - 2 >= 0) && (prevY - 2 >= 0) && (prevX + 3 < maxX) && (prevY + 3 < maxY)) {1129 if ((col10m[prevX - 2][prevY - 2] == 0) && (col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 3][prevY + 3] == 0)) {1130 tempX = prevX - 1;1131 tempY = prevY - 1;1132 makemove = true;1133 break;1134 }1135 }1136 // look for -XXX--1137 if ((prevX - 1 >= 0) && (prevY - 1 >= 0) && (prevX + 4 < maxX) && (prevY + 4 < maxY)) {1138 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 3][prevY + 3] == 0) && (col10m[prevX + 4][prevY + 4] == 0)) {1139 tempX = prevX + 3;1140 tempY = prevY + 3;1141 makemove = true;1142 break;1143 }1144 }1145 }1146 1147 // up and down1148 cnt = 0;1149 // look in the next 2 spaces1150 for (m = 1; m <=2; m++) {1151 if (prevY + m < maxY) {1152 if (col10m[prevX][prevY + m] == 1) {1153 cnt++;1154 }1155 }1156 }1157 if (cnt == 2) {1158 // found XXX, so check if appropriate spaces exist1159 // look for --XXX-1160 if ((prevY - 2 >= 0) && (prevY + 3 < maxY)) {1161 if ((col10m[prevX][prevY - 2] == 0) && (col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 3] == 0)) {1162 tempX = prevX;1163 tempY = prevY - 1;1164 makemove = true;1165 break;1166 }1167 }1168 // look for -XXX--1169 if ((prevY - 1 >= 0) && (prevY + 4 < maxY)) {1170 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 3] == 0) && (col10m[prevX][prevY + 4] == 0)) {1171 tempX = prevX;1172 tempY = prevY + 3;1173 makemove = true;1174 break;1175 }1176 }1177 }1178 1179 // top right to bottom left diagonal1180 cnt = 0;1181 // look in the next 2 spaces1182 for (m = 1; m <=2; m++) {1183 if ((prevX - m >= 0) && (prevY + m < maxY)) {1184 if (col10m[prevX - m][prevY + m] == 1) {1185 cnt++;1186 }1187 }1188 }1189 if (cnt == 2) {1190 // found XXX, so check if appropriate spaces exist1191 // look for --XXX-1192 if ((prevX + 2 < maxX) && (prevY - 2 >= 0) && (prevX - 3 >= 0) && (prevY + 3 < maxY)) {1193 if ((col10m[prevX + 2][prevY - 2] == 0) && (col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 3][prevY + 3] == 0)) {1194 tempX = prevX + 1;1195 tempY = prevY - 1;1196 makemove = true;1197 break;1198 }1199 }1200 // look for -XXX--1201 if ((prevX + 1 < maxX) && (prevY - 1 >= 0) && (prevX - 4 >= 0) && (prevY + 4 < maxY)) {1202 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 3][prevY + 3] == 0) && (col10m[prevX - 4][prevY + 4] == 0)) {1203 tempX = prevX - 3;1204 tempY = prevY + 3;1205 makemove = true;1206 break;1207 }1208 }1209 }1210 1211 // left to right1212 cnt = 0;1213 // look in the next 2 spaces1214 for (m = 1; m <=2; m++) {1215 if (prevX + m < maxX) {1216 if (col10m[prevX + m][prevY] == 1) {1217 cnt++;1218 }1219 }1220 }1221 if (cnt == 2) {1222 // found XXX, so check if appropriate spaces exist1223 // look for --XXX-1224 if ((prevX - 2 >= 0) && (prevX + 3 < maxX)) {1225 if ((col10m[prevX - 2][prevY] == 0) && (col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 3][prevY] == 0)) {1226 tempX = prevX - 1;1227 tempY = prevY;1228 makemove = true;1229 break;1230 }1231 }1232 // look for -XXX--1233 if ((prevX - 1 >= 0) && (prevX + 4 < maxX)) {1234 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 3][prevY] == 0) && (col10m[prevX + 4][prevY] == 0)) {1235 tempX = prevX + 3;1236 tempY = prevY;1237 makemove = true;1238 break;1239 }1240 }1241 } 1242 } 1243 }1244 1245 // Step 9: Try to form 3 "O"s in a row: look for two "O"s in a row with sufficient space to form -OOOO-1246 if (!makemove) {1247 //this.bubble("tracelog","Trying step 9...");1248 for (n = 1; n <= oMoves ; n++) {1249 prevX = oMovesX[n];1250 prevY = oMovesY[n];1251 1252 // top left to bottom right diagonal1253 if ((prevX + 1 < maxX) && (prevY + 1 < maxY)) {1254 if (col10m[prevX + 1][prevY + 1] == 2) {1255 // found OO, so check for ---OO-, --OO--, -OO---1256 if ((prevX - 3 >= 0) && (prevY - 3 >= 0) && (prevX + 2 < maxX) && (prevY + 2 < maxY)) {1257 if ((col10m[prevX - 3][prevY - 3] == 0) && (col10m[prevX - 2][prevY - 2] == 0) && (col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 2][prevY + 2] == 0)) {1258 tempX = prevX - 1;1259 tempY = prevY - 1;1260 makemove = true;1261 break;1262 }1263 } else if ((prevX - 2 >= 0) && (prevY - 2 >= 0) && (prevX + 3 < maxX) && (prevY + 3 < maxY)) {1264 if ((col10m[prevX - 2][prevY - 2] == 0) && (col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 2][prevY + 2] == 0) && (col10m[prevX + 3][prevY + 3] == 0)) {1265 tempX = prevX + 2;1266 tempY = prevY + 2;1267 makemove = true;1268 break;1269 } 1270 } else if ((prevX - 1 >= 0) && (prevY - 1 >= 0) && (prevX + 4 < maxX) && (prevY + 4 < maxY)) {1271 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 2][prevY + 2] == 0) && (col10m[prevX + 3][prevY + 3] == 0) && (col10m[prevX + 4][prevY + 4] == 0)) {1272 tempX = prevX + 2;1273 tempY = prevY + 2;1274 makemove = true;1275 break;1276 } 1277 }1278 }1279 }1280 1281 // up and down1282 if (prevY + 1 < maxY) {1283 if (col10m[prevX][prevY + 1] == 2) {1284 // found OO, so check for ---OO-, --OO--, -OO---1285 if ((prevY - 3 >= 0) && (prevY + 2 < maxY)) {1286 if ((col10m[prevX][prevY - 3] == 0) && (col10m[prevX][prevY - 2] == 0) && (col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 2] == 0)) {1287 tempX = prevX;1288 tempY = prevY - 1;1289 makemove = true;1290 break;1291 }1292 } else if ((prevY - 2 >= 0) && (prevY + 3 < maxY)) {1293 if ((col10m[prevX][prevY - 2] == 0) && (col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 2] == 0) && (col10m[prevX][prevY + 3] == 0)) {1294 tempX = prevX;1295 tempY = prevY + 2;1296 makemove = true;1297 break;1298 } 1299 } else if ((prevY - 1 >= 0) && (prevY + 4 < maxY)) {1300 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 2] == 0) && (col10m[prevX][prevY + 3] == 0) && (col10m[prevX][prevY + 4] == 0)) {1301 tempX = prevX;1302 tempY = prevY + 2;1303 makemove = true;1304 break;1305 } 1306 }1307 }1308 }1309 1310 // top right to bottom left diagonal1311 if ((prevX - 1 >= 0) && (prevY + 1 < maxY)) {1312 if (col10m[prevX - 1][prevY + 1] == 2) {1313 // found OO, so check for ---OO-, --OO--, -OO---1314 if ((prevX + 3 < maxX) && (prevY - 3 >= 0) && (prevX - 2 >= 0) && (prevY + 2 < maxY)) {1315 if ((col10m[prevX + 3][prevY - 3] == 0) && (col10m[prevX + 2][prevY - 2] == 0) && (col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 2][prevY + 2] == 0)) {1316 tempX = prevX + 1;1317 tempY = prevY - 1;1318 makemove = true;1319 break;1320 }1321 } else if ((prevX + 2 < maxX) && (prevY - 2 >= 0) && (prevX - 3 >= 0) && (prevY + 3 < maxY)) {1322 if ((col10m[prevX + 2][prevY - 2] == 0) && (col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 2][prevY + 2] == 0) && (col10m[prevX - 3][prevY + 3] == 0)) {1323 tempX = prevX - 2;1324 tempY = prevY + 2;1325 makemove = true;1326 break;1327 } 1328 } else if ((prevX + 1 < maxX) && (prevY - 1 >= 0) && (prevX - 4 >= 0) && (prevY + 4 < maxY)) {1329 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 2][prevY + 2] == 0) && (col10m[prevX - 3][prevY + 3] == 0) && (col10m[prevX - 4][prevY + 4] == 0)) {1330 tempX = prevX - 2;1331 tempY = prevY + 2;1332 makemove = true;1333 break;1334 } 1335 }1336 }1337 }1338 1339 // left to right1340 if (prevX + 1 < maxX) {1341 if (col10m[prevX + 1][prevY] == 2) {1342 // found OO, so check for ---OO-, --OO--, -OO---1343 if ((prevX - 3 >= 0) && (prevX + 2 < maxX)) {1344 if ((col10m[prevX - 3][prevY] == 0) && (col10m[prevX - 2][prevY] == 0) && (col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 2][prevY] == 0)) {1345 tempX = prevX - 1;1346 tempY = prevY;1347 makemove = true;1348 break;1349 }1350 } else if ((prevX - 2 >= 0) && (prevX + 3 < maxX)) {1351 if ((col10m[prevX - 2][prevY] == 0) && (col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 2][prevY] == 0) && (col10m[prevX + 3][prevY] == 0)) {1352 tempX = prevX + 2;1353 tempY = prevY;1354 makemove = true;1355 break;1356 } 1357 } else if ((prevX - 1 >= 0) && (prevX + 4 < maxX)) {1358 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 2][prevY] == 0) && (col10m[prevX + 3][prevY] == 0) && (col10m[prevX + 4][prevY] == 0)) {1359 tempX = prevX + 2;1360 tempY = prevY;1361 makemove = true;1362 break;1363 } 1364 }1365 }1366 } 1367 }1368 }1369 1370 // Step 10: Handle special case: Look for -O-O-1371 if (!makemove) {1372 //this.bubble("tracelog","Trying step 10...");1373 for (n = 1; n <= oMoves ; n++) {1374 prevX = oMovesX[n];1375 prevY = oMovesY[n];1376 1377 // top left to bottom right diagonal1378 if ((prevX - 1 >= 0) && (prevY - 1 >= 0) && (prevX + 3 < maxX) && (prevY + 3 < maxY)) {1379 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 1][prevY + 1] == 0) && (col10m[prevX + 2][prevY + 2] == 2) && (col10m[prevX + 3][prevY + 3] == 0)) {1380 tempX = prevX + 1;1381 tempY = prevY + 1;1382 makemove = true;1383 break;1384 }1385 }1386 1387 // up and down1388 if ((prevY - 1 >=0) && (prevY + 3 < maxY)) {1389 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 1] == 0) && (col10m[prevX][prevY + 2] == 2) && (col10m[prevX][prevY + 3] == 0)) {1390 tempX = prevX;1391 tempY = prevY + 1;1392 makemove = true;1393 break;1394 }1395 }1396 1397 // top right to bottom left diagonal1398 if ((prevX + 1 < maxX) && (prevY - 1 >= 0) && (prevX - 3 >= 0) && (prevY + 3 < maxY)) {1399 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 1][prevY + 1] == 0) && (col10m[prevX - 2][prevY + 2] == 2) && (col10m[prevX - 3][prevY + 3] == 0)) {1400 tempX = prevX - 1;1401 tempY = prevY + 1;1402 makemove = true;1403 break;1404 }1405 }1406 1407 // left to right1408 if ((prevX - 1 >= 0) && (prevX + 3 < maxX)) {1409 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 1][prevY] == 0) && (col10m[prevX + 2][prevY] == 2) && (col10m[prevX + 3][prevY] == 0)) {1410 tempX = prevX + 1;1411 tempY = prevY;1412 makemove = true;1413 break;1414 }1415 }1416 }1417 } 1418 1419 // Step 11: Try to form 3 "O"s in a row: look for two "O"s in a row with only just enough space to form 5 "O"s1420 if (!makemove) {1421 //this.bubble("tracelog","Trying step 11...");1422 for (n = 1; n <= oMoves ; n++) {1423 prevX = oMovesX[n];1424 prevY = oMovesY[n];1425 1426 // top left to bottom right diagonal1427 if ((prevX + 1 < maxX) && (prevY + 1 < maxY)) {1428 if (col10m[prevX + 1][prevY + 1] == 2) {1429 // found OO, so check for --OO-, -OO--1430 if ((prevX - 2 >= 0) && (prevY - 2 >= 0) && (prevX + 2 < maxX) && (prevY + 2 < maxY)) {1431 if ((col10m[prevX - 2][prevY - 2] == 0) && (col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 2][prevY + 2] == 0)) {1432 tempX = prevX - 1;1433 tempY = prevY - 1;1434 makemove = true;1435 break;1436 }1437 } else if ((prevX - 1 >= 0) && (prevY - 1 >= 0) && (prevX + 3 < maxX) && (prevY + 3 < maxY)) {1438 if ((col10m[prevX - 1][prevY - 1] == 0) && (col10m[prevX + 2][prevY + 2] == 0) && (col10m[prevX + 3][prevY + 3] == 0)) {1439 tempX = prevX + 2;1440 tempY = prevY + 2;1441 makemove = true;1442 break;1443 } 1444 }1445 }1446 }1447 1448 // up and down1449 if (prevY + 1 < maxY) {1450 if (col10m[prevX][prevY + 1] == 2) {1451 // found OO, so check for --OO-, -OO--1452 if ((prevY - 2 >= 0) && (prevY + 2 < maxY)) {1453 if ((col10m[prevX][prevY - 2] == 0) && (col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 2] == 0)) {1454 tempX = prevX;1455 tempY = prevY - 1;1456 makemove = true;1457 break;1458 }1459 } else if ((prevY - 1 >= 0) && (prevY + 3 < maxY)) {1460 if ((col10m[prevX][prevY - 1] == 0) && (col10m[prevX][prevY + 2] == 0) && (col10m[prevX][prevY + 3] == 0)) {1461 tempX = prevX;1462 tempY = prevY + 2;1463 makemove = true;1464 break;1465 } 1466 }1467 }1468 }1469 1470 // top right to bottom left diagonal1471 if ((prevX - 1 >= 0) && (prevY + 1 < maxY)) {1472 if (col10m[prevX - 1][prevY + 1] == 2) {1473 // found OO, so check for --OO-, -OO--1474 if ((prevX + 2 < maxX) && (prevY - 2 >= 0) && (prevX - 2 >= 0) && (prevY + 2 < maxY)) {1475 if ((col10m[prevX + 2][prevY - 2] == 0) && (col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 2][prevY + 2] == 0)) {1476 tempX = prevX + 1;1477 tempY = prevY - 1;1478 makemove = true;1479 break;1480 }1481 } else if ((prevX + 1 < maxX) && (prevY - 1 >= 0) && (prevX - 3 >= 0) && (prevY + 3 < maxY)) {1482 if ((col10m[prevX + 1][prevY - 1] == 0) && (col10m[prevX - 2][prevY + 2] == 0) && (col10m[prevX - 3][prevY + 3] == 0)) {1483 tempX = prevX - 2;1484 tempY = prevY + 2;1485 makemove = true;1486 break;1487 } 1488 }1489 }1490 }1491 1492 // left to right1493 if (prevX + 1 < maxX) {1494 if (col10m[prevX + 1][prevY] == 2) {1495 // found OO, so check for --OO-, -OO--1496 if ((prevX - 2 >= 0) && (prevX + 2 < maxX)) {1497 if ((col10m[prevX - 2][prevY] == 0) && (col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 2][prevY] == 0)) {1498 tempX = prevX - 1;1499 tempY = prevY;1500 makemove = true;1501 break;1502 }1503 } else if ((prevX - 1 >= 0) && (prevX + 3 < maxX)) {1504 if ((col10m[prevX - 1][prevY] == 0) && (col10m[prevX + 2][prevY] == 0) && (col10m[prevX + 3][prevY] == 0)) {1505 tempX = prevX + 2;1506 tempY = prevY;1507 makemove = true;1508 break;1509 } 1510 }1511 }1512 } 1513 }1514 }1515 1516 // Step 12: Play a semi-random move near one of the previous moves1517 if (!makemove) {1518 //this.bubble("tracelog","Trying step 12...");1519 loop1:1520 for (n=1; n <= oMoves; n++) {1521 prevX = oMovesX[n];1522 prevY = oMovesY[n];1523 choices = 0;1524 distance = 1;1525 loop2:1526 do1527 {1528 do1529 {1530 choices++;1531 if (choices == 15) {1532 break loop2;1533 }1534 direction = Math.ceil(Math.random() * 8);1535 loop3:1536 switch (direction) {1537 case 1:1538 {1539 tempX = prevX - distance;1540 tempY = prevY - distance;1541 break loop3;1542 }1543 case 2:1544 {1545 tempX = prevX;1546 tempY = prevY - distance;1547 break loop3;1548 }1549 case 3:1550 {1551 tempX = prevX + distance;1552 tempY = prevY - distance;1553 break loop3;1554 }1555 case 4:1556 {1557 tempX = prevX - distance;1558 tempY = prevY;1559 break loop3;1560 }1561 case 5:1562 {1563 tempX = prevX + distance;1564 tempY = prevY;1565 break loop3;1566 }1567 case 6:1568 {1569 tempX = prevX - distance;1570 tempY = prevY + distance;1571 break loop3;1572 }1573 case 7:1574 {1575 tempX = prevX;1576 tempY = prevY + distance;1577 break loop3;1578 }1579 case 8:1580 {1581 tempX = prevX + distance;1582 tempY = prevY + distance;1583 } 1584 }1585 } while ((tempX < 0) || (tempX >= maxX) || (tempY < 0) || (tempY >= maxY));1586 } while (col10m[tempX][tempY] != 0);1587 if ((choices != 15) && (col10m[tempX][tempY] == 0)) {1588 // found a space next to one of O's moves1589 makemove = true;1590 break loop1;1591 }1592 }1593 }1594 1595 // Step 13: Forced to play a dud move: random "O"1596 if ((oMoves != 0) && (!makemove)) {1597 //this.bubble("tracelog","Trying step 13 - random!...");1598 do1599 {1600 tempX = Math.floor(Math.random() * maxX);1601 tempY = Math.floor(Math.random() * maxY);1602 }1603 while (col10m[tempX][tempY] != 0);1604 }1605 1606 // Make first move near X's first move1607 if (oMoves == 0) {1608 do1609 {1610 tempX = xMovesX[1];1611 tempY = xMovesY[1];1612 distance = Math.ceil(Math.random() * 2);1613 direction = Math.ceil(Math.random() * 8);1614 switch (direction) {1615 case 1:1616 {1617 tempX = tempX - distance;1618 tempY = tempY - distance;1619 break;1620 }1621 case 2:1622 {1623 tempY = tempY - distance;1624 break;1625 }1626 case 3:1627 {1628 tempX = tempX + distance;1629 tempY = tempY - distance;1630 break;1631 }1632 case 4:1633 {1634 tempX = tempX - distance;1635 break;1636 }1637 case 5:1638 {1639 tempX = tempX + distance;1640 break;1641 }1642 case 6:1643 {1644 tempX = tempX - distance;1645 tempY = tempY + distance;1646 break;1647 }1648 case 7:1649 {1650 tempY = tempY + distance;1651 break;1652 }1653 case 8:1654 {1655 tempX = tempX + distance;1656 tempY = tempY + distance;1657 } 1658 }1659 } while ((tempX < 0) || (tempX >= maxX) || (tempY < 0) || (tempY >= maxY));1660 }1661 1662 if (tempX < 10) {1663 if (tempY < 10) {1664 id = "3Buttons0" + tempX + '0' + tempY;1665 } else {1666 id = "3Buttons0" + tempX + '' + tempY;1667 }1668 } else {1669 if (tempY < 10) {1670 id = "3Buttons" + tempX + '0' + tempY;1671 } else {1672 id = "3Buttons" + tempX + '' + tempY;1673 }1674 }1675 col10m[tempX][tempY] = 2;1676 oMoves++; // first move stored in oMovesX[1] and oMovesY[1]1677 oMovesX[oMoves] = tempX;1678 oMovesY[oMoves] = tempY;1679 return id;1680 }1681 1682 target.checkWin = function (player) {1683 var x, y, tempX, tempY, n;1684 var tempXA = [];1685 var tempYA = [];1686 1687 var res = false;1688 var winsofar = 0;1689 var inarow;1690 1691 //searching for diagonals going from top left to bottom right1692 for (y = 0; y < maxY - 4; y++) {1693 for (x = 0; x < maxX - 4; x++) {1694 if (col10m[x][y] == player) {1695 tempX = x;1696 tempY = y;1697 inarow = 0;1698 do1699 {1700 tempXA[winsofar + inarow] = tempX;1701 tempYA[winsofar + inarow] = tempY;1702 inarow++;1703 tempX++;1704 tempY++;1705 }1706 while ((col10m[tempX][tempY] == player) && (tempX < maxX) && (tempY < maxY));1707 if (inarow > 4) {1708 winsofar = winsofar + inarow;1709 }1710 }1711 }1712 }1713 1714 //searching for diagonals going from top right to bottom left1715 for (y = 4; y < maxY; y++) {1716 for (x = 0; x < maxX; x++) {1717 if (col10m[x][y] == player) {1718 tempX = x;1719 tempY = y;1720 inarow = 0;1721 do1722 {1723 tempXA[winsofar + inarow] = tempX;1724 tempYA[winsofar + inarow] = tempY;1725 inarow++;1726 tempX++;1727 tempY--;1728 }1729 while ((col10m[tempX][tempY] == player) && (tempX < maxX) && (tempY > 0));1730 if (inarow > 4) {1731 winsofar = winsofar + inarow;1732 }1733 }1734 }1735 }1736 1737 //special search for diagonals going from top right to bottom left starting in the top row1738 for (x = maxX; x > 4; x--) {1739 if (col10m[x][0] == player) {1740 tempX = x;1741 tempY = 0;1742 inarow = 0;1743 do1744 {1745 tempXA[winsofar + inarow] = tempX;1746 tempYA[winsofar + inarow] = tempY;1747 inarow++;1748 tempX--;1749 tempY++;1750 }1751 while ((col10m[tempX][tempY] == player) && (tempX > 0) && (tempY < maxY));1752 if (inarow > 4) {1753 winsofar = winsofar + inarow;1754 }1755 }1756 }1757 1758 //special handling of one tricky diagonal1759 if ((col10m[4][0] == player) && (col10m[3][1] == player) && (col10m[2][2] == player) && (col10m[1][3] == player) && (col10m[0][4] == player)) {1760 tempXA[winsofar] = 4;1761 tempYA[winsofar] = 0;1762 tempXA[winsofar + 1] = 3;1763 tempYA[winsofar + 1] = 1;1764 tempXA[winsofar + 2] = 2;1765 tempYA[winsofar + 2] = 2;1766 tempXA[winsofar + 3] = 1;1767 tempYA[winsofar + 3] = 3;1768 tempXA[winsofar + 4] = 0;1769 tempYA[winsofar + 4] = 4;1770 winsofar = winsofar + 5;1771 }1772 1773 //searching for up and down1774 for (y = 0; y < maxY - 4; y++) {1775 for (x = 0; x < maxX; x++) {1776 if (col10m[x][y] == player) {1777 tempX = x;1778 tempY = y;1779 inarow = 0;1780 do1781 {1782 tempXA[winsofar + inarow] = tempX;1783 tempYA[winsofar + inarow] = tempY;1784 inarow++;1785 tempY++;1786 }1787 while ((col10m[tempX][tempY] == player) && (tempY < maxY));1788 if (inarow > 4) {1789 winsofar = winsofar + inarow;1790 }1791 }1792 }1793 }1794 1795 //searching for left to right1796 for (x = 0; x < maxX - 4; x++) {1797 for (y = 0; y < maxY; y++) {1798 if (col10m[x][y] == player) {1799 tempX = x;1800 tempY = y;1801 inarow = 0;1802 do1803 {1804 tempXA[winsofar + inarow] = tempX;1805 tempYA[winsofar + inarow] = tempY;1806 inarow++;1807 tempX++;1808 }1809 while ((col10m[tempX][tempY] == player) && (tempX < maxX));1810 if (inarow > 4) {1811 winsofar = winsofar + inarow;1812 }1813 }1814 }1815 }1816 1817 //check for result1818 if (winsofar > 4) {1819 res = true;1820 gameover = true;1821 1822 if (players == 2) {1823 if (player == 1) {1824 // player 1 wins1825 this.showTurn.setValue("Player 1 won!");1826 } else {1827 // player 2 wins1828 this.showTurn.setValue("Player 2 won!");1829 }1830 } else {1831 if (player == 1) {1832 // player 1 wins1833 this.showTurn.setValue("Congratulations! You won!");1834 } else {1835 // reader wins1836 this.showTurn.setValue("Bad luck! I won!");1837 }1838 }1839 this.grid2Cursor.show(false);1840 this.grid1Cursor.show(false);1841 1842 1843 //change buttons for entries in the temp arrays of tuplets1844 for (n = 0; n < winsofar; n++) {1845 //get button id using XA and YA1846 if (tempXA[n] < 10) {1847 if (tempYA[n] < 10) {1848 id = "3Buttons0" + tempXA[n] + '0' + tempYA[n];1849 } else {1850 id = "3Buttons0" + tempXA[n] + '' + tempYA[n];1851 }1852 } else {1853 if (tempYA[n] < 10) {1854 id = "3Buttons" + tempXA[n] + '0' + tempYA[n];1855 } else {1856 id = "3Buttons" + tempXA[n] + '' + tempYA[n];1857 }1858 }1859 //set button.u=player+2 (buttons with colors inverted)1860 this[id].u = player + 2;1861 }1862 //this.setButtons();1863 }1864 return res;1865 }1866 1867 target.checkfordraw = function () {1868 var placesleft = 0;1869 var res = false;1870 var x, y;1871 for (x = 0; x < maxX; x++) {1872 for (y = 0; y < maxY; y++) {1873 if (col10m[x][y] == 0) {1874 placesleft++;1875 }1876 }1877 }1878 if (placesleft == 0) {1879 this.showTurn.setValue("It's a draw!");1880 gameover = true;1881 res = true;1882 }1883 return res;1884 }1885 1886 target.placeXO = function () {1887 var id;1888 var butt;1889 var res = false;1890 var drawres = false;1891 1892 if (Exiting) {1893 kbook.autoRunRoot.exitIf(kbook.model);1894 }1895 1896 if (gameover) {1897 return;1898 }1899 1900 if (posX < 10) {1901 if (posY < 10) {1902 id = "3Buttons0" + posX + '0' + posY;1903 } else {1904 id = "3Buttons0" + posX + '' + posY;1905 }1906 } else {1907 if (posY < 10) {1908 id = "3Buttons" + posX + '0' + posY;1909 } else {1910 id = "3Buttons" + posX + '' + posY;1911 }1912 }1913 1914 if (player1turn) {1915 // player 1 places "X"1916 if (col10m[posX][posY] != 0) {1917 return;1918 }1919 col10m[posX][posY] = 1;1920 this[id].u = 1;1921 1922 // store X's moves to help determine O's moves1923 xMoves++;1924 xMovesX[xMoves] = posX;1925 xMovesY[xMoves] = posY;1926 1927 // check for win1928 res = this.checkWin(1);1929 1930 if (!res) {1931 // if not win1932 // check for draw (no free spaces)1933 drawres = this.checkfordraw();1934 if (!drawres) {1935 if (players == 1) {1936 // reader's turn1937 this.showTurn.setValue("My turn...");1938 if (!isTouch) {1939 this.grid1Cursor.show(false);1940 }1941 FskUI.Window.update.call(kbook.model.container.getWindow());1942 id = target.placeO();1943 this[id].u = 2;1944 1945 // check for win1946 res = this.checkWin(2);1947 1948 if (!res) {1949 // if not win1950 // check for draw (no free spaces)1951 drawres = this.checkfordraw();1952 if (!drawres) {1953 this.showTurn.setValue("Your turn...");1954 if (!isTouch) {1955 this.grid1Cursor.show(true);1956 }1957 }1958 }1959 } else {1960 // player 2's turn1961 player1turn = false;1962 this.showTurn.setValue("Player 2's turn...");1963 this.drawgrid2Cursor(posX, posY);1964 if (!isTouch) {1965 this.grid2Cursor.show(true);1966 this.grid1Cursor.show(false);1967 }1968 }1969 }1970 }1971 } else {1972 // player 2 places "O"1973 if (col10m[posX][posY] != 0) {1974 return;1975 }1976 col10m[posX][posY] = 2;1977 this[id].u = 2;1978 //this.setButtons();1979 1980 // check for win1981 res = this.checkWin(2);1982 1983 if (!res) {1984 // if not win1985 // check for draw (no free spaces)1986 drawres = this.checkfordraw();1987 if (!drawres) {1988 player1turn = true;1989 this.showTurn.setValue("Player 1's turn...");1990 this.drawgrid1Cursor(posX, posY);1991 if (!isTouch) {1992 this.grid1Cursor.show(true);1993 this.grid2Cursor.show(false);1994 }1995 }1996 } else {1997 // player 2 won!1998 this.showTurn.setValue("Player 2 won!");1999 this.showTurn.show(true);2000 this.grid2Cursor.show(false);2001 this.grid1Cursor.show(false);2002 return;2003 }2004 }2005 }2006 2007 target.doGridClick = function (sender) {2008 var id, y, x, u;2009 id = getSoValue(sender, "id");2010 x = id.substring(8, 10);2011 y = id.substring(10, 12);2012 u = getSoValue(sender,"u");2013 if (u == 0) {2014 posX = parseInt(x, 10);2015 posY = parseInt(y, 10);2016 if (players == 2) {2017 if (player1turn) {2018 this.drawgrid1Cursor(posX, posY);2019 } else {2020 this.drawgrid2Cursor(posX, posY);2021 }2022 } else {2023 this.drawgrid1Cursor(posX, posY);2024 }2025 this.placeXO();2026 } 2027 }2028 2029 target.doButtonClick = function (sender) {2030 var id;2031 id = getSoValue(sender, "id");2032 n = id.substring(7, 10);2033/* if (n == "EXT") {2034 kbook.autoRunRoot.exitIf(kbook.model);2035 return;2036 } */2037 if (n == "ONE") {2038 this.GameOnePlayer();2039 return;2040 }2041 if (n == "TWO") {2042 this.GameTwoPlayers();2043 return;2044 } 2045 }2046 2047 target.moveCursor = function (dir) {2048 switch (dir) {2049 case "down":2050 {2051 posY = (posY + 1) % maxY;2052 break;2053 }2054 case "up":2055 {2056 posY = (maxY + posY - 1) % maxY;2057 break;2058 }2059 case "left":2060 {2061 posX = (maxX + posX - 1) % maxX;2062 break;2063 }2064 case "right":2065 {2066 posX = (posX + 1) % maxX;2067 break;2068 }2069 }2070 if (players == 2) {2071 if (player1turn) {2072 this.drawgrid1Cursor(posX, posY);2073 } else {2074 this.drawgrid2Cursor(posX, posY);2075 }2076 } else {2077 this.drawgrid1Cursor(posX, posY);2078 }2079 }2080 2081 target.doRoot = function (sender) {2082 kbook.autoRunRoot.exitIf(kbook.model);2083 return;2084 }2085 2086 target.GameOnePlayer = function () {2087 players = 1;2088 this.resetButtons();2089 posX = 5;2090 posY = 6;2091 gameover = false;2092 firstmove = true;2093 oMoves = 0;2094 xMoves = 0;2095 this.drawgrid1Cursor(posX, posY);2096 this.drawgrid2Cursor(posX, posY);2097 this.showTurn.setValue("Your turn...");2098 player1turn = true;2099 if (!isTouch) {2100 this.grid1Cursor.show(true);2101 this.grid2Cursor.show(false);2102 }2103 }2104 2105 target.GameTwoPlayers = function () {2106 players = 2;2107 this.resetButtons();2108 posX = 5;2109 posY = 6;2110 gameover = false;2111 firstmove = true;2112 oMoves = 0;2113 xMoves = 0;2114 this.drawgrid1Cursor(posX, posY);2115 this.drawgrid2Cursor(posX, posY);2116 this.showTurn.setValue("Player 1's turn...");2117 player1turn = true;2118 if (!isTouch) {2119 this.grid1Cursor.show(true);2120 this.grid2Cursor.show(false);2121 }2122 }2123 2124 target.newGame = function (digit) {2125 switch (digit*1) { /* typecast to number */2126 case 1:2127 {2128 players = 1;2129 this.resetButtons();2130 posX = 5;2131 posY = 6;2132 gameover = false;2133 firstmove = true;2134 oMoves = 0;2135 xMoves = 0;2136 this.drawgrid1Cursor(posX, posY);2137 this.drawgrid2Cursor(posX, posY);2138 this.showTurn.setValue("Your turn...");2139 player1turn = true;2140 if (!isTouch) {2141 this.grid1Cursor.show(true);2142 this.grid2Cursor.show(false);2143 }2144 return;2145 }2146 case 2:2147 {2148 players = 2;2149 this.resetButtons();2150 posX = 5;2151 posY = 6;2152 gameover = false;2153 firstmove = true;2154 oMoves = 0;2155 xMoves = 0;2156 this.drawgrid1Cursor(posX, posY);2157 this.drawgrid2Cursor(posX, posY);2158 this.showTurn.setValue("Player 1's turn...");2159 player1turn = true;2160 if (!isTouch) {2161 this.grid1Cursor.show(true);2162 this.grid2Cursor.show(false);2163 }2164 return;2165 }2166 case 0:2167 {2168 kbook.autoRunRoot.exitIf(kbook.model);2169 return;2170 }2171 }2172 }2173 2174 target.doCenterF = function () {2175 return;2176 }2177};2178tmp(); ...

Full Screen

Full Screen

boardTest.js

Source:boardTest.js Github

copy

Full Screen

...47 deepEqual(boardData, startingBoard(), "pieces are set up on board");48 deepEqual(sideData, SIDE.white, "side started on white");49});50test("makeMove - ok", function () {51 ok(boardModel.makeMove({ x: 0, y: 6 }, { x: 0, y: 5}));52 deepEqual(boardData[6][0], null, "old square is empty");53 deepEqual(54 boardData[5][0],55 { side: SIDE.white, type: PIECE.pawn },56 "new square contains the moved piece"57 );58 //check that rest of pieces match original board59 boardData[6][0] = boardData[5][0];60 boardData[5][0] = null;61 deepEqual(boardData, startingBoard(), "rest of pieces in correct places");62});63test("undo/redo", function () {64 boardModel.makeMove({ x: 0, y: 6 }, { x: 0, y: 5});65 boardModel.undo();66 deepEqual(boardData, startingBoard(), "undo to original setup");67 deepEqual(sideData, SIDE.white, "undo side restored");68 boardModel.redo();69 deepEqual(70 boardData[5][0],71 { side: SIDE.white, type: PIECE.pawn },72 "redo to original move"73 );74 deepEqual(sideData, SIDE.black, "redo side restored");75});76test("undo/redo multiple", function () {77 boardModel.makeMove({ x: 0, y: 6 }, { x: 0, y: 5});78 boardModel.makeMove({ x: 0, y: 1 }, { x: 0, y: 2});79 boardModel.undo();80 deepEqual(boardData[2][0], null, "first undo ok");81 boardModel.undo();82 deepEqual(boardData, startingBoard(), "second undo ok");83 boardModel.redo();84 deepEqual(boardData[5][0], {type: PIECE.pawn, side: SIDE.white}, "first redo ok");85 boardModel.redo();86 deepEqual(boardData[2][0], {type: PIECE.pawn, side: SIDE.black}, "second redo ok");87});88test("makeMove - fail - wrong player", function () {89 ok(!boardModel.makeMove({ x: 0, y: 1}, { x: 0, y: 2 }));90 deepEqual(boardData, startingBoard(), "board unchanged");91});92test("makeMove - fail - null square", function () {93 ok(!boardModel.makeMove({ x: 0, y: 3}, { x: 0, y: 4 }));94 deepEqual(boardData, startingBoard(), "board unchanged");95});96test("makeMove - fail - break piece's move rules", function () {97 ok(!boardModel.makeMove({ x: 0, y: 6 }, { x: 0, y: 3 }));98 deepEqual(boardData, startingBoard(), "board unchanged");99});100var setupCheckTests = function (side) {101 var board = tLib.blankBoard();102 board[2][2] = createPieceModel.king({ side: SIDE.black });103 board[2][4] = createPieceModel.rook({ side: SIDE.black });104 board[2][5] = createPieceModel.rook({ side: SIDE.white });105 board[4][3] = createPieceModel.pawn({ side: SIDE.white });106 board[0][2] = createPieceModel.king({ side: SIDE.white });107 boardModel = createBoardModel({ board : board, side: side });108 boardModel.subscribe("board", function (data) {109 boardData = data;110 });111};112test("makeMove - ok - puts opponent into check", function () {113 setupCheckTests(SIDE.white);114 ok(boardModel.makeMove({ x: 5, y: 2 }, { x: 4, y: 2 }));115 deepEqual(116 boardData[2][4],117 { side: SIDE.white, type: PIECE.rook },118 "moves white rook"119 );120});121test("makeMove - fail - moves into check", function () {122 setupCheckTests(SIDE.black);123 ok(!boardModel.makeMove({ x: 4, y: 2 }, { x: 4, y: 1 }));124 deepEqual(boardData, startingBoard(), "board unchanged");125});126test("makeMove - fail - move king into check", function () {127 setupCheckTests(SIDE.black);128 ok(!boardModel.makeMove({ x: 2, y: 2 }, { x: 2, y: 3 }));129 deepEqual(boardData, startingBoard(), "board unchanged");130});131test("makeMove - fail - move king into check by other king", function () {132 setupCheckTests(SIDE.white);133 ok(!boardModel.makeMove({ x: 2, y: 0 }, { x: 2, y: 1 }));134 deepEqual(boardData, startingBoard(), "board unchanged");135});136var setupCastlingTests = function (extraSetup) {137 boardModel = undefined;138 boardData = undefined;139 sideData = undefined;140 var board = tLib.blankBoard();141 board[0][0] = createPieceModel.rook({ side: SIDE.black });142 board[0][7] = createPieceModel.rook({ side: SIDE.black });143 board[0][4] = createPieceModel.king({ side: SIDE.black });144 board[7][4] = createPieceModel.king({ side: SIDE.white });145 if (extraSetup) {146 extraSetup(board);147 }148 boardModel = createBoardModel({ board : board, side: SIDE.black });149 boardModel.subscribe("board", function (data) {150 boardData = data;151 });152 boardModel.subscribe("side", function (data) {153 sideData = data;154 });155};156test("makeMove - castle kingside", function () {157 setupCastlingTests();158 ok(boardModel.makeMove({ x: 4, y: 0 }, { x: 6, y: 0 }));159 deepEqual(boardData[0][6], {side:SIDE.black,type:PIECE.king}, "king moved");160 deepEqual(boardData[0][5], {side:SIDE.black,type:PIECE.rook}, "rook moved");161});162test("makeMove - castling changes sides", function () {163 setupCastlingTests();164 boardModel.makeMove({ x: 4, y: 0 }, { x: 6, y: 0 });165 deepEqual(sideData, SIDE.white, "sides changed after castle");166});167test("makeMove - castle queenside", function () {168 setupCastlingTests();169 ok(boardModel.makeMove({ x: 4, y: 0}, { x: 2, y: 0}));170 deepEqual(boardData[0][2], {side:SIDE.black,type:PIECE.king}, "king moved");171 deepEqual(boardData[0][3], {side:SIDE.black,type:PIECE.rook}, "rook moved");172});173test("makeMove - castling failed, not first king move", function () {174 setupCastlingTests();175 ok(boardModel.makeMove({ x: 4, y: 0 }, { x: 3, y: 0 }), "move king");176 ok(boardModel.makeMove({ x: 4, y: 7 }, { x: 3, y: 7 }), "move white piece");177 ok(boardModel.makeMove({ x: 3, y: 0 }, { x: 4, y: 0 }), "move king to start");178 ok(boardModel.makeMove({ x: 3, y: 7 }, { x: 4, y: 7 }), "move white piece");179 ok(!boardModel.makeMove({ x: 4, y: 0 }, { x: 2, y: 0 }), "failed castle");180});181test("makeMove - castling failed, rook has moved", function () {182 setupCastlingTests();183 ok(boardModel.makeMove({ x: 0, y: 0 }, { x: 1, y: 0 }), "move rook");184 ok(boardModel.makeMove({ x: 4, y: 7 }, { x: 3, y: 7 }), "move white piece");185 ok(boardModel.makeMove({ x: 1, y: 0}, { x: 0, y: 0 }), "move rook to start");186 ok(boardModel.makeMove({ x: 3, y: 7 }, { x: 4, y: 7 }), "move white piece");187 ok(!boardModel.makeMove({ x: 4, y: 0 }, { x: 2, y: 0 }), "failed castle");188});189test("makeMove - castling queenside failed, piece in the way", function () {190 setupCastlingTests(function (board) {191 board[0][1] = createPieceModel.bishop({ side: SIDE.black });192 });193 ok(!boardModel.makeMove({ x: 4, y: 0 }, { x: 2, y: 0 }), "failed castle");194});195test("makeMove - castling kingside failed, piece in the way", function () {196 setupCastlingTests(function (board) {197 board[0][5] = createPieceModel.bishop({ side: SIDE.black });198 });199 ok(!boardModel.makeMove({ x: 4, y: 0 }, { x: 6, y: 0 }), "failed castle");200});201test("makeMove - castling failed, castle into check", function () {202 setupCastlingTests(function (board) {203 board[2][4] = createPieceModel.bishop({ side: SIDE.white });204 });205 ok(!boardModel.makeMove({ x: 4, y: 0 }, { x: 2, y: 0 }), "failed castle");206});207test("makeMove - castling failed, castle through check", function () {208 setupCastlingTests(function (board) {209 board[5][3] = createPieceModel.rook({ side: SIDE.white });210 });211 ok(!boardModel.makeMove({ x: 4, y: 0 }, { x: 2, y: 0 }), "failed castle");212});213var setupEnPassantTests = function (extraSetup) {214 boardModel = undefined;215 boardData = undefined;216 sideData = undefined;217 var board = tLib.blankBoard();218 board[1][1] = createPieceModel.pawn({ side: SIDE.black });219 board[2][4] = createPieceModel.pawn({ side: SIDE.black });220 board[3][2] = createPieceModel.pawn({ side: SIDE.white });221 board[3][3] = createPieceModel.pawn({ side: SIDE.white });222 board[4][5] = createPieceModel.pawn({ side: SIDE.black });223 board[6][4] = createPieceModel.pawn({ side: SIDE.white });224 if (extraSetup) {225 extraSetup(board);226 }227 boardModel = createBoardModel({ board : board, side: SIDE.black });228 boardModel.subscribe("board", function (data) {229 boardData = data;230 });231 boardModel.subscribe("side", function (data) {232 sideData = data;233 });234};235test("makeMove - en passant - white", function () {236 setupEnPassantTests();237 ok(boardModel.makeMove({ x: 1, y: 1 }, { x: 1, y: 3 }), "setup move");238 ok(boardModel.makeMove({ x: 2, y: 3 }, { x: 1, y: 2 }), "en passant move");239 deepEqual(boardData[3][1], null, "piece is captured");240});241test("makeMove - en passant - changes sides", function () {242 setupEnPassantTests();243 ok(boardModel.makeMove({ x: 1, y: 1 }, { x: 1, y: 3 }), "setup move");244 ok(boardModel.makeMove({ x: 2, y: 3 }, { x: 1, y: 2 }), "en passant move");245 deepEqual(sideData, SIDE.black, "sides changed after en passant move.");246 //deepEqual(boardData[3][1], null, "piece is captured");247});248test("makeMove - en passant - black", function () {249 setupEnPassantTests();250 ok(boardModel.makeMove({ x: 1, y: 1 }, { x: 1, y: 2 }), "change sides to white");251 ok(boardModel.makeMove({ x: 4, y: 6 }, { x: 4, y: 4 }), "setup move");252 ok(boardModel.makeMove({ x: 5, y: 4 }, { x: 4, y: 5 }), "en passant move");253 deepEqual(boardData[4][4], null, "piece is captured");254});255test("makeMove - en passant - failed - only advanced one", function () {256 setupEnPassantTests();257 ok(boardModel.makeMove({ x: 4, y: 2 }, { x: 4, y: 3}), "setup, only move one square");258 ok(!boardModel.makeMove({ x: 3, y: 3 }, { x: 4, y: 2 }), "failed en passant attempt");259});260test("makeMove - en passant - failed - missed opportunity", function () {261 setupEnPassantTests();262 ok(boardModel.makeMove({ x: 1, y: 1 }, { x: 1, y: 3 }), "setup");263 ok(boardModel.makeMove({ x: 3, y: 3 }, { x: 3, y: 2 }), "miss en passant opportunity");264 ok(boardModel.makeMove({ x: 4, y: 2 }, { x: 4, y: 3 }), "switch sides");265 ok(!boardModel.makeMove({ x: 2, y: 3 }, { x: 1, y: 2 }), "failed en passant attempt");266});267var pawnPromotionData;268var setupPawnPromotionTests = function (extraSetup) {269 boardModel = undefined;270 boardData = undefined;271 var board = tLib.blankBoard();272 board[1][0] = createPieceModel.pawn({ side: SIDE.white });273 if(extraSetup) {274 extraSetup(board);275 }276 boardModel = createBoardModel({ board : board, side: SIDE.white });277 boardModel.subscribe("board", function (data) {278 boardData = data;279 });280 boardModel.subscribe("side", function (side) {281 sideData = side;282 });283 boardModel.subscribe("pawnPromotion", function (data) {284 pawnPromotionData = data;285 });286};287test("promote pawn", function () {288 setupPawnPromotionTests();289 ok(boardModel.makeMove({ x: 0, y: 1 }, { x: 0, y: 0 }));290 deepEqual(sideData, SIDE.white, "side still white (requires promotion choice)");291 deepEqual(pawnPromotionData, SIDE.white, "published pawn promotion event");292 boardModel.promotePawn(PIECE.bishop);293 deepEqual(boardData[0][0], { type: PIECE.bishop, side: SIDE.white }, "board changed");294 deepEqual(sideData, SIDE.black, "changed sides after pawn promotion");295});296test("promote pawn - attack into position", function () {297 setupPawnPromotionTests(function (board) {298 board[0][1] = createPieceModel.pawn({ side: SIDE.black });299 });300 ok(boardModel.makeMove({ x: 0, y: 1 }, { x: 1, y: 0 }));301 deepEqual(sideData, SIDE.white, "side still white (requires promotion choice)");302 deepEqual(pawnPromotionData, SIDE.white, "published pawn promotion event");303});304var checkmateData;305var setupCheckmateTests = function (extraSetup) {306 boardModel = undefined;307 boardData = undefined;308 checkmateData = undefined;309 var board = tLib.blankBoard();310 board[0][1] = createPieceModel.rook({ side: SIDE.black });311 board[3][2] = createPieceModel.king({ side: SIDE.black });312 board[3][0] = createPieceModel.king({ side: SIDE.white });313 if(extraSetup) {314 extraSetup(board);315 }316 boardModel = createBoardModel({ board : board, side: SIDE.black });317 boardModel.subscribe("winner", function (side) {318 checkmateData = side;319 });320};321test("checkmate", function () {322 setupCheckmateTests();323 ok(boardModel.makeMove({ x: 1, y: 0 }, { x: 0, y: 0 }));324 deepEqual(checkmateData, SIDE.black, "black published as the winner");325});...

Full Screen

Full Screen

Game.js

Source:Game.js Github

copy

Full Screen

...21 });22 });23 });2425 context("#makeMove()", function() {26 it("should fail if move is null", function() {27 expectException(function() {28 const game = new Game();29 game.init([new Player("player1")]);30 game.makeMove();31 });32 });33 });3435 });3637 describe("Expected outputs", function() {38 context("#makeMove()", function() {39 let game;40 beforeEach(function() {41 game = new Game();42 });43 context("One player", function() {44 let player;45 const strike = ['X'];46 beforeEach(function() {47 player = new Player('P1');48 game.init([player]);49 });50 context("All strikes", function() {51 it("should have a score of 300", function() {52 for (let i = 0; i < 9; i++) {53 game.makeMove(strike);54 }55 game.makeMove(['X','X','X']);56 assert.equal(player.getScore(), 300);57 });58 });5960 context("Starts with a strike", function() {61 it("should have a score of 168", function() {62 game.makeMove(['X']);63 game.makeMove(['7', '/']);64 game.makeMove(['7', '2']);65 game.makeMove(['9', '/']);66 game.makeMove(['X']);67 game.makeMove(['X']);68 game.makeMove(['X']);69 game.makeMove(['2', '3']);70 game.makeMove(['6', '/']);71 game.makeMove(['7', '/', '3']);72 assert.equal(player.getScore(), 168);73 });74 });7576 context("Starts with a spare", function() {77 it("should have a score of 170", function() {78 game.makeMove(['7', '/']);79 game.makeMove(['X']);80 game.makeMove(['7', '2']);81 game.makeMove(['9', '/']);82 game.makeMove(['X']);83 game.makeMove(['X']);84 game.makeMove(['X']);85 game.makeMove(['2', '3']);86 game.makeMove(['6', '/']);87 game.makeMove(['7', '/', '3']);88 assert.equal(player.getScore(), 170);89 });90 });9192 context("Starts with an open frame", function() {93 it("should have a score of 171", function() {94 game.makeMove(['7', '2']);95 game.makeMove(['7', '/']);96 game.makeMove(['X']);97 game.makeMove(['9', '/']);98 game.makeMove(['X']);99 game.makeMove(['X']);100 game.makeMove(['X']);101 game.makeMove(['2', '3']);102 game.makeMove(['6', '/']);103 game.makeMove(['7', '/', '3']);104 assert.equal(player.getScore(), 171);105 });106 });107 });108 109 context("Two players", function() {110 let players;111 beforeEach(function() {112 players = [new Player('P1'), new Player('P2')];113 game.init(players);114 });115 it("Players 2 gets higher scores", function() {116 for (let i = 0; i < 10; i++) {117 game.makeMove([1,2]);118 game.makeMove([4,2]);119 }120 const board = game.getScoreBoard();121 it("should return P2 as the winner (higher on chart)", function() {122 assert.equal(board[0].player, 'P2');123 });124 it("should have a score of 63", function() {125 assert.equal(board[0].score, 63);126 });127 });128 });129 });130131 context("#isDone", function() {132 context('One player', function() {133 let game;134 let frame = [1,1];135 beforeEach(function() {136 game = new Game();137 players = [new Player('P1')];138 game.init(players);139 });140141 it("should return false if played less than 10 moves", function() {142 for (let i = 0; i < 9; i++) {143 game.makeMove(frame);144 }145 assert.equal(game.isDone(), false);146 });147148 it("should return true if played 10 moves", function() {149 for (let i = 0; i < 10; i++) {150 game.makeMove(frame);151 }152 assert.equal(game.isDone(), true);153 });154155 });156157 context('Two players', function() {158 let game;159 let frame = [1,1];160 beforeEach(function() {161 game = new Game();162 players = [new Player('P1'), new Player('P2')];163 game.init(players);164 });165166 it("should return false if both played less than 10 moves", function() {167 for (let i = 0; i < 18; i++) {168 game.makeMove(frame);169 }170 assert.equal(game.isDone(), false);171 });172173 it("should return false if only one played 10 moves", function() {174 for (let i = 0; i < 19; i++) {175 game.makeMove(frame);176 }177 assert.equal(game.isDone(), false);178 });179180 it("should return true if both played 10 moves", function() {181 for (let i = 0; i < 20; i++) {182 game.makeMove(frame);183 }184 assert.equal(game.isDone(), true);185 });186 });187 });188189 context("#switchPlayer", function() {190 191 const playerDone = {192 name: 'PlayerDone',193 isDone() {194 return true;195 }196 }; ...

Full Screen

Full Screen

Board.js

Source:Board.js Github

copy

Full Screen

...67 renderBoard() {8 this.boardHTML = `<table class="ChessBoard" id="chesstable">9 <tr>10 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="11"></div></td>11 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="12"></div></td>12 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="13"></div></td>13 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="14"></div></td>14 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="15"></div></td>15 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="16"></div></td>16 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="17"></div></td>17 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="18"></div></td>18 </tr>19 <tr>20 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="21" ></div></td>21 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="22"></div></td>22 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="23"></div></td>23 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="24"></div></td>24 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="25"></div></td>25 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="26"></div></td>26 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="27"></div></td>27 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="28"></div></td>28 </tr>29 <tr>30 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="31"></div></td>31 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="32"></div></td>32 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="33"></div></td>33 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="34"></div></td>34 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="35"></div></td>35 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="36"></div></td>36 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="37"></div></td>37 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="38"></div></td>38 </tr>39 <tr>40 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="41"></div></td>41 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="42"></div></td>42 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="43"></div></td>43 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="44"></div></td>44 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="45"></div></td>45 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="46"></div></td>46 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="47"></div></td>47 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="48"></div></td>48 </tr>49 <tr>50 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="51"></div></td>51 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="52"></div></td>52 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="53"></div></td>53 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="54"></div></td>54 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="55"></div></td>55 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="56"></div></td>56 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="57"></div></td>57 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="58"></div></td>58 </tr>59 <tr>60 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="61"></div></td>61 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="62"></div></td>62 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="63"></div></td>63 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="64"></div></td>64 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="65"></div></td>65 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="66"></div></td>66 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="67"></div></td>67 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="68"></div></td>68 </tr>69 <tr>70 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="71"></div></td>71 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="72"></div></td>72 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="73"></div></td>73 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="74"></div></td>74 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="75"></div></td>75 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="76"></div></td>76 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="77"></div></td>77 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="78"></div></td>78 </tr>79 <tr>80 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="81"></div></td>81 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="82"></div></td>82 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="83"></div></td>83 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="84"></div></td>84 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="85"></div></td>85 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="86"></div></td>86 <td><div class="BlackDimension BlackBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="87"></div></td>87 <td><div class="BoardBlock" onclick="makeMove(this)"><img onclick="select(this.id)" id="88"></div></td>88 </tr>8990 </table>`;9192 document.getElementsByClassName("Board_div")[0].innerHTML = this.boardHTML;93 for (let i = 0; i < this.pieces.length; i++) {94 let piece = this.pieces[i];95 document.getElementById(piece.getPosition()).src = piece.getSource();96 }97 }9899 update(board){100 this.boardHTML = board;101 document.getElementsByClassName("Board_div")[0].innerHTML = this.boardHTML; ...

Full Screen

Full Screen

Chess.test.js

Source:Chess.test.js Github

copy

Full Screen

...24 }25});26test("PawnMove", () => {27 chess.initializeBoard();28 expect(chess.makeMove(1, 2, 2, 3)).toEqual(false);29 expect(chess.makeMove(1, 2, 2, 2)).toEqual(true);30 expect(chess.makeMove(6, 3, 4, 3)).toEqual(true);31 expect(chess.makeMove(2, 2, 3, 2)).toEqual(true);32 expect(chess.makeMove(4, 3, 3, 2)).toEqual(true);33 expect(chess.board[3][2].color).toEqual(1);34 expect(chess.points[1]).toEqual(1);35 expect(chess.makeMove(1, 6, 3, 6)).toEqual(true);36 expect(chess.makeMove(6, 6, 5, 6)).toEqual(true);37 expect(chess.makeMove(3, 6, 4, 6)).toEqual(true);38 expect(chess.makeMove(6, 7, 4, 7)).toEqual(true);39 expect(chess.makeMove(4, 6, 5, 7)).toEqual(true);40 expect(chess.points[0]).toEqual(1);41});42test("RookMove", () => {43 chess.initializeBoard();44 expect(chess.makeMove(0, 0, 2, 0)).toEqual(false);45 expect(chess.makeMove(1, 0, 3, 0)).toEqual(true);46 expect(chess.makeMove(7, 0, 5, 0)).toEqual(false);47 expect(chess.makeMove(6, 0, 4, 0)).toEqual(true);48 expect(chess.makeMove(0, 0, 2, 0)).toEqual(true);49 expect(chess.makeMove(7, 0, 5, 0)).toEqual(true);50 expect(chess.makeMove(2, 0, 2, 5)).toEqual(true);51 expect(chess.makeMove(5, 0, 5, 5)).toEqual(true);52 expect(chess.makeMove(2, 5, 5, 5)).toEqual(true);53 expect(chess.points[0]).toEqual(5);54});55test("KnightMove", () => {56 chess.initializeBoard();57 expect(chess.makeMove(0, 1, 0, 3)).toEqual(false);58 expect(chess.makeMove(0, 1, 2, 2)).toEqual(true);59 expect(chess.makeMove(7, 1, 5, 0)).toEqual(true);60 expect(chess.makeMove(2, 2, 4, 3)).toEqual(true);61 expect(chess.makeMove(5, 0, 3, 1)).toEqual(true);62 expect(chess.makeMove(4, 3, 3, 1)).toEqual(true);63 expect(chess.points[0]).toEqual(3);64});65test("BishopMove", () => {66 chess.initializeBoard();67 expect(chess.makeMove(0, 2, 2, 4)).toEqual(false);68 expect(chess.makeMove(1, 3, 2, 3)).toEqual(true);69 expect(chess.makeMove(6, 4, 5, 4)).toEqual(true);70 expect(chess.makeMove(0, 2, 2, 4)).toEqual(true);71 expect(chess.makeMove(7, 5, 4, 2)).toEqual(true);72 expect(chess.makeMove(2, 4, 4, 2)).toEqual(true);73 expect(chess.points[0]).toEqual(3);74});75test("QueenMove", () => {76 chess.initializeBoard();77 expect(chess.makeMove(0, 3, 4, 3)).toEqual(false);78 expect(chess.makeMove(1, 4, 3, 4)).toEqual(true);79 expect(chess.makeMove(6, 3, 4, 3)).toEqual(true);80 expect(chess.makeMove(0, 3, 4, 7)).toEqual(true);81 expect(chess.makeMove(7, 3, 2, 3)).toEqual(false);82 expect(chess.makeMove(7, 3, 5, 3)).toEqual(true);83 expect(chess.makeMove(4, 7, 5, 7)).toEqual(true);84 expect(chess.makeMove(5, 3, 5, 7)).toEqual(true);85 expect(chess.points[1]).toEqual(9);86});87test("KingMove", () => {88 chess.initializeBoard();89 expect(chess.makeMove(0, 4, 1, 4)).toEqual(false);90 expect(chess.makeMove(1, 4, 3, 4)).toEqual(true);91 expect(chess.makeMove(6, 4, 4, 4)).toEqual(true);92 expect(chess.makeMove(0, 4, 1, 4)).toEqual(true);93 expect(chess.makeMove(7, 4, 6, 4)).toEqual(true);94 expect(chess.makeMove(1, 4, 2, 5)).toEqual(true);95 expect(chess.makeMove(6, 4, 5, 5)).toEqual(true);96 expect(chess.makeMove(2, 5, 3, 5)).toEqual(false);97});98test("Check",() => {99 chess.initializeBoard();100 expect(chess.makeMove(1, 5, 2, 5)).toEqual(true);101 expect(chess.makeMove(6, 4, 5, 4)).toEqual(true);102 expect(chess.makeMove(1, 6, 2, 6)).toEqual(true);103 expect(chess.makeMove(7, 3, 3, 7)).toEqual(true);104 expect(chess.makeMove(2, 6, 3, 6)).toEqual(false);105 expect(chess.makeMove(1, 0, 2, 0)).toEqual(true);106 expect(chess.makeMove(3, 7, 2, 6)).toEqual(true);107 expect(chess.isKingChecked(0)).toEqual(true);108 expect(chess.isCheckmated(0)).toEqual(false);109});110test("CheckMate",() => {111 chess.initializeBoard();112 expect(chess.makeMove(1, 5, 2, 5)).toEqual(true);113 expect(chess.makeMove(6, 4, 5, 4)).toEqual(true);114 expect(chess.makeMove(1, 6, 3, 6)).toEqual(true);115 expect(chess.makeMove(7, 3, 3, 7)).toEqual(true);116 expect(chess.isCheckmated(0)).toEqual(true);117});118test("Stalemate",() => {119 chess.initializeBoard();120 for (let i = 0; i < chess.board.length; i++){121 for (let j = 0; j < chess.board[i].length; j++){122 chess.board[i][j] = null;123 }124 }125 chess.board[0][3] = new Piece(1, 1);126 chess.board[0][5] = new Piece(1, 1);127 chess.board[3][0] = new Piece(1, 1);128 chess.board[5][0] = new Piece(1, 1);129 chess.board[4][4] = new Piece(0, 5);130 expect(chess.isStalemated(0)).toEqual(true);131 expect(chess.isCheckmated(0)).toEqual(false);132});133test("Stalemate",() => {134 chess.initializeBoard();135 for (let i = 0; i < chess.board.length; i++){136 for (let j = 0; j < chess.board[i].length; j++){137 if (!chess.board[i][j]){138 continue;139 }140 if (chess.board[i][j].type != 1 && chess.board[i][j].type != 5){141 chess.board[i][j] = null;142 }143 }144 }145 expect(chess.canCastle(0, 0)).toEqual(true);146 expect(chess.canCastle(0, 1)).toEqual(true);147 expect(chess.canCastle(1, 0)).toEqual(true);148 expect(chess.canCastle(1, 1)).toEqual(true);149 expect(chess.makeMove(0, 0, 0, 3)).toEqual(true);150 expect(chess.canCastle(0, 0)).toEqual(false);151 expect(chess.canCastle(1, 0)).toEqual(false);152 expect(chess.makeMove(7, 4, 7, 0)).toEqual(false);153 expect(chess.makeMove(7, 4, 7, 7)).toEqual(true);...

Full Screen

Full Screen

Queen.spec.js

Source:Queen.spec.js Github

copy

Full Screen

...11 board.select(4, 3).occupyBy(queen);12 var possibleMoves = queen.generateAllPossibleMoves();13 expect(possibleMoves.length).to.be.equal(27);14 var expectedMoves = [15 tu.makeMove(1, 0),16 tu.makeMove(2, 1),17 tu.makeMove(3, 2),18 tu.makeMove(5, 4),19 tu.makeMove(6, 5),20 tu.makeMove(7, 6),21 tu.makeMove(7, 0),22 tu.makeMove(6, 1),23 tu.makeMove(5, 2),24 tu.makeMove(3, 4),25 tu.makeMove(2, 5),26 tu.makeMove(1, 6),27 tu.makeMove(0, 7),28 tu.makeMove(4, 0),29 tu.makeMove(4, 1),30 tu.makeMove(4, 2),31 tu.makeMove(4, 4),32 tu.makeMove(4, 5),33 tu.makeMove(4, 6),34 tu.makeMove(4, 7),35 tu.makeMove(0, 3),36 tu.makeMove(1, 3),37 tu.makeMove(2, 3),38 tu.makeMove(3, 3),39 tu.makeMove(5, 3),40 tu.makeMove(6, 3),41 tu.makeMove(7, 3)42 ];43 expect(tu.checkMoves(possibleMoves, expectedMoves)).to.be.true;44 });45 it('should not be able to beat friendly chess piece', function() {46 var board = new ChessBoardRepresentation();47 var queen = new ChessPiecesFactory.Queen(ChessSet.white);48 var pawn = new ChessPiecesFactory.Pawn(ChessSet.white);49 board.select(4, 3).occupyBy(queen);50 board.select(6, 3).occupyBy(pawn);51 var possibleMoves = queen.generateAllPossibleMoves();52 expect(possibleMoves.length).to.be.equal(25);53 var expectedMoves = [54 tu.makeMove(1, 0),55 tu.makeMove(2, 1),56 tu.makeMove(3, 2),57 tu.makeMove(5, 4),58 tu.makeMove(6, 5),59 tu.makeMove(7, 6),60 tu.makeMove(7, 0),61 tu.makeMove(6, 1),62 tu.makeMove(5, 2),63 tu.makeMove(3, 4),64 tu.makeMove(2, 5),65 tu.makeMove(1, 6),66 tu.makeMove(0, 7),67 tu.makeMove(4, 0),68 tu.makeMove(4, 1),69 tu.makeMove(4, 2),70 tu.makeMove(4, 4),71 tu.makeMove(4, 5),72 tu.makeMove(4, 6),73 tu.makeMove(4, 7),74 tu.makeMove(0, 3),75 tu.makeMove(1, 3),76 tu.makeMove(2, 3),77 tu.makeMove(3, 3),78 tu.makeMove(5, 3)79 ];80 expect(tu.checkMoves(possibleMoves, expectedMoves)).to.be.true;81 });82 it('should be able to enemy chess piece', function() {83 var board = new ChessBoardRepresentation();84 var queen = new ChessPiecesFactory.Queen(ChessSet.white);85 var pawn = new ChessPiecesFactory.Pawn(ChessSet.black);86 board.select(4, 3).occupyBy(queen);87 board.select(6, 3).occupyBy(pawn);88 var possibleMoves = queen.generateAllPossibleMoves();89 expect(possibleMoves.length).to.be.equal(26);90 var expectedMoves = [91 tu.makeMove(1, 0),92 tu.makeMove(2, 1),93 tu.makeMove(3, 2),94 tu.makeMove(5, 4),95 tu.makeMove(6, 5),96 tu.makeMove(7, 6),97 tu.makeMove(7, 0),98 tu.makeMove(6, 1),99 tu.makeMove(5, 2),100 tu.makeMove(3, 4),101 tu.makeMove(2, 5),102 tu.makeMove(1, 6),103 tu.makeMove(0, 7),104 tu.makeMove(4, 0),105 tu.makeMove(4, 1),106 tu.makeMove(4, 2),107 tu.makeMove(4, 4),108 tu.makeMove(4, 5),109 tu.makeMove(4, 6),110 tu.makeMove(4, 7),111 tu.makeMove(0, 3),112 tu.makeMove(1, 3),113 tu.makeMove(2, 3),114 tu.makeMove(3, 3),115 tu.makeMove(5, 3),116 tu.makeMove(6, 3)117 ];118 expect(tu.checkMoves(possibleMoves, expectedMoves)).to.be.true;119 });120 it('should not be able to move out of board', function() {121 var board = new ChessBoardRepresentation();122 var queen = new ChessPiecesFactory.Queen(ChessSet.white);123 board.select(0, 0).occupyBy(queen);124 var possibleMoves = queen.generateAllPossibleMoves();125 expect(possibleMoves.length).to.be.equal(21);126 var expectedMoves = [127 tu.makeMove(1, 1),128 tu.makeMove(2, 2),129 tu.makeMove(3, 3),130 tu.makeMove(4, 4),131 tu.makeMove(5, 5),132 tu.makeMove(6, 6),133 tu.makeMove(7, 7),134 tu.makeMove(0, 1),135 tu.makeMove(0, 2),136 tu.makeMove(0, 3),137 tu.makeMove(0, 4),138 tu.makeMove(0, 5),139 tu.makeMove(0, 6),140 tu.makeMove(0, 7),141 tu.makeMove(1, 0),142 tu.makeMove(2, 0),143 tu.makeMove(3, 0),144 tu.makeMove(4, 0),145 tu.makeMove(5, 0),146 tu.makeMove(6, 0),147 tu.makeMove(7, 0)148 ];149 expect(tu.checkMoves(possibleMoves, expectedMoves)).to.be.true;150 });...

Full Screen

Full Screen

layout.js

Source:layout.js Github

copy

Full Screen

...26}27const resetBoard = () => {28 handleReset();29 container.innerHTML = `<div class="board">30 <div class="square" id="1" onclick="makeMove(this)">31 <!-- <div class="player">X</div> -->32 </div>33 <div class="square" id="2" onclick="makeMove(this)">34 <!-- <div class="player">O</div> -->35 </div>36 <div class="square" id="3" onclick="makeMove(this)"></div>37 <div class="square" id="4" onclick="makeMove(this)"></div>38 <div class="square" id="5" onclick="makeMove(this)"></div>39 <div class="square" id="6" onclick="makeMove(this)"></div>40 <div class="square" id="7" onclick="makeMove(this)"></div>41 <div class="square" id="8" onclick="makeMove(this)"></div>42 <div class="square" id="9" onclick="makeMove(this)"></div>43 </div>`;...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

2// import GameView from "./GameView.js";3// let game = new Game();4// let gameView = new GameView(document.getElementById("app"));5// console.log(game.turn);6// game.makeMove(0);7// console.log(game.board.join(","));8// console.log(game.turn);9// game.makeMove(6);10// console.log(game.turn);11// game.makeMove(5);12// console.log(game.board.join(","));13// game.makeMove(1); //X14// game.makeMove(0); //015// game.makeMove(2); //x16// game.makeMove(3); //o17// game.makeMove(4); //X18// game.makeMove(5); //O19// console.log(game.isInProgress());20// game.makeMove(6); //X21// console.log(game.isInProgress());22// game.makeMove(7); //023// console.log(game.isInProgress());24// game.makeMove(8); //X25// console.log(game.board);26// console.log(game.findWinningCombination());27// console.log(game.isInProgress());28import Game from "./Game.js";29import GameView from "./GameView.js";30let game = new Game();31let gameView = new GameView(document.getElementById("app"));32// define functions33gameView.onTileClick = function (i) {34 game.makeMove(i);35 gameView.update(game);36};37gameView.onRestartClick = function () {38 game = new Game();39 gameView.update(game);40};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('text=I agree');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.mouse.move(100, 100);7 await page.mouse.down();8 await page.mouse.move(200, 200);9 await page.mouse.up();10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch({ headless: false });15 const context = await browser.newContext();16 const page = await context.newPage();17 await page.mouse.move(100, 100);18 await page.mouse.down();19 await page.mouse.move(200, 200);20 await page.mouse.up();21 await browser.close();22})();23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch({ headless: false });26 const context = await browser.newContext();27 const page = await context.newPage();28 await page.mouse.move(100, 100);29 await page.mouse.down();30 await page.mouse.move(200, 200);31 await page.mouse.up();32 await browser.close();33})();34const { chromium } = require('playwright');35(async () => {36 const browser = await chromium.launch({ headless: false });37 const context = await browser.newContext();38 const page = await context.newPage();39 await page.mouse.move(100, 100);40 await page.mouse.down();41 await page.mouse.move(200, 200);42 await page.mouse.up();43 await browser.close();44})();45const { chromium } = require('playwright');46(async () => {47 const browser = await chromium.launch({ headless: false });48 const context = await browser.newContext();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.mouse.move(100, 100);6 await page.mouse.down();7 await page.mouse.move(200, 200);8 await page.mouse.up();9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.mouse.move(100, 100, { steps: 10 });7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { makeMove } = require('playwright/lib/server/playwright');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await makeMove(page, { x: 100, y: 100, steps: 100 });7 await browser.close();8})();9[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { makeMove } = require('playwright-core/lib/server/chromium/crPage');2const { chromium } = require('playwright-core');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await makeMove(page, 100, 100);8 await browser.close();9})();10const makeMove = async (page, x, y) => {11 const { targetId } = page._delegate;12 const { pageProxy } = page._delegate._browserContext;13 await pageProxy.send('Input.dispatchMouseEvent', {14 });15};16 async _onInput(input: Protocol.Input.inputDispatchedPayload) {17 if (input.type === 'mouseWheel') {18 const { x, y, deltaX, deltaY, modifiers, button, buttons, clickCount, pointerType } = input.data;19 const wheelTicksX = deltaX;20 const wheelTicksY = deltaY;21 const event: WheelEvent = {22 };23 this._page._onWheel(event);24 }25 }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { makeMove } = require('playwright-core/lib/server/playwright.js');2const { chromium } = require('playwright-core');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await makeMove(page, { x: 100, y: 100 });8 await browser.close();9})();10const { test, expect } = require('@playwright/test');11test('basic test', async ({ page }) => {12 const title = page.locator('title');13 await expect(title).toHaveText('Google');14});15const puppeteer = require('puppeteer');16(async () => {17 const browser = await puppeteer.launch();18 const page = await browser.newPage();19 await page.mouse.move(100, 100);20 await browser.close();21})();22const puppeteer = require('puppeteer-cluster');23(async () => {24 const cluster = await Cluster.launch({

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test, expect } = require('@playwright/test');2const { makeMove } = require('@playwright/test/lib/api/test');3test('Playwright Internal API Test', async ({ page }) => {4 await makeMove(page, 100, 100);5 await page.mouse.down();6 await makeMove(page, 200, 200);7 await page.mouse.up();8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { makeMove } = require('playwright/lib/server/childProcess');2makeMove('right');3makeMove('down');4makeMove('left');5makeMove('up');6const { makeMove } = require('playwright/lib/server/childProcess');7makeMove('right');8makeMove('down');9makeMove('left');10makeMove('up');11[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1function makeMove(x,y,stepsize) {2 var xstep = x/stepsize;3 var ystep = y/stepsize;4 var xdir = xstep/Math.abs(xstep);5 var ydir = ystep/Math.abs(ystep);6 var xcurr = 0;7 var ycurr = 0;8 for (var i=0; i<stepsize; i++) {9 xcurr += xdir;10 ycurr += ydir;11 PlaywrightInternal.makeMove(xcurr,ycurr);12 }13}14function makeMove(x,y,stepsize) {15 var xstep = x/stepsize;16 var ystep = y/stepsize;17 var xdir = xstep/Math.abs(xstep);18 var ydir = ystep/Math.abs(ystep);19 var xcurr = 0;20 var ycurr = 0;21 for (var i=0; i<stepsize; i++) {22 xcurr += xdir;23 ycurr += ydir;24 PlaywrightInternal.makeMove(xcurr,ycurr);25 }26}27function makeMove(x,y,stepsize) {28 var xstep = x/stepsize;29 var ystep = y/stepsize;30 var xdir = xstep/Math.abs(xstep);31 var ydir = ystep/Math.abs(ystep);32 var xcurr = 0;33 var ycurr = 0;34 for (var i=0; i<stepsize; i++) {35 xcurr += xdir;36 ycurr += ydir;37 PlaywrightInternal.makeMove(xcurr,ycurr);38 }39}40function makeMove(x,y,stepsize) {

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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