Skip to content

Commit

Permalink
move sinad functions inside Game
Browse files Browse the repository at this point in the history
- refactor sinad test cases
- more isSubsetOf test cases
- cleanup comments
- better formatting
- BUILD ERROR. DO NOT MERGE.
  • Loading branch information
22Chaos committed Oct 28, 2024
1 parent 4e3eb81 commit af4781a
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 202 deletions.
45 changes: 42 additions & 3 deletions src/gameplay/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2306,13 +2306,14 @@ class Game extends Room {
const VH = this.voteHistory; //brevity

if(VH === undefined) {
return set; //return empty set.
return set; // empty set.
}

for (const player in VH) {
//TODO: write check to ensure player really is in this.PlayersInGame.
if (VH.hasOwnProperty(player)) {
if(VH[player].length < missionNum) { //in case mission hasn't happened yet.
if(VH[player].length < missionNum) {
//in case mission hasn't happened yet.
return set;
}

Expand All @@ -2325,9 +2326,47 @@ class Game extends Room {
}
}
return set;
};
}

updateMissionSizesSinad(): 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.
console.log(this.getPlayersOnMission(2)) ;
console.log(this.getPlayersOnMission(3)) ;
console.log(!isSubsetOf(this.getPlayersOnMission(2),this.getPlayersOnMission(3)));
if(!isSubsetOf(
this.getPlayersOnMission(2)
,this.getPlayersOnMission(3)
)) {
this.numPlayersOnMission[6 - MIN_PLAYERS] = [2,3,4,4,3];

this.sendText(
'The mission sizes of Mission 4 and Mission 5 have been swapped!'
, 'gameplay-text'
);
}
this.hasSinadRun = true;
}

hasSinadRun: boolean = false;

shouldSinadRun(): boolean {
return (
this.enableSinadMode
// this 6p check is also covered by room.ts hostTryStartGame()
&& this.playersInGame.length == 6
// && this.gameMode == GameMode.AVALON

// m1 m2 pass, m3 failed
&& this.missionHistory.length >= 3
&& this.missionHistory[0] === 'succeeded'
&& this.missionHistory[1] === 'succeeded'
&& this.missionHistory[2] === 'failed'
);
}
}


export default Game;

// Helpful functions
Expand Down
43 changes: 4 additions & 39 deletions src/gameplay/phases/common/votingMission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ class VotingMission implements IPhase {
this.thisRoom.playersInGame.length) %
this.thisRoom.playersInGame.length;

if(!this.hasSinadRun && this.shouldSinadRun()) {
this.updateMissionSizesSinad();
this.hasSinadRun = true;
if(!this.thisRoom.hasSinadRun && this.thisRoom.shouldSinadRun()) {
this.thisRoom.updateMissionSizesSinad();
this.thisRoom.hasSinadRun = true;
//not necessary since above func also sets it to true.
}

this.thisRoom.changePhase(Phase.PickingTeam);
Expand Down Expand Up @@ -278,42 +279,6 @@ class VotingMission implements IPhase {
getProhibitedIndexesToPick(indexOfPlayer: number): number[] {
return [];
}

updateMissionSizesSinad(): 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.
console.log(this.thisRoom.getPlayersOnMission(2)) ;
console.log(this.thisRoom.getPlayersOnMission(3)) ;
console.log(!isSubsetOf(this.thisRoom.getPlayersOnMission(2),this.thisRoom.getPlayersOnMission(3)));
if(!isSubsetOf(
this.thisRoom.getPlayersOnMission(2)
,this.thisRoom.getPlayersOnMission(3)
)) {
this.thisRoom.numPlayersOnMission[6 - MIN_PLAYERS] = [2,3,4,4,3];

this.thisRoom.sendText(
'The mission sizes of Mission 4 and Mission 5 have been swapped!'
, 'gameplay-text'
);
}
}

hasSinadRun: boolean = false;

shouldSinadRun(): boolean {
return (
this.thisRoom.enableSinadMode
// this 6p check is also covered by room.ts hostTryStartGame()
&& this.thisRoom.playersInGame.length == 6
&& this.thisRoom.gameMode == GameMode.AVALON

// m1 m2 pass, m3 failed
&& this.thisRoom.missionHistory.length >= 3
&& this.thisRoom.missionHistory[0] === 'succeeded'
&& this.thisRoom.missionHistory[1] === 'succeeded'
&& this.thisRoom.missionHistory[2] === 'failed'
);
}
}

export default VotingMission;
Loading

0 comments on commit af4781a

Please sign in to comment.