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:
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user