How to use shouldMark method in Playwright Internal

Best JavaScript code snippet using playwright-internal

game.js

Source:game.js Github

copy

Full Screen

1'use strict';2let gPickedPos = null;3let whitePiecesCount = 124let blackPiecesCount = 125let gPossibleMoves = []6let gIsRecursiveEating = false7let isCurrentlyEating = false8let gIsDownRight = false;9let gIsDownLeft = false;10let gIsUpRight = false;11let gIsUpLeft = false;12//rules to end game:13let gOnlyKingsMoveCounter = 014const playTurn = (destinationRow, destinationCol) => {15 console.log(gPickedPos.row + "|" + gPickedPos.col, "==>", destinationRow + "|" + destinationCol);16 if (gBoard[gPickedPos.row][gPickedPos.col].rank === "king") {//if king17 if (isEnemyPieceInRoute(destinationRow - gPickedPos.row, destinationCol - gPickedPos.col)) {18 kingEat(destinationRow, destinationCol, gPickedPos.row, gPickedPos.col)19 eatingSound.play()20 gOnlyKingsMoveCounter = 0;21 }22 else {23 gOnlyKingsMoveCounter++;24 updateScore()25 if (gOnlyKingsMoveCounter === 15) {26 endTurn()27 return28 }29 move(destinationRow, destinationCol, gPickedPos.row, gPickedPos.col)30 }31 }32 else {//if soldier33 if (Math.abs(gPickedPos.row - destinationRow) === 2 || Math.abs(gPickedPos.col - destinationCol) === 2) {34 eat(destinationRow, destinationCol, gPickedPos.row, gPickedPos.col)35 eatingSound.play()36 gOnlyKingsMoveCounter = 0;37 } else {38 move(destinationRow, destinationCol, gPickedPos.row, gPickedPos.col)39 gOnlyKingsMoveCounter = 0;40 }41 }42}43const isEnemyPieceInRoute = (rowDiff, colDiff) => {44 const row = gPickedPos.row45 const col = gPickedPos.col46 if (rowDiff > 0) {47 if (colDiff > 0) {48 //down right49 for (let i = 1; i < Math.abs(rowDiff); i++) {50 if (gBoard[row + i][col + i].isOccupied && gBoard[row + i][col + i].isMarked) return true51 }52 } else {53 //down left54 for (let i = 1; i < Math.abs(rowDiff); i++) {55 if (gBoard[row + i][col - i].isOccupied && gBoard[row + i][col - i].isMarked) return true56 }57 }58 } else {59 if (colDiff > 0) {60 //up right61 for (let i = 1; i < Math.abs(rowDiff); i++) {62 if (gBoard[row - i][col + i].isOccupied && gBoard[row - i][col + i].isMarked) return true63 }64 } else {65 //up left66 for (let i = 1; i < Math.abs(rowDiff); i++) {67 if (gBoard[row - i][col - i].isOccupied && gBoard[row - i][col - i].isMarked) return true68 }69 }70 }71 return false72}73const endTurn = () => {74 cancelPick()75 updateScore()76 countPiecesAndRank()77 if (isGameOver()) return78 gTurnCount++79 gPossibleMoves = []80 gPickedPos = null81 isWhitesTurn = !isWhitesTurn82 gIsRecursiveEating = false83 isCurrentlyEating = false84 markTurn()85 isLegalMoveLeft()86}87const move = (destinationRow, destinationCol, row, col) => {88 if (isCurrentlyEating) return89 isAbleToEat()90 gBoard[destinationRow][destinationCol] = gBoard[row][col]91 gBoard[destinationRow][destinationCol].location = { row: destinationRow, col: destinationCol }92 gBoard[row][col] = { location: { row, col }, isOccupied: false }93 movingSound.play()94 if (95 gBoard[destinationRow][destinationCol].rank === "soldier" && (96 (gBoard[destinationRow][destinationCol].isWhitePiece && gBoard[destinationRow][destinationCol].location.row === 7)97 ||98 (!gBoard[destinationRow][destinationCol].isWhitePiece && gBoard[destinationRow][destinationCol].location.row === 0)99 )100 ) {101 crownSoldier(gBoard[destinationRow][destinationCol])102 setTimeout(() => {103 promotionSound.play()104 }, 200)105 }106 renderBoard(gBoard)107 cancelPick()108 endTurn()109}110const eat = (destinationRow, destinationCol, row, col) => {111 //find out direction:112 const rowDiff = row - destinationRow//if diff < 0 we are going down113 const colDiff = col - destinationCol// if diff <0 we are going left114 gBoard[destinationRow][destinationCol] = gBoard[row][col]115 gBoard[destinationRow][destinationCol].location = { row: destinationRow, col: destinationCol }116 if (rowDiff < 0) {//turn the enemy piece to an empty cell117 if (colDiff < 0) {118 //down right119 gBoard[row + 1][col + 1].isWhitePiece ? whitePiecesCount-- : blackPiecesCount--;120 gBoard[row + 1][col + 1] = { location: { row: row + 1, col: col + 1 }, isOccupied: false, isEatingPath: false }121 } else {122 //down left123 gBoard[row + 1][col - 1].isWhitePiece ? whitePiecesCount-- : blackPiecesCount--;124 gBoard[row + 1][col - 1] = { location: { row: row + 1, col: col - 1 }, isOccupied: false, isEatingPath: false }125 }126 } else {127 if (colDiff < 0) {128 //up right129 gBoard[row - 1][col + 1].isWhitePiece ? whitePiecesCount-- : blackPiecesCount--;130 gBoard[row - 1][col + 1] = { location: { row: row - 1, col: col + 1 }, isOccupied: false, isEatingPath: false }131 } else {132 //up left133 gBoard[row - 1][col - 1].isWhitePiece ? whitePiecesCount-- : blackPiecesCount--;134 gBoard[row - 1][col - 1] = { location: { row: row - 1, col: col - 1 }, isOccupied: false, isEatingPath: false }135 }136 }137 gBoard[row][col] = { location: { row, col }, isOccupied: false }//turn the former location to an empty cell138 renderBoard(gBoard)139 // console.log("number of black pieces:", blackPiecesCount, "|", "number of white pieces:", whitePiecesCount);140 // console.log(destinationRow + 1);141 // console.log(destinationCol - 1);142 if (//checking if can continue eating by checking if theres a possible targeted enemy piece around143 (destinationRow + 1 < 8 && destinationCol + 1 < 8 && gBoard[destinationRow + 1][destinationCol + 1].isMarked && gBoard[destinationRow + 1][destinationCol + 1].isOccupied)144 ||145 (destinationRow + 1 < 8 && destinationCol - 1 >= 0 && gBoard[destinationRow + 1][destinationCol - 1].isMarked && gBoard[destinationRow + 1][destinationCol - 1].isOccupied)146 ||147 (destinationRow - 1 >= 0 && destinationCol + 1 < 8 && gBoard[destinationRow - 1][destinationCol + 1].isMarked && gBoard[destinationRow - 1][destinationCol + 1].isOccupied)148 ||149 (destinationRow - 1 >= 0 && destinationCol - 1 >= 0 && gBoard[destinationRow - 1][destinationCol - 1].isMarked && gBoard[destinationRow - 1][destinationCol - 1].isOccupied)150 ) {151 gBoard[destinationRow][destinationCol].isMarked = false152 // gBoard[destinationRow][destinationCol].isEatingPath = false153 // console.log("keep eating")154 gPickedPos = { row: destinationRow, col: destinationCol }155 gIsRecursiveEating = true156 unMarkAll()157 checkAndMarkPossibleMoves(destinationRow, destinationCol, gBoard[destinationRow][destinationCol].isWhitePiece, "soldier", true)158 isCurrentlyEating = true159 renderBoard(gBoard)160 }161 else {162 console.log("end turn!");163 cancelPick()164 endTurn()165 gBoard[destinationRow][destinationCol].isSelected = false166 if ((gBoard[destinationRow][destinationCol].isWhitePiece && gBoard[destinationRow][destinationCol].location.row === 7)167 ||168 (!gBoard[destinationRow][destinationCol].isWhitePiece && gBoard[destinationRow][destinationCol].location.row === 0)) {169 crownSoldier(gBoard[destinationRow][destinationCol])170 setTimeout(() => {171 promotionSound.play()172 }, 200)173 }174 unMarkAll()175 updateScore()176 renderBoard(gBoard)177 }178}179const kingEat = (destinationRow, destinationCol, row, col) => {180 //loop by the difference between destination and gPickedPos and unmark all the cells181 const rowDiff = row - destinationRow182 const colDiff = col - destinationCol183 if (rowDiff < 0) {//turn the enemy piece to an empty cell184 if (colDiff < 0) {185 //down right186 for (let i = 1; i < Math.abs(rowDiff); i++) {187 if (gBoard[row + i][col + i].isOccupied && gBoard[row + i][col + i].isMarked) isWhitesTurn ? blackPiecesCount-- : whitePiecesCount--188 gBoard[row + i][col + i] = { location: { row: row + i, col: col + i }, isOccupied: false, isEatingPath: false }189 }190 } else {191 //down left192 for (let i = 1; i < Math.abs(rowDiff); i++) {193 if (gBoard[row + i][col - i].isOccupied && gBoard[row + i][col - i].isMarked) isWhitesTurn ? blackPiecesCount-- : whitePiecesCount--194 gBoard[row + i][col - i] = { location: { row: row + i, col: col - i }, isOccupied: false, isEatingPath: false }195 }196 }197 } else {198 if (colDiff < 0) {199 //up right200 for (let i = 1; i < Math.abs(rowDiff); i++) {201 if (gBoard[row - i][col + i].isOccupied && gBoard[row - i][col + i].isMarked) isWhitesTurn ? blackPiecesCount-- : whitePiecesCount--202 gBoard[row - i][col + i] = { location: { row: row - i, col: col + i }, isOccupied: false, isEatingPath: false }203 }204 } else {205 //up left206 for (let i = 1; i < Math.abs(rowDiff); i++) {207 if (gBoard[row - i][col - i].isOccupied && gBoard[row - i][col - i].isMarked) isWhitesTurn ? blackPiecesCount-- : whitePiecesCount--208 gBoard[row - i][col - i] = { location: { row: row - i, col: col - i }, isOccupied: false, isEatingPath: false }209 }210 }211 }212 gBoard[destinationRow][destinationCol] = gBoard[row][col]213 gBoard[destinationRow][destinationCol].location = { row: destinationRow, col: destinationCol }214 gBoard[row][col] = { location: { row, col }, isOccupied: false }215 //check is there are other possible cells to eat216 // gIsRecursiveEating = true217 // isCurrentlyEating = true218 unMarkAll()219 checkAndMarkPossibleMoves(destinationRow, destinationCol, gBoard[destinationRow][destinationCol].isWhitePiece, "king", true)220 gPickedPos = { row: destinationRow, col: destinationCol }221 // isCurrentlyEating = false222 let isMoreToEat = false223 gBoard.forEach(row => {224 row.forEach(cell => {225 if (cell.isOccupied && cell.isMarked) isMoreToEat = true226 })227 })228 if (isMoreToEat) {229 console.log("keep eating")230 isCurrentlyEating = true231 gIsRecursiveEating = true232 updateScore()233 }234 else {235 isCurrentlyEating = false236 gIsRecursiveEating = false237 console.log("end turn!");238 cancelPick()239 endTurn()240 unMarkAll()241 gBoard[destinationRow][destinationCol].isSelected = false242 renderBoard(gBoard)243 }244}245const cellClicked = (cell) => {246 let row = +cell.dataset.pos[0]247 let col = +cell.dataset.pos[2]248 if (!gBoard[row][col].isOccupied && !gBoard[row][col].isMarked) {249 const selectedCell = document.querySelector(".selected")250 if (!!selectedCell) {251 cancelPick()252 }253 }254 if (!!gPickedPos && isLegalMove(row, col)) playTurn(row, col)255}256const pieceClicked = (piece) => {257 if (isCurrentlyEating) return258 const selectedCell = document.querySelector(".selected")259 if (!!selectedCell) {260 cancelPick()261 gPickedPos = null262 }263 let elCell = piece.parentElement264 let row = +elCell.dataset.pos[0]265 let col = +elCell.dataset.pos[2]266 if (!gBoard[row][col].isOccupied || (gBoard[row][col].isOccupied && isWhitesTurn != gBoard[row][col].isWhitePiece)) return//checking to see i cant pick an empty cell267 const isWhite = gBoard[row][col].isWhitePiece268 const rank = gBoard[row][col].rank269 gPickedPos = { row, col }270 checkAndMarkPossibleMoves(row, col, isWhite, rank)271 //cheking possible moves..272 let markedCellExists = false273 gBoard.forEach(row => {274 row.forEach(cell => {275 if (cell.isMarked) markedCellExists = true276 })277 })278 if (!markedCellExists) {279 gPickedPos = null280 return281 }282 gBoard[row][col].isSelected = true283 renderBoard(gBoard)284}285const cancelPick = (ev) => {286 if (gPickedPos === null || isCurrentlyEating) return287 if (ev && (ev.target.classList[0] === "cell" || ev.target.parentElement.classList[0] === "cell")) return;288 const selectedCells = document.querySelector(".selected")289 if (!!selectedCells) {290 gBoard.forEach(row => {291 row.forEach(cell => {292 cell.isSelected = false293 cell.isMarked = false294 cell.isEatingPath = false295 })296 })297 // selectedCells.classList.remove("selected")298 gPickedPos = null299 }300 gIsRecursiveEating = false301 renderBoard(gBoard)302}303const isLegalMove = (row, col) => {304 if (gBoard[row][col].isOccupied || !gBoard[row][col].isMarked) return false305 const rowDiff = gPickedPos.row - row306 const colDiff = gPickedPos.col - col307 if (gBoard[gPickedPos.row][gPickedPos.col].rank === "soldier") {//soldier308 if (Math.abs(rowDiff) === 1 && Math.abs(colDiff) === 1) {309 return true310 } else if (Math.abs(rowDiff) === 2 && Math.abs(colDiff) === 2) {311 if (rowDiff < 0) {//turn the enemy piece to an empty cell312 if (colDiff < 0) {313 //down right314 if (gPickedPos.row + 1 < 8 && gPickedPos.col + 1 < 8 && gBoard[gPickedPos.row + 1][gPickedPos.col + 1].isOccupied315 &&316 gBoard[gPickedPos.row + 1][gPickedPos.col + 1].isWhitePiece === isWhitesTurn) return false317 } else {318 //down left319 if (gPickedPos.row + 1 < 8 && gPickedPos.col - 1 >= 0 && gBoard[gPickedPos.row + 1][gPickedPos.col - 1].isOccupied320 &&321 gBoard[gPickedPos.row + 1][gPickedPos.col - 1].isWhitePiece === isWhitesTurn) return false322 }323 } else {324 if (colDiff < 0) {325 //up right326 if (gPickedPos.row - 1 >= 0 && gPickedPos.col + 1 < 8 && gBoard[gPickedPos.row - 1][gPickedPos.col + 1].isOccupied327 &&328 gBoard[gPickedPos.row - 1][gPickedPos.col + 1].isWhitePiece === isWhitesTurn) return false329 } else {330 //up left331 if (gPickedPos.row - 1 >= 0 && gPickedPos.col - 1 >= 0 && gBoard[gPickedPos.row - 1][gPickedPos.col - 1].isOccupied332 &&333 gBoard[gPickedPos.row - 1][gPickedPos.col - 1].isWhitePiece === isWhitesTurn) return false334 }335 }336 //eating337 return true338 } else return false339 } else {//king340 //implement king legal moves logic341 if (Math.abs(rowDiff) != Math.abs(colDiff)) return false342 if (rowDiff < 0) {//turn the enemy piece to an empty cell343 if (colDiff < 0) {344 //down right345 for (let i = 1; i < Math.abs(rowDiff); i++) {346 if (gPickedPos.row + i > 7 || gPickedPos.col + i > 8) break347 if (gBoard[gPickedPos.row + i][gPickedPos.col + i].isOccupied && gBoard[gPickedPos.row + i][gPickedPos.col + i].isWhitePiece === isWhitesTurn) return false348 }349 } else {350 //down left351 for (let i = 1; i < Math.abs(rowDiff); i++) {352 if (gPickedPos.row + i > 7 || gPickedPos.col - i < 0) break353 if (gBoard[gPickedPos.row + i][gPickedPos.col - i].isOccupied && gBoard[gPickedPos.row + i][gPickedPos.col - i].isWhitePiece === isWhitesTurn) return false354 }355 }356 } else {357 if (colDiff < 0) {358 //up right359 for (let i = 1; i < Math.abs(rowDiff); i++) {360 if (gPickedPos.row - i < 0 || gPickedPos.col + i > 7) break361 if (gBoard[gPickedPos.row - i][gPickedPos.col + i].isOccupied && gBoard[gPickedPos.row - i][gPickedPos.col + i].isWhitePiece === isWhitesTurn) return false362 }363 } else {364 //up left365 for (let i = 1; i < Math.abs(rowDiff); i++) {366 if (gPickedPos.row - i < 0 || gPickedPos.col - i < 0) break367 if (gBoard[gPickedPos.row - i][gPickedPos.col - i].isOccupied && gBoard[gPickedPos.row - i][gPickedPos.col - i].isWhitePiece === isWhitesTurn) return false368 }369 }370 }371 return true372 }373}374const checkAndMarkPossibleMoves = (row, col, isWhite, rank, isUnmarked = false) => {375 gPossibleMoves = []376 let isCellEmpty = !gBoard[row][col].isOccupied377 let isEnemyPiece = gBoard[row][col].isOccupied && (gBoard[row][col].isWhitePiece != isWhite)378 let temp = []379 let shouldMark = false380 if (rank === "king") {381 if (gIsRecursiveEating) {382 console.log("isCurrentlyEating:", isCurrentlyEating);383 //down right384 for (let i = 1; i < (8 - row) && i < (8 - col); i++) {385 if (!(row + i + 1 < 8 && col + i + 1 < 8 && !gBoard[row + i][col + i].isMarked)) break386 // if unoccupied add to tempArray387 if (!gIsDownRight && !isCorrectDirection(row, col, row + i, col + i)) break388 if (!gBoard[row + i][col + i].isOccupied) temp.push({ row: row + i, col: col + i })389 else if (gBoard[row + i][col + i].isOccupied && gBoard[row + i][col + i].isWhitePiece === isWhitesTurn) break390 else if (gBoard[row + i][col + i].isOccupied && gBoard[row + i + 1][col + i + 1].isOccupied) break391 if (392 gBoard[row + i][col + i].isOccupied393 &&394 gBoard[row + i][col + i].isWhitePiece != isWhitesTurn395 &&396 !gBoard[row + i + 1][col + i + 1].isOccupied397 &&398 !gBoard[row + i + 1][col + i + 1].isMarked) {399 shouldMark = true400 gBoard[row + i][col + i].isMarked = true401 if (!isCurrentlyEating) gBoard[row][col].isMarked = true402 temp.push({ row: row + i + 1, col: col + i + 1 })403 }404 }405 temp = [...new Set(temp)]406 if (shouldMark) temp.forEach(cell => {407 gBoard[cell.row][cell.col].isMarked = true408 // gPossibleMoves.push(cell)409 })410 temp = []411 shouldMark = false412 //down left413 for (let i = 1; i < (8 - row) && i < col + 1; i++) {414 if (!(row + i + 1 < 8 && col - i - 1 >= 0 && !gBoard[row + i][col - i].isMarked)) break415 // if unoccupied add to tempArray416 if (!gIsDownLeft && !isCorrectDirection(row, col, row + i, col - i)) break417 if (!gBoard[row + i][col - i].isOccupied) temp.push({ row: row + i, col: col - i })418 else if (gBoard[row + i][col - i].isOccupied && gBoard[row + i][col - i].isWhitePiece === isWhitesTurn) break419 else if (gBoard[row + i][col - i].isOccupied && gBoard[row + i + 1][col - i - 1].isOccupied) break420 if (421 gBoard[row + i][col - i].isOccupied422 &&423 gBoard[row + i][col - i].isWhitePiece != isWhitesTurn424 &&425 !gBoard[row - i - 1][col - i - 1].isOccupied426 &&427 !gBoard[row - i - 1][col - i - 1].isMarked) {428 shouldMark = true429 Board[row + i][col - i].isMarked = true430 temp.push({ row: row + i + 1, col: col - i - 1 })431 }432 }433 temp = [...new Set(temp)]434 if (shouldMark) temp.forEach(cell => {435 gBoard[cell.row][cell.col].isMarked = true436 // gPossibleMoves.push(cell)437 })438 temp = []439 shouldMark = false440 //up left441 for (let i = 1; i < row + 1 && i < col + 1; i++) {442 if (!(row - i - 1 >= 0 && col - i - 1 >= 0 && !gBoard[row - i][col - i].isMarked)) break443 // if unoccupied add to tempArray444 if (!gIsUpLeft && !isCorrectDirection(row, col, row - i, col - i)) break445 if (!gBoard[row - i][col - i].isOccupied) temp.push({ row: row - i, col: col - i })446 else if (gBoard[row - i][col - i].isOccupied && gBoard[row - i][col - i].isWhitePiece === isWhitesTurn) break447 else if (gBoard[row - i][col - i].isOccupied && gBoard[row - i - 1][col - i - 1].isOccupied) break448 if (449 gBoard[row - i][col - i].isOccupied450 &&451 gBoard[row - i][col - i].isWhitePiece != isWhitesTurn452 &&453 !gBoard[row - i - 1][col - i - 1].isOccupied454 &&455 !gBoard[row - i - 1][col - i - 1].isMarked) {456 shouldMark = true457 gBoard[row - i][col - i].isMarked = true458 temp.push({ row: row - i - 1, col: col - i - 1 })459 }460 }461 temp = [...new Set(temp)]462 if (shouldMark) temp.forEach(cell => {463 gBoard[cell.row][cell.col].isMarked = true464 // gPossibleMoves.push(cell)465 })466 temp = []467 shouldMark = false468 //up right469 for (let i = 1; i < row + 1 && i < (8 - col); i++) {470 if (!(row - i - 1 >= 0 && col + i + 1 < 8 && !gBoard[row - i][col + i].isMarked)) break471 // if unoccupied add to tempArray472 if (!gIsUpRight && !isCorrectDirection(row, col, row - i, col + i)) break473 if (!gBoard[row - i][col + i].isOccupied) temp.push({ row: row - i, col: col + i })474 else if (gBoard[row - i][col + i].isOccupied && gBoard[row - i][col + i].isWhitePiece === isWhitesTurn) break475 else if (gBoard[row - i][col + i].isOccupied && gBoard[row - i - 1][col + i + 1].isOccupied) break476 if (477 gBoard[row - i][col + i].isOccupied478 &&479 gBoard[row - i][col + i].isWhitePiece != isWhitesTurn480 &&481 !gBoard[row - i - 1][col + i + 1].isOccupied482 &&483 !gBoard[row - i - 1][col + i + 1].isMarked484 ) {485 shouldMark = true486 gBoard[row - i][col + i].isMarked = true487 temp.push({ row: row - i - 1, col: col + i + 1 })488 }489 }490 temp = [...new Set(temp)]491 if (shouldMark) temp.forEach(cell => {492 gBoard[cell.row][cell.col].isMarked = true493 // gPossibleMoves.push(cell)494 })495 temp = []496 shouldMark = false497 gIsDownRight = false;498 gIsDownLeft = false;499 gIsUpRight = false;500 gIsUpLeft = false;501 }502 else {503 //down right504 for (let i = 1; i < (8 - row) && i < (8 - col); i++) {505 if (gBoard[row + i][col + i].isOccupied && gBoard[row + i][col + i].isWhitePiece === isWhite) break506 else if (!gBoard[row + i][col + i].isOccupied) {507 gBoard[row + i][col + i].isMarked = true508 gPossibleMoves.push({ row: row + i, col: col + i })509 }510 else if (row + i + 1 < 8 && col + i + 1 < 8 && (gBoard[row + i][col + i].isWhitePiece != isWhite) && !gBoard[row + i + 1][col + i + 1].isOccupied) {511 gBoard[row + i + 1][col + i + 1].isMarked = true512 gBoard[row + i + 1][col + i + 1].isEatingPath = true513 gBoard[row + i][col + i].isMarked = true514 gPossibleMoves.push({ row: row + i + 1, col: col + i + 1 })515 gIsRecursiveEating = true;516 gIsDownRight = true517 } else break;518 }519 //down left520 for (let i = 1; i < (8 - row) && i < col + 1; i++) {521 if (gBoard[row + i][col - i].isOccupied && gBoard[row + i][col - i].isWhitePiece === isWhite) break522 else if (!gBoard[row + i][col - i].isOccupied) {523 gBoard[row + i][col - i].isMarked = true524 gPossibleMoves.push({ row: row + i, col: col - i })525 }526 else if (row + i + 1 < 8 && col - i - 1 >= 0 && (gBoard[row + i][col - i].isWhitePiece != isWhite) && !gBoard[row + i + 1][col - i - 1].isOccupied) {527 gBoard[row + i + 1][col - i - 1].isMarked = true528 gBoard[row + i + 1][col - i - 1].isEatingPath = true529 gBoard[row + i][col - i].isMarked = true530 gPossibleMoves.push({ row: row + i + 1, col: col - i - 1 })531 gIsRecursiveEating = true;532 gIsDownLeft = true533 } else break534 }535 //up left536 for (let i = 1; i < row + 1 && i < col + 1; i++) {537 if (gBoard[row - i][col - i].isOccupied && gBoard[row - i][col - i].isWhitePiece === isWhite) break538 else if (!gBoard[row - i][col - i].isOccupied) {539 gBoard[row - i][col - i].isMarked = true540 gPossibleMoves.push({ row: row - i, col: col - i })541 }542 else if (row - i - 1 >= 0 && col - i - 1 >= 0 && (gBoard[row - i][col - i].isWhitePiece != isWhite) && !gBoard[row - i - 1][col - i - 1].isOccupied) {543 gBoard[row - i - 1][col - i - 1].isMarked = true544 gBoard[row - i - 1][col - i - 1].isEatingPath = true545 gBoard[row - i][col - i].isMarked = true546 gPossibleMoves.push({ row: row - i - 1, col: col - i - 1 })547 gIsRecursiveEating = true;548 gIsUpLeft = true549 } else break550 }551 //up right552 for (let i = 1; i < row + 1 && i < (8 - col); i++) {553 if (gBoard[row - i][col + i].isOccupied && gBoard[row - i][col + i].isWhitePiece === isWhite) break554 else if (!gBoard[row - i][col + i].isOccupied) {555 gBoard[row - i][col + i].isMarked = true556 gPossibleMoves.push({ row: row - i, col: col + i })557 }558 else if (row - i - 1 >= 0 && col + i + 1 < 8 && (gBoard[row - i][col + i].isWhitePiece != isWhite) && !gBoard[row - i - 1][col + i + 1].isOccupied) {559 gBoard[row - i - 1][col + i + 1].isMarked = true560 gBoard[row - i - 1][col + i + 1].isEatingPath = true561 gBoard[row - i][col + i].isMarked = true562 gPossibleMoves.push({ row: row - i - 1, col: col + i + 1 })563 gIsUpRight = true564 } else break565 }566 }567 }568 else {569 if (gIsRecursiveEating) {570 if (//checking if can continue eating by checking if theres a possible targeted enemy piece around571 isUnmarked ||572 ((row + 1 < 8 && col + 1 < 8 && gBoard[row + 1][col + 1].isMarked && gBoard[row + 1][col + 1].isOccupied)573 ||574 (row + 1 < 8 && col - 1 >= 0 && gBoard[row + 1][col - 1].isMarked && gBoard[row + 1][col - 1].isOccupied)575 ||576 (row - 1 >= 0 && col + 1 < 8 && gBoard[row - 1][col + 1].isMarked && gBoard[row - 1][col + 1].isOccupied)577 ||578 (row - 1 >= 0 && col - 1 >= 0 && gBoard[row - 1][col - 1].isMarked && gBoard[row - 1][col - 1].isOccupied)579 )) {580 if (!isEnemyPiece && row - 2 >= 0 && col + 2 < 8 && gBoard[row - 1][col + 1].isOccupied && (gBoard[row - 1][col + 1].isWhitePiece != isWhite) && !gBoard[row - 2][col + 2].isOccupied && !gBoard[row - 2][col + 2].isMarked) {581 gBoard[row - 1][col + 1].isMarked = true;582 gBoard[row - 2][col + 2].isMarked = true;583 gPossibleMoves.push({ row: row - 2, col: col + 2 });584 }585 if (!isEnemyPiece && row - 2 >= 0 && col - 2 >= 0 && gBoard[row - 1][col - 1].isOccupied && (gBoard[row - 1][col - 1].isWhitePiece != isWhite) && !gBoard[row - 2][col - 2].isOccupied && !gBoard[row - 2][col - 2].isMarked) {586 gBoard[row - 1][col - 1].isMarked = true;587 gBoard[row - 2][col - 2].isMarked = true;588 gPossibleMoves.push({ row: row - 2, col: col - 2 });589 }590 if (!isEnemyPiece && row + 2 < 8 && col + 2 < 8 && gBoard[row + 1][col + 1].isOccupied && (gBoard[row + 1][col + 1].isWhitePiece != isWhite) && !gBoard[row + 2][col + 2].isOccupied && !gBoard[row + 2][col + 2].isMarked) {591 gBoard[row + 1][col + 1].isMarked = true;592 gBoard[row + 2][col + 2].isMarked = true;593 gPossibleMoves.push({ row: row + 2, col: col + 2 });594 }595 if (!isEnemyPiece && row + 2 < 8 && col - 2 >= 0 && gBoard[row + 1][col - 1].isOccupied && (gBoard[row + 1][col - 1].isWhitePiece != isWhite) && !gBoard[row + 2][col - 2].isOccupied && !gBoard[row + 2][col - 2].isMarked) {596 gBoard[row + 1][col - 1].isMarked = true;597 gBoard[row + 2][col - 2].isMarked = true;598 gPossibleMoves.push({ row: row + 2, col: col - 2 });599 }600 }601 }602 if (!gIsRecursiveEating && isWhite) {//white603 if (isWhite && !isCellEmpty && !isEnemyPiece && row + 1 < 8 && col + 1 < 8 && !gBoard[row + 1][col + 1].isOccupied) {604 gPossibleMoves.push({ row: row + 1, col: col + 1 });605 gBoard[row + 1][col + 1].isMarked = true;606 }607 if (isWhite && !isCellEmpty && !isEnemyPiece && row + 1 < 8 && col - 1 >= 0 && !gBoard[row + 1][col - 1].isOccupied) {608 gPossibleMoves.push({ row: row + 1, col: col - 1 });609 gBoard[row + 1][col - 1].isMarked = true610 }611 if (!isEnemyPiece && row + 2 < 8 && col + 2 < 8 && gBoard[row + 1][col + 1].isOccupied && (gBoard[row + 1][col + 1].isWhitePiece != isWhite) && !gBoard[row + 2][col + 2].isOccupied) {612 gBoard[row + 1][col + 1].isMarked = true;613 gBoard[row + 2][col + 2].isMarked = true;614 gPossibleMoves.push({ row: row + 2, col: col + 2 });615 gIsRecursiveEating = true616 }617 if (!isEnemyPiece && row + 2 < 8 && col - 2 >= 0 && gBoard[row + 1][col - 1].isOccupied && (gBoard[row + 1][col - 1].isWhitePiece != isWhite) && !gBoard[row + 2][col - 2].isOccupied) {618 gBoard[row + 1][col - 1].isMarked = true;619 gBoard[row + 2][col - 2].isMarked = true;620 gPossibleMoves.push({ row: row + 2, col: col - 2 });621 gIsRecursiveEating = true622 }623 }624 else if (!gIsRecursiveEating && !isWhite) {//black625 if (!isWhite && !isCellEmpty && !isEnemyPiece && row - 1 >= 0 && col + 1 < 8 && !gBoard[row - 1][col + 1].isOccupied) {626 gPossibleMoves.push({ row: row - 1, col: col + 1 });627 gBoard[row - 1][col + 1].isMarked = true;628 }629 if (!isWhite && !isCellEmpty && !isEnemyPiece && row - 1 >= 0 && col - 1 >= 0 && !gBoard[row - 1][col - 1].isOccupied) {630 gPossibleMoves.push({ row: row - 1, col: col - 1 });631 gBoard[row - 1][col - 1].isMarked = true;632 }633 if (!isEnemyPiece && row - 2 >= 0 && col + 2 < 8 && gBoard[row - 1][col + 1].isOccupied && (gBoard[row - 1][col + 1].isWhitePiece != isWhite) && !gBoard[row - 2][col + 2].isOccupied) {634 gBoard[row - 1][col + 1].isMarked = true;635 gBoard[row - 2][col + 2].isMarked = true;636 gPossibleMoves.push({ row: row - 2, col: col + 2 });637 gIsRecursiveEating = true638 }639 if (!isEnemyPiece && row - 2 >= 0 && col - 2 >= 0 && gBoard[row - 1][col - 1].isOccupied && (gBoard[row - 1][col - 1].isWhitePiece != isWhite) && !gBoard[row - 2][col - 2].isOccupied) {640 gBoard[row - 1][col - 1].isMarked = true;641 gBoard[row - 2][col - 2].isMarked = true;642 gPossibleMoves.push({ row: row - 2, col: col - 2 });643 gIsRecursiveEating = true644 }645 }646 }647 renderBoard(gBoard)648 gPossibleMoves = [...new Set(gPossibleMoves)]649 if (gIsRecursiveEating) {650 if (gBoard[row][col].rank === "king") return651 gPossibleMoves.forEach(move => {652 // if (gBoard[row][col].rank === "king") isUnmarked = true653 checkAndMarkPossibleMoves(move.row, move.col, isWhite, rank, isUnmarked)654 })655 }656}657const unMarkAll = () => {658 gBoard.forEach(row => {659 row.forEach(cell => {660 cell.isMarked = false661 })662 })663 renderBoard(gBoard)664}665const checkEatenPiecesAround = (row, col) => {666 //gPickedPos.row- row ===> if smaller than 0 we check if if right down(one square) is not occupied, then if theres any occupied+marked cells 667 const rowDiff = gPickedPos.row - row668 const colDiff = gPickedPos.col - col669 if (rowDiff < 0) {670 if (colDiff < 0) {671 for (let i = 1; i < (8 - row) && i < (8 - col); i++) {672 if (i > 1 && !gBoard[gPickedPos.row + i][gPickedPos.col + i].isOccupied) return false673 if (gBoard[gPickedPos.row + i][gPickedPos.col + i].isOccupied && gBoard[gPickedPos.row + i][gPickedPos.col + i].isMarked) return true674 }675 } else {676 for (let i = 1; i < (8 - row) && i < col + 1; i++) {677 if (gBoard[gPickedPos.row + i][gPickedPos.col - i].isOccupied && gBoard[gPickedPos.row + i][gPickedPos.col - i]) return true678 }679 }680 } else {681 if (colDiff < 0) {682 for (let i = 1; i < row + 1 && i < col + 1; i++) {683 if (i > 1 && !gBoard[gPickedPos.row - i][gPickedPos.col - i].isOccupied) return false684 if (gBoard[gPickedPos.row - i][gPickedPos.col - i].isOccupied && gBoard[gPickedPos.row - i][gPickedPos.col - i].isMarked) return true685 }686 } else {687 for (let i = 1; i < row + 1 && i < (8 - col); i++) {688 if (i > 1 && !gBoard[gPickedPos.row - i][gPickedPos.col + i].isOccupied) return false689 if (gBoard[gPickedPos.row - i][gPickedPos.col + i].isOccupied && gBoard[gPickedPos.row - i][gPickedPos.col + i].isMarked) return true690 }691 }692 }693 // if (gBoard[row][col].rank === "king") {694 //down right695 // } else {696 // return (697 // row + 1 < 8 && col + 1 < 8 && gBoard[row + 1][col + 1].isOccupied && gBoard[row + 1][col + 1].isMarked698 // ||699 // row + 1 < 8 && col - 1 >= 0 && gBoard[row + 1][col - 1].isOccupied && gBoard[row + 1][col - 1].isMarked700 // ||701 // row - 1 >= 0 && col - 1 >= 0 && gBoard[row - 1][col - 1].isOccupied && gBoard[row - 1][col - 1].isMarked702 // ||703 // row - 1 >= 0 && col + 1 < 8 && gBoard[row - 1][col + 1].isOccupied && gBoard[row - 1][col + 1].isMarked704 // )705 // }706}707const crownSoldier = (cell) => {708 cell.rank = "king"709 //play promotion sound710}711const isAbleToEat = () => {712 const cellsToBurn = []713 gBoard.forEach(row => {714 row.forEach(cell => {715 const row = cell.location.row716 const col = cell.location.col717 const isWhite = cell.isWhitePiece718 if (isWhite != isWhitesTurn) return719 if (cell.rank === "soldier") {720 if (isWhite) {721 if (row + 2 < 8 && col + 2 < 8 && gBoard[row + 1][col + 1].isOccupied && (gBoard[row + 1][col + 1].isWhitePiece != isWhite) && !gBoard[row + 2][col + 2].isOccupied) {722 cellsToBurn.push(cell)723 }724 if (row + 2 < 8 && col - 2 >= 0 && gBoard[row + 1][col - 1].isOccupied && (gBoard[row + 1][col - 1].isWhitePiece != isWhite) && !gBoard[row + 2][col - 2].isOccupied) {725 cellsToBurn.push(cell)726 }727 } else {728 if (row - 2 >= 0 && col + 2 < 8 && gBoard[row - 1][col + 1].isOccupied && (gBoard[row - 1][col + 1].isWhitePiece != isWhite) && !gBoard[row - 2][col + 2].isOccupied) {729 cellsToBurn.push(cell)730 }731 if (row - 2 >= 0 && col - 2 >= 0 && gBoard[row - 1][col - 1].isOccupied && (gBoard[row - 1][col - 1].isWhitePiece != isWhite) && !gBoard[row - 2][col - 2].isOccupied) {732 cellsToBurn.push(cell)733 }734 }735 } else {736 //down right row+ col+737 for (let i = 1; i < (8 - row) && i < (8 - col); i++) {738 if (!gBoard[row + i][col + i].isOccupied) continue739 else if (gBoard[row + i][col + i].isWhitePiece === isWhitesTurn) break740 else if (row + i + 1 < 8 && col + i + 1 < 8 &&741 gBoard[row + i][col + i].isWhitePiece != isWhitesTurn742 &&743 gBoard[row + i][col + i].isOccupied744 &&745 !gBoard[row + i + 1][col + i + 1].isOccupied) cellsToBurn.push(cell)746 else if (row + i + 1 < 8 && col + i + 1 < 8 &&747 gBoard[row + i][col + i].isOccupied748 &&749 gBoard[row + i + 1][col + i + 1].isOccupied) break750 }751 //down left row+ col-752 for (let i = 1; i < (8 - row) && i < col + 1; i++) {753 if (!gBoard[row + i][col - i].isOccupied) continue754 else if (gBoard[row + i][col - i].isWhitePiece === isWhitesTurn) break755 else if (row + i + 1 < 8 && col - i - 1 >= 0756 &&757 gBoard[row + i][col - i].isOccupied758 &&759 gBoard[row + i][col - i].isWhitePiece != isWhitesTurn760 &&761 !gBoard[row + i + 1][col - i - 1].isOccupied) cellsToBurn.push(cell)762 else if (row + i + 1 < 8 && col - i - 1 >= 0763 &&764 gBoard[row + i][col - i].isOccupied765 &&766 gBoard[row + i + 1][col - i - 1].isOccupied) break767 }768 //up left row- col-769 for (let i = 1; i < row + 1 && i < col + 1; i++) {770 if (!gBoard[row - i][col - i].isOccupied) continue771 else if (gBoard[row - i][col - i].isWhitePiece === isWhitesTurn) break772 else if (row - i - 1 >= 0 && col - i - 1 >= 0773 &&774 gBoard[row - i][col - i].isOccupied775 &&776 gBoard[row - i][col - i].isWhitePiece != isWhitesTurn777 &&778 !gBoard[row - i - 1][col - i - 1].isOccupied) cellsToBurn.push(cell)779 else if (row - i - 1 >= 0 && col - i - 1 >= 0780 &&781 gBoard[row - i][col - i].isOccupied782 &&783 gBoard[row - i - 1][col - i - 1].isOccupied) break784 }785 //up right row- col +786 for (let i = 1; i < row + 1 && i < (8 - col); i++) {787 if (!gBoard[row - i][col + i].isOccupied) continue788 else if (gBoard[row - i][col + i].isWhitePiece === isWhitesTurn) break789 else if (row - i - 1 >= 0 && col + i + 1 < 8790 &&791 gBoard[row - i][col + i].isOccupied792 &&793 gBoard[row - i][col + i].isWhitePiece != isWhitesTurn794 &&795 !gBoard[row - i - 1][col + i + 1].isOccupied) cellsToBurn.push(cell)796 else if (row - i - 1 >= 0 && col + i + 1 < 8797 &&798 gBoard[row - i][col + i].isOccupied799 &&800 gBoard[row - i - 1][col + i + 1].isOccupied) break801 }802 }803 })804 })805 if (cellsToBurn.length > 0) {806 gOnlyKingsMoveCounter = 0807 badSound.play();808 }809 cellsToBurn.forEach(cell => {810 gBoard[cell.location.row][cell.location.col].isWhitePiece ? whitePiecesCount-- : blackPiecesCount--811 gBoard[cell.location.row][cell.location.col] = { location: { row: cell.location.row, col: cell.location.col }, isOccupied: false }812 })813 cancelPick()814}815const isLegalMoveLeft = () => {816 let movesLeft = false;817 gBoard.forEach(gameRow => {818 gameRow.forEach(cell => {819 const row = cell.location.row820 const col = cell.location.col821 if (!cell.isOccupied || cell.isWhitePiece != isWhitesTurn) return822 if (cell.rank === "king" || cell.isWhitePiece) {//white or king823 //down right824 if (row + 1 < 8 && col + 1 < 8 && !gBoard[row + 1][col + 1].isOccupied) {825 movesLeft = true826 return827 }828 else if (row + 2 < 8 && col + 2 < 8 && !gBoard[row + 2][col + 2].isOccupied) {829 movesLeft = true830 return831 }832 if (row + 1 < 8 && col - 1 >= 0 && !gBoard[row + 1][col - 1].isOccupied) {833 movesLeft = true834 return835 }836 else if (row + 2 < 8 && col - 2 >= 0 && !gBoard[row + 2][col - 2].isOccupied) {837 movesLeft = true838 return839 }840 }841 if (cell.rank === "king" || !cell.isWhitePiece) {//black or king842 if (row - 1 >= 0 && col + 1 < 8 && !gBoard[row - 1][col + 1].isOccupied) {843 movesLeft = true844 return845 }846 else if (row - 2 >= 0 && col + 2 < 8 && !gBoard[row - 2][col + 2].isOccupied) {847 movesLeft = true848 return849 }850 if (row - 1 >= 0 && col - 1 >= 0 && !gBoard[row - 1][col - 1].isOccupied) {851 movesLeft = true852 return853 }854 else if (row - 2 >= 0 && col - 2 >= 0 && !gBoard[row - 2][col - 2].isOccupied) {855 movesLeft = true856 return857 }858 }859 })860 if (movesLeft) return861 })862 if (!movesLeft) {863 gameOver()864 updateScore()865 }866}867const countPiecesAndRank = () => {868 let whiteSoldierCount = 0869 let blackSoldierCount = 0870 let whiteKingCount = 0871 let blackKingCount = 0872 gBoard.forEach(row => {873 row.forEach(cell => {874 if (cell.isOccupied && cell.isWhitePiece && cell.rank === "soldier") whiteSoldierCount++875 else if (cell.isOccupied && !cell.isWhitePiece && cell.rank === "soldier") blackSoldierCount++876 else if (cell.isOccupied && cell.isWhitePiece && cell.rank === "king") whiteKingCount++877 else if (cell.isOccupied && !cell.isWhitePiece && cell.rank === "king") blackKingCount++878 })879 })880 if ((whiteKingCount === 2 && blackKingCount === 1) || blackKingCount === 2 && whiteKingCount === 1) {881 isDraw = true882 gameOver()883 updateScore()884 }885}886const isCorrectDirection = (currentRow, currentCol, row, col) => {887 console.log("currentRow: ", currentRow);888 console.log("currentCol: ", currentCol);889 const rowDiff = currentRow - row890 const colDiff = currentCol - col891 if (rowDiff < 0) {892 if (colDiff < 0) {893 //down right894 for (let i = 1; i <= Math.abs(rowDiff) && i <= Math.abs(colDiff); i++) {895 if (row - i < 0 || col - i < 0) break896 if (row - i === currentRow && col - i === currentCol) return true897 // if (gBoard[row - i][col - i].isOccupied && gBoard[row - i][col - i].isMarked && gBoard[row - i][col - i].isWhitePiece != isWhitesTurn) return true898 }899 } else {900 //down left901 for (let i = 1; i <= Math.abs(rowDiff) && i <= Math.abs(colDiff); i++) {902 if (row - i < 0 || col + i > 7) break903 console.log("row - i:", row - i);904 console.log("col + i:", col + i);905 if (row - i === currentRow && col + i === currentCol) return true906 // if (gBoard[row - i][col + i].isOccupied && gBoard[row - i][col + i].isMarked && gBoard[row - i][col + i].isWhitePiece != isWhitesTurn) return true907 }908 }909 } else {910 if (colDiff < 0) {911 //up right912 for (let i = 1; i <= Math.abs(rowDiff) && i <= Math.abs(colDiff); i++) {913 if (row + i > 7 || col - i < 0) break914 console.log("row + i === currentRow && col - i === currentCol:", row + i === currentRow && col - i === currentCol);915 if (row + i === currentRow && col - i === currentCol) return true916 // if (gBoard[row + i][col - i].isOccupied && gBoard[row + i][col - i].isMarked && gBoard[row + i][col - i].isWhitePiece != isWhitesTurn) return true917 }918 } else {919 //up left920 for (let i = 1; i <= Math.abs(rowDiff) && i <= Math.abs(colDiff); i++) {921 if (row + i > 7 || col + i > 7) break922 console.log("row + i:", row + i);923 console.log("col + i:", col + i);924 if (row + i === currentRow && col + i === currentCol) return true925 // if (gBoard[row + i][col + i].isOccupied && gBoard[row + i][col + i].isMarked && gBoard[row + i][col + i].isWhitePiece != isWhitesTurn) return true926 }927 }928 }929 return false...

