Enhance pawn movement logic to allow attackers to get another turn when beating opponent pawns; refactor beatPawns method to return count of beaten pawns

This commit is contained in:
2026-01-30 21:44:39 +05:30
parent f7f8798f43
commit 99d24daff2
2 changed files with 13 additions and 8 deletions
+7 -3
View File
@@ -49,16 +49,20 @@ const RoomSchema = new mongoose.Schema({
RoomSchema.methods.beatPawns = function (position, attackingPawnColor) {
// Do not beat pawns on safe/colored positions
if (isSafePosition(position)) {
return;
return 0;
}
let beatenCount = 0;
const pawnsOnPosition = this.pawns.filter(pawn => pawn.position === position);
pawnsOnPosition.forEach(pawn => {
if (pawn.color !== attackingPawnColor) {
const index = this.getPawnIndex(pawn._id);
this.pawns[index].position = this.pawns[index].basePos;
if (index !== -1 && this.pawns[index].position !== this.pawns[index].basePos) {
this.pawns[index].position = this.pawns[index].basePos;
beatenCount++;
}
}
});
return beatenCount;
};
RoomSchema.methods.changeMovingPlayer = function () {