Skip to content

Commit

Permalink
Added Sinad mode
Browse files Browse the repository at this point in the history
  • Loading branch information
22Chaos committed Oct 21, 2024
1 parent fc510d4 commit 76bcd18
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
23 changes: 11 additions & 12 deletions src/gameplay/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ const ALLIANCES = [
Alliance.Spy,
];

export const NUM_PLAYERS_ON_MISSION = [
[2, 3, 2, 3, 3],
[2, 3, 4, 3, 4],
[2, 3, 3, 4, 4],
[3, 4, 4, 5, 5],
[3, 4, 4, 5, 5],
[3, 4, 4, 5, 5],
];

export class GameConfig {
roomConfig: RoomConfig;
Expand Down Expand Up @@ -97,6 +89,15 @@ class Game extends Room {
pickNum = 0;
roomCreationType: RoomCreationType;

const NUM_PLAYERS_ON_MISSION = [
[2, 3, 2, 3, 3],
[2, 3, 4, 3, 4],
[2, 3, 3, 4, 4],
[3, 4, 4, 5, 5],
[3, 4, 4, 5, 5],
[3, 4, 4, 5, 5],
];

// Game misc variables
winner: Alliance = '';
requireSave = false;
Expand Down Expand Up @@ -138,7 +139,6 @@ class Game extends Room {
this.enableSinadMode = gameConfig.enableSinadMode;
this.roomCreationType = gameConfig.roomCreationType;
this.getTimeFunc = gameConfig.getTimeFunc;
console.log("Inside Game's constructor. the value of enableSinadMode is:", this.enableSinadMode);
this.phaseBeforePause = '';
this.playerUsernamesInGame = [];

Expand Down Expand Up @@ -570,7 +570,6 @@ class Game extends Room {
if (this.disableVoteHistory) {
this.sendText('The game has vote history disabled.', 'gameplay-text');
}
console.log('Yo. Btw, the value of enableSinadMode is:', this.enableSinadMode);
if (this.enableSinadMode) {
this.sendText('The game has Sinad Mode enabled.', 'gameplay-text');
}
Expand Down Expand Up @@ -1081,7 +1080,7 @@ class Game extends Room {
data[i].proposedTeam = this.anonymizer.anonMany(this.proposedTeam);

data[i].numPlayersOnMission =
NUM_PLAYERS_ON_MISSION[playerRoles.length - MIN_PLAYERS]; // - 5
this.NUM_PLAYERS_ON_MISSION[playerRoles.length - MIN_PLAYERS]; // - 5
data[i].numSelectTargets = this.getClientNumOfTargets(i);

data[i].votes = this.publicVotes;
Expand Down Expand Up @@ -1166,7 +1165,7 @@ class Game extends Room {
data.proposedTeam = this.anonymizer.anonMany(this.proposedTeam);

data.numPlayersOnMission =
NUM_PLAYERS_ON_MISSION[playerRoles.length - MIN_PLAYERS]; // - 5
this.NUM_PLAYERS_ON_MISSION[playerRoles.length - MIN_PLAYERS]; // - 5
data.numSelectTargets = this.getClientNumOfTargets();

data.votes = this.publicVotes;
Expand Down
9 changes: 5 additions & 4 deletions src/gameplay/phases/common/pickingTeam.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import usernamesIndexes from '../../../myFunctions/usernamesIndexes';
import { ButtonSettings, IPhase, Phase } from '../types';
import { MIN_PLAYERS, NUM_PLAYERS_ON_MISSION } from '../../game';
import { MIN_PLAYERS } from '../../game';
import { SocketUser } from '../../../sockets/types';

class PickingTeam implements IPhase {
Expand Down Expand Up @@ -52,7 +52,7 @@ class PickingTeam implements IPhase {
this.thisRoom.publicVotes = [];

const num =
NUM_PLAYERS_ON_MISSION[
this.thisRoom.NUM_PLAYERS_ON_MISSION[
this.thisRoom.playersInGame.length - MIN_PLAYERS
][this.thisRoom.missionNum - 1];
// console.log("Num player for this.thisRoom mission : " + num);
Expand Down Expand Up @@ -140,7 +140,7 @@ class PickingTeam implements IPhase {

numOfTargets(indexOfPlayer: number): number {
const num =
NUM_PLAYERS_ON_MISSION[this.thisRoom.playersInGame.length - MIN_PLAYERS][
this.thisRoom.NUM_PLAYERS_ON_MISSION[this.thisRoom.playersInGame.length - MIN_PLAYERS][
this.thisRoom.missionNum - 1
];

Expand All @@ -158,7 +158,7 @@ class PickingTeam implements IPhase {
indexOfPlayer === this.thisRoom.teamLeader
) {
const num =
NUM_PLAYERS_ON_MISSION[
this.thisRoom.NUM_PLAYERS_ON_MISSION[
this.thisRoom.playersInGame.length - MIN_PLAYERS
][this.thisRoom.missionNum - 1];

Expand All @@ -178,6 +178,7 @@ class PickingTeam implements IPhase {
getProhibitedIndexesToPick(indexOfPlayer: number): number[] {
return [];
}

}

export default PickingTeam;
60 changes: 60 additions & 0 deletions src/gameplay/phases/common/votingMission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import usernamesIndexes from '../../../myFunctions/usernamesIndexes';
import { ButtonSettings, IPhase, Phase } from '../types';
import { Alliance } from '../../types';
import { SocketUser } from '../../../sockets/types';
import { GameMode } from '../../gameModes';
import { MIN_PLAYERS } from '../../game';

class VotingMission implements IPhase {
static phase = Phase.VotingMission;
Expand Down Expand Up @@ -153,6 +155,9 @@ class VotingMission implements IPhase {
1 +
this.thisRoom.playersInGame.length) %
this.thisRoom.playersInGame.length;


this.updateMissionSizesForSinad();
this.thisRoom.changePhase(Phase.PickingTeam);
}
this.thisRoom.requireSave = true;
Expand Down Expand Up @@ -270,6 +275,61 @@ class VotingMission implements IPhase {
getProhibitedIndexesToPick(indexOfPlayer: number): number[] {
return [];
}

updateMissionSizesForSinad(): void {
// in 6p avalon, if m1 and m2 both succeed and m3 is a dani's pick (i.e. m3!=m2+1)
// then the sizes of m4 and m5 are swapped, requiring 4 ppl and 3 ppl respectively.

if(!this.thisRoom.enableSinadMode)
{
return;
}
if(this.thisRoom.playersInGame.length !== 6 && this.thisRoom.gameMode !== GameMode.AVALON)
{
return; //not tested for other gamemodes.
}

const VH = this.thisRoom.voteHistory; //for brevity

const setOfPlayersOnM2 = new Set<string>();
const setOfPlayersOnM3 = new Set<string>();


if(
//m1 m2 pass, m3 failed, and we're at m4.1
this.thisRoom.missionHistory &&
this.thisRoom.missionHistory.length === 3 &&
this.thisRoom.missionHistory[0] === 'succeeded' &&
this.thisRoom.missionHistory[1] === 'succeeded' &&
this.thisRoom.missionHistory[2] === 'failed' &&
this.thisRoom.missionNum === 4 &&
this.thisRoom.pickNum === 1
) {
for (const player in VH) {
if (VH.hasOwnProperty(player)) {

const playerVH = VH[player];
const playerM2 = playerVH[1][playerVH[1].length -1];
const playerM3 = playerVH[2][playerVH[2].length -1];

if (typeof playerM2 === 'string' && playerM2.includes("VHpicked")) {
setOfPlayersOnM2.add(player);
}
if (typeof playerM3 === 'string' && playerM3.includes("VHpicked")) {
setOfPlayersOnM3.add(player);
}
}
}

let isM2ASubsetOfM3: boolean = [...setOfPlayersOnM2].every(player => setOfPlayersOnM3.has(player));

if(!isM2ASubsetOfM3) {
this.thisRoom.NUM_PLAYERS_ON_MISSION[6-MIN_PLAYERS] = [2,3,4,4,3];
let announcingSinadMode: string = "The mission sizes of Mission 4 and Mission 5 have been swapped!";
this.thisRoom.sendText(announcingSinadMode,'gameplay-text');
}
}
}
}

export default VotingMission;
4 changes: 2 additions & 2 deletions src/gameplay/tests/game.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Game, { GameConfig, NUM_PLAYERS_ON_MISSION } from '../game';
import Game, { GameConfig } from '../game';
import { RoomConfig } from '../room';
import { GameMode } from '../gameModes';
import { ReadyPrompt } from '../../sockets/readyPrompt';
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('Game Engine', () => {
// Picking team
expect(game.phase).toEqual(Phase.PickingTeam);

const numOfPlayers = NUM_PLAYERS_ON_MISSION[1][game.missionNum - 1];
const numOfPlayers = game.NUM_PLAYERS_ON_MISSION[1][game.missionNum - 1];
const usernamesToPick = [];

// Need to add a spy to fail if not success
Expand Down

0 comments on commit 76bcd18

Please sign in to comment.