Full Screen

Full Screen

747110cb83c5d9948fa42e36cd4e7f19ad369eReactDebugTool.js

Source:747110cb83c5d9948fa42e36cd4e7f19ad369eReactDebugTool.js Github

copy

Full Screen

...147 currentTimerType = timerType;148 };149 var lastMarkTimeStamp = 0;150 var canUsePerformanceMeasure = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function';151 var shouldMark = function shouldMark(debugID) {152 if (!_isProfiling || !canUsePerformanceMeasure) {153 return false;154 }155 var element = ReactComponentTreeHook.getElement(debugID);156 if (element == null || typeof element !== 'object') {157 return false;158 }159 var isHostElement = typeof element.type === 'string';160 if (isHostElement) {161 return false;162 }163 return true;164 };165 var markBegin = function markBegin(debugID, markType) {166 if (!shouldMark(debugID)) {167 return;168 }169 var markName = debugID + '::' + markType;170 lastMarkTimeStamp = performanceNow();171 performance.mark(markName);172 };173 var markEnd = function markEnd(debugID, markType) {174 if (!shouldMark(debugID)) {175 return;176 }177 var markName = debugID + '::' + markType;178 var displayName = ReactComponentTreeHook.getDisplayName(debugID) || 'Unknown';179 var timeStamp = performanceNow();180 if (timeStamp - lastMarkTimeStamp > 0.1) {181 var measurementName = displayName + ' [' + markType + ']';182 performance.measure(measurementName, markName);183 }184 performance.clearMarks(markName);185 performance.clearMeasures(measurementName);186 };187 ReactDebugTool = {188 addHook: function addHook(hook) {...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...189 <input190 type="text"191 name="user"192 id="user-register"193 className={shouldMark('user') ? 'errInput' : ''}194 onChange={(e) => setUser(e.target.value)}195 onBlur={(e) => handleBlur(e.target.name)}196 />197 </div>198 {shouldMark('user') && (199 <div className="errors">200 {errors['user'].map((err, i) => (201 <p className="err-msg" key={i}>202 {err}203 </p>204 ))}205 </div>206 )}207 <div className="register-wrap">208 <label htmlFor="email">email:</label>209 <input210 type="text"211 name="email"212 id="email-register"213 className={shouldMark('email') ? 'errInput' : ''}214 onChange={(e) => setEmail(e.target.value)}215 onBlur={(e) => handleBlur(e.target.name)}216 />217 </div>218 {shouldMark('email') && (219 <div className="errors">220 {errors['email'].map((err, i) => (221 <p className="err-msg" key={i}>222 {err}223 </p>224 ))}225 </div>226 )}227 <div className="register-wrap">228 <label htmlFor="password">senha:</label>229 <input230 type="password"231 name="password"232 id="password-register"233 className={shouldMark('password') ? 'errInput' : ''}234 onChange={(e) => setPassword(e.target.value)}235 onBlur={(e) => handleBlur(e.target.name)}236 />237 </div>238 {shouldMark('password') && (239 <div className="errors">240 {errors['password'].map((err, i) => (241 <p className="err-msg" key={i}>242 {err}243 </p>244 ))}245 </div>246 )}247 <div className="register-wrap">248 <label htmlFor="confirm-pass">confirmar senha:</label>249 <input250 type="password"251 name="confirmPass"252 id="confirm-pass-register"253 className={shouldMark('confirmPass') ? 'errInput' : ''}254 onChange={(e) => setConfirmPass(e.target.value)}255 onBlur={(e) => handleBlur(e.target.name)}256 />257 </div>258 {shouldMark('confirmPass') && (259 <div className="errors">260 {errors['confirmPass'].map((err, i) => (261 <p className="err-msg" key={i}>262 {err}263 </p>264 ))}265 </div>266 )}267 <button type="submit">Confirmar</button>268 </div>269 </form>270 </div>271 </div>272 </div>...

