Skip to content

Commit

Permalink
Create socket
Browse files Browse the repository at this point in the history
  • Loading branch information
FPT-NMTung committed Dec 1, 2024
1 parent 7119be5 commit 477ad17
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions controllers/gomokuSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ function getUserInfoByToken (token) {
}

const checkWinGomoku = (type, steps, lastMove) => {
console.log(steps)

let arrSource = []
let currentPlayer = lastMove.player

Expand Down Expand Up @@ -390,6 +388,35 @@ const checkWinGomoku = (type, steps, lastMove) => {
return fnCheckWinType(count)
}

function fnCheckWinCrossOr () {
let count = 0
let index = 0
while (fnGetLocation(lastMove.x + index, lastMove.y - index)) {
const value = fnGetLocation(lastMove.x + index, lastMove.y - index)

if (value === currentPlayer) {
count++;
index++;
} else {
break;
}
}

index = 1
while (fnGetLocation(lastMove.x - index, lastMove.y + index)) {
const value = fnGetLocation(lastMove.x - index, lastMove.y + index)

if (value === currentPlayer) {
count++;
index++;
} else {
break;
}
}

return fnCheckWinType(count)
}

function fnCheckWinType (count) {
if (type === 'TYPE_1' && count === 5) {
return true
Expand Down Expand Up @@ -423,6 +450,12 @@ const checkWinGomoku = (type, steps, lastMove) => {
return true
}

isWin = fnCheckWinCrossOr()
if (isWin) {
console.log(`${currentPlayer} win!!!`)
return true
}

return false
}

Expand Down

0 comments on commit 477ad17

Please sign in to comment.