Full Screen

Full Screen

ttAPIMarking.js

Source:ttAPIMarking.js Github

copy

Full Screen

1"use strict";23(async () => {4 await loadDatabase();56 if (!settings.pages.api.marking) return;78 try {9 markSelections();10 markResponses();11 } catch (e) {12 console.error(e);13 }1415 function markSelections() {16 for (const field of document.findAll(".panel-body > p[class*='_fields']")) {17 const type = getSection(field.classList[0].substring(0, 1));1819 new MutationObserver((mutations, observer) => {20 observer.disconnect();2122 toSpan(field);2324 for (const selection of API_SELECTIONS[type]) {25 const span = field.find(`.selection[data-selection="${selection}"]`);26 if (!span) continue;2728 span.classList.add("used");29 }30 }).observe(field, { childList: true });31 }3233 function toSpan(field) {34 if (field.classList.contains("tt-modified")) return;3536 field.classList.add("tt-modified");3738 const selections = field.textContent39 .split(": ")40 .slice(1)41 .join(": ")42 .split(",")43 .map((selection) => selection.trim());4445 const small = field.firstElementChild;4647 small.innerHTML = "";48 small.appendChild(document.newElement({ type: "strong", text: "Available fields: " }));4950 for (const selection of selections) {51 small.appendChild(document.newElement({ type: "span", text: selection, class: "selection", dataset: { selection } }));5253 if (selections.indexOf(selection) !== selections.length - 1) {54 small.appendChild(document.createTextNode(", "));55 }56 }57 }58 }5960 function markResponses() {61 for (const result of document.findAll(".panel-body > div[class*='_result']")) {62 const type = getSection(result.classList[0].substring(0, 1));6364 new MutationObserver(() => {65 const responseElement = result.firstElementChild;6667 const originalPre = responseElement.find("pre");68 originalPre.classList.add("original");6970 const modifiedPre = document.newElement({ type: "pre", class: "modified active" });71 responseElement.insertBefore(modifiedPre, originalPre);7273 try {74 populateResponse();75 } catch (error) {76 modifiedPre.appendChild(document.createTextNode("ERROR occurred!"));77 console.error(error);78 }79 createTabs();8081 function populateResponse() {82 const response = JSON.parse(originalPre.textContent);8384 modifiedPre.appendChild(document.newElement({ type: "span", text: "{" }));85 modifiedPre.appendChild(document.newElement("br"));86 loadResponse(response, API_USAGE[type], 1);87 modifiedPre.appendChild(document.newElement({ type: "span", text: "}" }));8889 function loadResponse(response, marking, indent) {90 for (const [key, value] of Object.entries(response)) {91 if (typeof value === "object") {92 if (Array.isArray(value)) {93 modifiedPre.appendChild(94 document.newElement({ type: "span", class: key in marking ? "used" : "", text: `${getIndent(indent)}"${key}": [` })95 );96 modifiedPre.appendChild(document.newElement("br"));9798 for (const item of value) {99 if (typeof item === "object") {100 if (Array.isArray(item)) {101 continue;102 } else if (item === null) {103 displayValue(key, null, indent, marking);104 } else {105 const toMark = marking === true || marking[key] === true || (key in marking ? "*" in marking[key] : false);106 const _marking = marking === true || marking[key] === true || (key in marking ? marking[key]["*"] || {} : {});107108 modifiedPre.appendChild(109 document.newElement({ type: "span", class: toMark ? "used" : "", text: `${getIndent(indent + 1)}{` })110 );111 modifiedPre.appendChild(document.newElement("br"));112 loadResponse(item, _marking || {}, indent + 2);113 modifiedPre.appendChild(114 document.newElement({ type: "span", class: toMark ? "used" : "", text: `${getIndent(indent + 1)}},` })115 );116 }117 } else {118 displayValue(false, item, indent + 1, marking[key]);119 }120 modifiedPre.appendChild(document.newElement("br"));121 }122123 modifiedPre.appendChild(124 document.newElement({ type: "span", class: key in marking ? "used" : "", text: `${getIndent(indent)}],` })125 );126 } else if (value === null) {127 displayValue(key, null, indent, marking);128 } else {129 const toMark = marking === true || key in marking || "*" in marking;130131 modifiedPre.appendChild(132 document.newElement({ type: "span", class: toMark ? "used" : "", text: `${getIndent(indent)}"${key}": {` })133 );134 modifiedPre.appendChild(document.newElement("br"));135 loadResponse(value, marking[key] || marking["*"] || {}, indent + 1);136 modifiedPre.appendChild(document.newElement({ type: "span", class: toMark ? "used" : "", text: `${getIndent(indent)}},` }));137 }138 } else {139 displayValue(key, value, indent, marking);140 }141 modifiedPre.appendChild(document.newElement("br"));142 }143144 function displayValue(key, value, indent, marking) {145 const marks = typeof value === "string";146147 if (typeof value === "object") value = String(value);148149 let display, shouldMark;150 if (key) {151 display = document.newElement({ type: "span", text: `${getIndent(indent)}"${key}": ${marks ? `"${value}"` : value},` });152 shouldMark = marking === true || key in marking || "*" in marking;153 } else {154 display = document.newElement({ type: "span", text: `${getIndent(indent)}${marks ? `"${value}"` : value},` });155 shouldMark = marking;156 }157 if (shouldMark) display.classList.add("used");158 modifiedPre.appendChild(display);159 }160 }161 }162163 function createTabs() {164 const original = document.newElement({ type: "div", class: "response-tab", text: "Original" });165 const modified = document.newElement({ type: "div", class: "response-tab active", text: "Modified" });166167 original.addEventListener("click", () => {168 [original, originalPre].forEach((x) => x.classList.add("active"));169 [modified, modifiedPre].forEach((x) => x.classList.remove("active"));170 });171 modified.addEventListener("click", () => {172 [modified, modifiedPre].forEach((x) => x.classList.add("active"));173 [original, originalPre].forEach((x) => x.classList.remove("active"));174 });175176 responseElement.insertBefore(document.newElement({ type: "div", class: "response-tabs", children: [original, modified] }), modifiedPre);177 }178 }).observe(result, { childList: true });179 }180181 function getIndent(level) {182 let indent = "";183184 for (let i = 0; i < level; i++) {185 indent += " ";186 }187188 return indent;189 }190 }191192 function getSection(char) {193 switch (char) {194 case "u":195 return "user";196 case "p":197 return "properties";198 case "f":199 return "faction";200 case "c":201 return "company";202 case "i":203 return "item_market";204 case "t":205 return "torn";206 default:207 return "user";208 }209 } ...

Full Screen

Full Screen

tileService.js

Source:tileService.js Github

copy

Full Screen

1import { Minesweeper, COORDS } from '../../../lib/minesweeper'2import { COLORS } from '../scenes/UI'3export class TileService {4 constructor(scene) {5 this.scene = scene6 this.uiScene = scene.scene.get('UI')7 if (window.room) {8 this.sweeper = new Minesweeper(window.room.state.toJSON().seed)9 } else {10 this.sweeper = new Minesweeper(Date.now().toString())11 }12 this.players = []13 }14 init = () => {15 this.lastCoords = {}16 this.textGroup = this.loadText()17 this.cursorGroup = this.loadCursors()18 this.chunks = this.loadChunks()19 this.tiles = this.chunks.map((c) => c.tiles.getChildren()).flat()20 this.update(true)21 }22 sync = (state) => {23 this.sweeper.state = state.tiles24 this.players = state.players25 this.update(true)26 this.scene.registry.set(27 'scores',28 this.players.map((p) => ({29 name: p.name,30 score: p.score,31 color: COLORS[p.index],32 })),33 )34 }35 loadChunks = () =>36 COORDS.map(([x, y]) => {37 const tiles = this.scene.add.group()38 for (let x = 0; x < CHUNK_SIZE; x++) {39 for (let y = 0; y < CHUNK_SIZE; y++) {40 const tile = this.scene.add.sprite(0, 0, 'tiles').setOrigin(0)41 tiles.add(tile)42 tile._cX = x43 tile._cY = y44 tile45 .setInteractive()46 .on('pointerover', (p) => {47 this.uiScene.cursorText.setText(`${tile._x},${tile._y}`)48 if (!this.isRevealable(tile)) return49 if (p.leftButtonDown()) {50 tile.setFrame(0)51 }52 })53 .on('pointerdown', (p) => {54 if (!this.isRevealable(tile) || p.rightButtonDown()) return55 tile.setFrame(0)56 this.scene.registry.set('face', 1)57 })58 .on('pointerout', (p) => {59 if (!this.isRevealable(tile)) return60 if (p.leftButtonDown()) {61 tile.setFrame(9)62 }63 })64 .on('pointerup', (p) => {65 if (!this.isRevealable(tile) && !p.rightButtonReleased()) return66 this.scene.registry.set('face', 0)67 this.onClickTile(tile, p.rightButtonReleased())68 })69 }70 }71 return { x, y, tiles }72 })73 update = (force) => {74 const { scrollX, scrollY } = this.scene.cameras.main75 const coords = getChunkCoords(scrollX, scrollY)76 if (77 !force &&78 this.lastCoords.x === coords.x &&79 this.lastCoords.y === coords.y80 )81 return82 this.lastCoords = coords83 this.chunks.forEach((chunk, i) => {84 chunk.x = COORDS[i][0] + coords.x85 chunk.y = COORDS[i][1] + coords.y86 const { width, height } = this.scene.cameras.main87 const yoffset = height / 2 - (TILE_SIZE * CHUNK_SIZE) / 288 const xoffset = width / 2 - (TILE_SIZE * CHUNK_SIZE) / 289 chunk.tiles.getChildren().forEach((tile) => {90 tile._x = tile._cX + chunk.x * CHUNK_SIZE91 tile._y = tile._cY + chunk.y * CHUNK_SIZE92 tile.x = tile._x * TILE_SIZE + xoffset93 tile.y = tile._y * TILE_SIZE + yoffset94 const frame = this.sweeper.getTileState(tile._x, tile._y)95 tile.setFrame(frame)96 if (frame === 10 || frame === 11) {97 const matchingPlayer = this.players.find((p) =>98 p.tiles.find(({ x, y }) => tile._x === x && tile._y === y),99 )100 tile.setTint(101 Phaser.Display.Color.HexStringToColor(102 COLORS[matchingPlayer?.index] || '#fff',103 ).color,104 )105 } else {106 tile.clearTint()107 }108 })109 })110 }111 loadText = () => {112 const group = this.scene.add.group({113 createCallback: (text) =>114 text115 .setFontFamily('Arial')116 .setFontSize(24)117 .setOrigin(0)118 .setStroke('#000', 4),119 })120 group.createMultiple({121 classType: Phaser.GameObjects.Text,122 key: ' ',123 visible: false,124 active: false,125 repeat: 20,126 max: 20,127 })128 return group129 }130 loadCursors = () => {131 this.cursors = {}132 this.cursorTweens = {}133 const group = this.scene.add.group()134 group.createMultiple({135 key: 'cursor',136 visible: false,137 active: false,138 repeat: 9,139 max: 9,140 })141 return group142 }143 updateCursor = (playerId, index, x, y) => {144 if (!this.uiScene.player?.id) return145 this.cursorGroup.getChildren().forEach((c) => c.setVisible(false))146 let cursor = this.cursors[playerId]147 if (!cursor) {148 cursor = this.cursorGroup.get()149 cursor150 .setVisible(true)151 .setActive(true)152 .setScale(2)153 .setOrigin(0, 0)154 .setDepth(11)155 cursor.setTint(156 Phaser.Display.Color.HexStringToColor(COLORS[index] || '#fff').color,157 )158 this.cursors[playerId] = cursor159 }160 cursor.setVisible(true)161 this.cursorTweens[playerId]?.remove()162 this.cursorTweens[playerId] = this.scene.tweens.add({163 targets: cursor,164 x: x,165 y: y,166 duration: 250,167 })168 }169 onClickTile = (tile, shouldMark) => {170 const frame = this.sweeper.getTileState(tile._x, tile._y)171 if (frame !== 9) return172 const isMine = this.sweeper.getIsMine(tile._x, tile._y)173 if ((isMine && !shouldMark) || (!isMine && shouldMark))174 this.scene.cameras.main.shake(250, 0.025)175 const { _x: x, _y: y } = tile176 const value = this.sweeper.getScore(x, y, shouldMark)177 this.scene.registry.set('face', value > 0 ? 2 : 3)178 if (window.room) {179 window.room.send('Move', { x, y, shouldMark })180 return181 }182 this.showScoreText(tile.x, tile.y, value)183 this.scene.registry.set('score', (s) => Math.max(0, s + value))184 if (shouldMark) {185 this.sweeper.markTile(x, y)186 } else {187 this.sweeper.revealTile(x, y)188 }189 this.tiles.forEach((sprite) =>190 sprite.setFrame(this.sweeper.getTileState(sprite._x, sprite._y)),191 )192 }193 onMove = (index, x, y, mark) => {194 const tile = this.tiles.find((t) => t._x === x && t._y === y)195 const value = this.sweeper.getScore(x, y, mark)196 this.showScoreText(tile.x, tile.y, value, COLORS[index])197 }198 showScoreText = (x, y, value, color = '#ffffff') => {199 const text = this.textGroup.get()200 text201 .setPosition(x, y)202 .setAlpha(1)203 .setActive(true)204 .setVisible(true)205 .setDepth(10)206 .setText(`${value > 0 ? '+' : '-'}${Math.abs(value)}`)207 .setColor(color)208 this.scene.tweens209 .createTimeline()210 .add({ targets: text, y: y - 10, duration: 800 })211 .add({212 targets: text,213 y: y - 15,214 alpha: 0,215 duration: 400,216 onComplete: () => text.setActive(false).setVisible(false),217 })218 .play()219 }220 isRevealable = (tile) => this.sweeper.getTileState(tile._x, tile._y) === 9221}222const TILE_SIZE = 32223const CHUNK_SIZE = 18224const getChunkCoords = (x, y) => ({ x: getChunkCoord(x), y: getChunkCoord(y) })225const getChunkCoord = (n) =>226 (CHUNK_SIZE * TILE_SIZE * Math.round(n / (CHUNK_SIZE * TILE_SIZE))) /227 CHUNK_SIZE /...

Full Screen

Full Screen

day14.js

Source:day14.js Github

copy

Full Screen

...101 regionGrid[y][x] = name;102 neigbors(x, y)103 .filter(function (_a) {104 var newX = _a[0], newY = _a[1];105 return shouldMark(regionGrid[newY][newX]);106 })107 .forEach(function (_a) {108 var newX = _a[0], newY = _a[1];109 return markRegion(name, newX, newY);110 });111}112var region = 0;113for (var y = 0; y < regionGrid.length; y++) {114 for (var x = 0; x < regionGrid[y].length; x++) {115 if (shouldMark(regionGrid[y][x])) {116 region++;117 markRegion(region, x, y);118 }119 }120}...

Full Screen

Full Screen

player.js

Source:player.js Github

copy

Full Screen

1import React, {useEffect, useState} from "react";2import {Button, Card, OverlayTrigger} from "react-bootstrap";3import {useStoreState} from "easy-peasy";4import {timeMin} from "../../utils/time";5import {useRegisterCmd} from "../ws/ws";6import Tooltip from "react-bootstrap/Tooltip";7export function Player(props) {8 const [time, setTime] = useState("00:00")9 // top or bottom10 const posish = props.posish;11 const {mode, browseIndex, gameTurn, browseTurn, lastMoveTimestamp, history, result,12 orientation, myColor, opponentOnline} = useStoreState(state => state.game)13 const {name, elo, serverTime} = useStoreState(state => state.game[posish])14 const currentBrowseMove = (mode === 'analysis') && ( posish === browseTurn ) && (browseIndex !== 0) && ((browseIndex !== history.length))15 const shouldTick = posish === gameTurn && !result16 const shouldMark = shouldTick || currentBrowseMove17 const isOpponent = orientation === myColor && posish === "top" || orientation !== myColor && posish === "bottom"18 const online = !isOpponent || opponentOnline19 //console.log("player " + posish + " opponent = " + isOpponent + " online = " + online)20 // timer21 useEffect(() => {22 if (shouldTick) {23 const interval = setInterval(() => {24 const elapsed = Date.now() - lastMoveTimestamp25 const clock = serverTime - elapsed26 setTime(timeMin(clock > 0 ? clock : 0))27 }, 100)28 return () => clearInterval(interval)29 } else {30 if (serverTime !== undefined)31 setTime(timeMin(serverTime))32 }33 }, [gameTurn, lastMoveTimestamp, serverTime, posish, result])34 return (35 <Card>36 <Card.Body>37 <div className="d-flex justify-content-between">38 <span className="mr-2" role="img">39 <OverlayTrigger placement="bottom" overlay={40 <Tooltip>41 {online ? "Online" : "Disconnected"}42 </Tooltip>43 }>44 <a className={"btn badge badge-pill " + (online ? "badge-success" : "badge-secondary")}>&nbsp;</a>45 </OverlayTrigger>46 <span className="ml-2" role="user">{name}</span>47 <span className="ml-2" role="img" aria-label="score">🏆48 <span className="ml-2" role="value">{elo}</span>49 </span>50 </span>51 <span className={shouldMark ? "text-warning ml-2" : "ml-2" } role="img" aria-label="clock">{shouldMark ? '⌛' : ''}52 <span className="ml-2 text-monospace" role="time">{time}</span>53 </span>54 </div>55 </Card.Body>56 </Card>57 )...

Full Screen

Full Screen

minesweeper.js

Source:minesweeper.js Github

copy

Full Screen

1import md5 from 'md5'2const FLOOD_DIST = 203const MINE_RATE = 84export class Minesweeper {5 constructor(seed = 'seed') {6 this.seed = seed7 this.state = {}8 this.markTile = (x, y) => {9 const tileState = this.getTileState(x, y)10 if (![9, 11].includes(tileState)) return11 const markFrame = tileState === 9 ? 11 : 912 this.setTileState(x, y, markFrame)13 }14 this.revealTile = (x, y) => {15 const frame = this.getIsMine(x, y) ? 10 : this.getMineCount(x, y)16 this.setTileState(x, y, frame)17 if (frame === 0) this.floodFill(x, y)18 }19 this.getIsMine = (x, y) =>20 intHash(`${this.seed}-${x}-${y}`) % MINE_RATE === 021 this.getTileState = (x, y) =>22 typeof this.state[`${x}:${y}`] === 'number' ? this.state[`${x}:${y}`] : 923 // TODO: doesn't fill diagonally24 this.floodFill = (_x, _y) => {25 let stack = [[_x, _y]]26 while (stack.length) {27 let [x, y] = stack.pop()28 while (y >= _y - FLOOD_DIST && this.hasHiddenAdj(x, y)) {29 y -= 130 }31 y += 132 while (y <= _y + FLOOD_DIST && this.hasHiddenAdj(x, y)) {33 this.revealAdj(x, y)34 if (x > _x - FLOOD_DIST) stack.push([x - 1, y])35 if (x < _x + FLOOD_DIST) stack.push([x + 1, y])36 y += 137 }38 }39 }40 this.getScore = (x, y, shouldMark) => {41 const isMine = this.getIsMine(x, y)42 const mineCount = this.getMineCount(x, y)43 if (shouldMark) {44 return isMine ? 1 : -145 } else {46 return isMine ? -10 : mineCount === 0 ? 3 : 147 }48 }49 this.hasHiddenAdj = (x, y) =>50 this.getFrame(x, y) === 0 &&51 NCOORDS.some(([i, j]) =>52 [9, 11].includes(this.getTileState(x + i, y + j)),53 )54 this.revealAdj = (x, y) =>55 COORDS.forEach(([i, j]) =>56 this.setTileState(x + i, y + j, this.getFrame(x + i, y + j)),57 )58 this.getMineCount = (x, y) =>59 NCOORDS.reduce(60 (n, [i, j]) => (this.getIsMine(x + i, y + j) ? n + 1 : n),61 0,62 )63 this.setTileState = (x, y, frame) => {64 this.state[`${x}:${y}`] = frame65 }66 this.getFrame = (x, y) =>67 this.getIsMine(x, y) ? 10 : this.getMineCount(x, y)68 }69}70const intHash = (str) =>71 md5(str)72 .split('')73 .reduce((n, c) => (n * 31 * c.charCodeAt(0)) % 982451653, 7)74// prettier-ignore75export const NCOORDS = [[-1,-1],[0,-1],[1,-1],[-1,0],[1,0],[-1,1],[0,1],[1,1]]...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { shouldMark } = require('playwright/lib/server/supplements/recorder/recorderSupplement');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('text=Google apps');8 await page.click('text=Maps');9 console.log(shouldMark(page, 'text=Google apps'));10 console.log(shouldMark(page, 'text=Maps'));11 console.log(shouldMark(page, 'text=News'));12 await browser.close();13})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shouldMark } = require('playwright/lib/server/trace/recorder');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const shouldMarkResult = shouldMark(page, 'foo');8 console.log(shouldMarkResult);9 await browser.close();10})();11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 const shouldMarkResult = page.shouldMark('foo');17 console.log(shouldMarkResult);18 await browser.close();19})();20const { chromium } = require('playwright');21(async () => {22 const browser = await chromium.launch();23 const context = await browser.newContext();24 const page = await context.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shouldMark } = require('playwright/lib/server/frames');2const { Page, Frame } = require('playwright/lib/server/chromium/crPage');3const { Page } = require('playwright/lib/server/chromium/crPage');4const { Frame } = require('playwright/lib/server/chromium/crPage');5const { Frame, Page } = require('playwright/lib/server/chromium/crPage');6const { Frame, Page } = require('playwright/lib/server/chromium/crPage');7const { Frame, Page } = require('playwright/lib/server/chromium/crPage');8const { Frame } = require('playwright/lib/server/chromium/crPage');9const { Page } = require('playwright/lib/server/chromium/crPage');10const { Frame } = require('playwright/lib/server/chromium/crPage');11const { Page } = require('playwright/lib/server/chromium/crPage');12const { Frame } = require('playwright/lib/server/chromium/crPage');13const { Page } = require('playwright/lib/server/chromium/crPage');14const { Frame, Page } = require('playwright/lib/server/chromium/crPage');15const { Frame, Page } = require('playwright/lib/server/chromium/crPage');16const { Frame } = require('playwright/lib/server/chromium/crPage');17const { Page } = require('playwright/lib/server/chromium/crPage');18const { Frame, Page } = require('playwright/lib/server/chromium/crPage');19const { Frame, Page } = require('playwright/lib/server/chromium/crPage');20const { Frame } = require('playwright/lib/server/chromium/crPage');21const { Page } = require('playwright/lib/server/chromium/crPage');22const { Frame, Page } = require('playwright/lib/server/chromium/crPage');23const { Frame, Page } = require('playwright/lib/server/chromium/crPage');24const { Frame } = require('playwright/lib/server/chromium/crPage');25const { Page } = require('playwright/lib/server/chromium/crPage');26const { Frame, Page } = require('playwright/lib/server/chromium/crPage');27const { Frame, Page } = require('playwright/lib/server/chromium/crPage');28const { Frame } = require('playwright/lib/server/chromium/crPage

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shouldMark } = require('playwright/lib/internal/trace/recorder');2const { Page } = require('playwright/lib/server/page');3const { Frame } = require('playwright/lib/server/frame');4const pageProto = Page.prototype;5const frameProto = Frame.prototype;6pageProto._addInitScript = function (source) {7 if (!shouldMark(this._page._browserContext._browser._options)) {8 return;9 }10 return this._page._addInitScript(source);11};12frameProto._addInitScript = function (source) {13 if (!shouldMark(this._page._browserContext._browser._options)) {14 return;15 }16 return this._frame._addInitScript(source);17};18pageProto._addInitScript = function (source) {19 if (!shouldMark(this._page._browserContext._browser._options)) {20 return;21 }22 return this._page._addInitScript(source);23};24frameProto._addInitScript = function (source) {25 if (!shouldMark(this._page._browserContext._browser._options)) {26 return;27 }28 return this._frame._addInitScript(source);29};30pageProto._addInitScript = function (source) {31 if (!shouldMark(this._page._browserContext._browser._options)) {32 return;33 }34 return this._page._addInitScript(source);35};36frameProto._addInitScript = function (source) {37 if (!shouldMark(this._page._browserContext._browser._options)) {38 return;39 }40 return this._frame._addInitScript(source);41};42pageProto._addInitScript = function (source) {43 if (!shouldMark(this._page._browserContext._browser._options)) {44 return;45 }46 return this._page._addInitScript(source);47};48frameProto._addInitScript = function (source) {49 if (!shouldMark(this._page._browserContext._browser._options)) {50 return;51 }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shouldMark } = require('playwright/lib/trace/recorder/recorderApp');2const { Page } = require('playwright/lib/server/page');3const page = new Page();4const action = {5};6const result = shouldMark(page, action);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shouldMark } = require('playwright/lib/server/trace/recorder');2const traceEvent = { name: 'Tracing.dataCollected', args: { name: 'EventName', cat: 'devtools.timeline' } };3console.log(shouldMark(traceEvent));4const { shouldMark } = require('playwright/lib/server/trace/recorder');5const traceEvent = { name: 'EventName', cat: 'devtools.timeline' };6console.log(shouldMark(traceEvent));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shouldMark } = require('@playwright/test/lib/test/runner');2const { expect } = require('@playwright/test');3const test = it('should mark the test as failed', async ({ page }) => {4 expect(await page.title()).toBe('Example');5});6shouldMark(test, 'failed', 'Test failed');7const { test } = require('./test');8test('should mark the test as failed', async ({ page }) => {9 expect(await page.title()).toBe('Example');10});11const { test } = require('./test');12test('should mark the test as failed', async ({ page }) => {13 expect(await page.title()).toBe('Example');14});15 at Object.<anonymous> (/path/to/test.js:11:5)16 at Object.<anonymous> (/path/to/test.js:11:5)17 at Object.<anonymous> (/path/to/test.js:11:5)18 at Object.<anonymous> (/path/to/test.js:11:5)19 at Object.<anonymous> (/path/to/test.js:11:5)20 at Object.<anonymous> (/path/to/test.js:11:5)21 at Object.<anonymous> (/path/to/test.js:11:5)22 at Object.<anonymous> (/path/to/test.js:11:5)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { shouldMark } = require('playwright/lib/internal/inspectorInstrumentation');2const { shouldMark } = require('playwright/lib/internal/inspectorInstrumentation');3const { shouldMark } = require('playwright/lib/internal/inspectorInstrumentation');4const { shouldMark } = require('playwright/lib/internal/inspectorInstrumentation');5const { shouldMark } = require('playwright/lib/internal/inspectorInstrumentation');6const { shouldMark } = require('playwright/lib/internal/inspector

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