Skip to content

Commit

Permalink
Updated unit tests for changes to objectives and adjusted scoreing fo…
Browse files Browse the repository at this point in the history
…r safetyBonus, DefensiveBonus, and CleanBonus to reflect the fact that the safeties are all in the same category now.
  • Loading branch information
strinsberg committed Jun 26, 2020
1 parent 55e70eb commit 117c886
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 38 deletions.
43 changes: 27 additions & 16 deletions src/classes/game/Objectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
const GROUP_BONUS = 5
const REPEAT_BONUS = 3
const VAR_BONUS = 2
const SAFETY_BONUS = 10
const SAFETY_BONUS = 3

// Objective Bonuses
const DEFENSIVE_BONUS = 10
const ANTIVIRUS_BONUS = 10
const FIREWALL_BONUS = 5
const CLEAN_BONUS = 10
const COMPLETE_BONUS = 10
const COMPLETE_BONUS = 5


/**
Expand Down Expand Up @@ -55,7 +56,7 @@ export default class Objectives {
*/
getSafetyBonus () {
let safetyCards = this.cardsPlayed.filter((c) => {
return c.type === "ANTIVIRUS" || c.type === "FIREWALL"
return c.type === "ANTIVIRUS" || c.type === "FIREWALL" || c.type === "SCAN"
})
return SAFETY_BONUS * safetyCards.length
}
Expand All @@ -67,50 +68,60 @@ export default class Objectives {
*/
getDefensiveBonus () {
if (this.player.helpedBy("ANTIVIRUS")) {
return DEFENSIVE_BONUS
return ANTIVIRUS_BONUS
} else if (this.player.hasPositive('FIREWALL')) {
return FIREWALL_BONUS
}
return 0


}

/**
* Return the the clean bonus the player has.
* Clean bonus is given if the player has no Virus.
* Is 0 if the player does not meet the requirements for the bonus.
*/
getCleanBonus () {
//return this.player.hurtBy("VIRUS") ? 0 : CLEAN_BONUS
getCleanBonus (playerHand, playerStacks) {
if(this.player.hurtBy('RANSOM')|| this.player.hurtBy('SPYWARE')){
return 0
}
// check for viruses
for (let stack of playerStacks) {
if (stack.getTop().type === 'VIRUS') {
return 0
}
}
// check for trojans
for (let card of playerHand.cards) {
if (card.isMimic) {
return 0
}
}
return CLEAN_BONUS
}

/**
* Return the bonus given if a player has at least one complete stack.
* Return a bonus for each stack that a player has with 2 repeats (Rx has to
* have variable on it).
* Is 0 if the player has no complete stacks.
* @param playerStacks An array of the player's stacks
*/
getCompleteBonus (playerStacks) {
if (playerStacks.filter(s => s.isComplete()).length > 0) {
return COMPLETE_BONUS
}
return 0
let complete = playerStacks.filter(s => s.isComplete())
return complete.length * COMPLETE_BONUS
}

/**
* Wraps all the bonuses up into an object for convenience.
* Requires the stacks of the player for complete program bonus.
* @param stacks An array of the player's stacks
*/
getBonuses (stacks) {
getBonuses (hand, stacks) {
let bonuses = {}
bonuses.group = this.player.objectives.getGroupBonus()
bonuses.repeat = this.player.objectives.getRepeatBonus()
bonuses.variable = this.player.objectives.getVariableBonus()
bonuses.safety = this.player.objectives.getSafetyBonus()
bonuses.clean = this.player.objectives.getCleanBonus()
bonuses.clean = this.player.objectives.getCleanBonus(hand, stacks)
bonuses.defensive = this.player.objectives.getDefensiveBonus()
bonuses.complete = this.getCompleteBonus(stacks)

Expand Down
8 changes: 5 additions & 3 deletions src/components/modals/WinnerModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<tr> <th>Safety Bonus</th>
<td v-for="player in players" :key="player.id">{{ playerScore(player.id).bonuses.safety }}</td>
</tr>
<tr> <th>Complete Program</th>
<tr> <th>Nested Loops</th>
<td v-for="player in players" :key="player.id">{{ playerScore(player.id).bonuses.complete }}</td>
</tr>
<tr> <th>Defensive Programmer (AntiVirus)</th>
Expand Down Expand Up @@ -88,7 +88,8 @@ export default {
computed: {
...mapState([
'players',
'stacks'
'stacks',
'hands'
]),
// does not deal with ties
getWinner () {
Expand All @@ -111,7 +112,8 @@ export default {
addBonuses (player) {
let scores = this.playerScore(player.id)
let stacks = this.stacks.filter(s => s.playerId === player.id)
scores.bonuses = player.objectives.getBonuses(stacks)
let hand = this.hands.find(h => h.playerId === player.id)
scores.bonuses = player.objectives.getBonuses(hand, stacks)
},
finalScore (player) {
let score = this.playerScore(player.id)
Expand Down
68 changes: 49 additions & 19 deletions tests/unit/Objectives.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import Player from '@/classes/game/Player'
let group = {type: 'GROUP'}
let repeat = {type: 'REPEAT'}
let variable = {type: 'VARIABLE'}
let virus = {type: 'VIRUS'}
let antivirus = {type: 'ANTIVIRUS'}
let firewall = {type: 'FIREWALL'}
let scan = {type: 'SCAN'}
let complete = {isComplete: () => {return true}}
let notComplete = {isComplete: () => {return false}}
function mockValue (value) { return jest.fn(() => { return value }) }


describe('Objectives.js', () => {
test('all objectives when there are no cards played', () => {
// Might be better to mock out the player in the future
let player = new Player(0, 'steve', false)
let stacks = []
let bonuses = player.objectives.getBonuses(stacks)
let bonuses = player.objectives.getBonuses({cards: []},[])
expect(bonuses.group).toEqual(0)
expect(bonuses.repeat).toEqual(0)
expect(bonuses.variable).toEqual(0)
Expand All @@ -36,40 +38,68 @@ describe('Objectives.js', () => {
objectives.cardsPlayed.push(variable)
objectives.cardsPlayed.push(repeat)
objectives.cardsPlayed.push(repeat)
expect(objectives.getRepeatBonus()).toEqual(4)
expect(objectives.getRepeatBonus()).toEqual(6)
})
test('played variable cards', () => {
let objectives = new Objectives({})
objectives.cardsPlayed.push(variable)
objectives.cardsPlayed.push(repeat)
objectives.cardsPlayed.push(variable)
expect(objectives.getVariableBonus()).toEqual(6)
expect(objectives.getVariableBonus()).toEqual(4)
})
test('played safety cards', () => {
let objectives = new Objectives({})
objectives.cardsPlayed.push(antivirus)
objectives.cardsPlayed.push(firewall)
objectives.cardsPlayed.push(scan)
objectives.cardsPlayed.push(variable)
expect(objectives.getSafetyBonus()).toEqual(20)
expect(objectives.getSafetyBonus()).toEqual(9)
})
test('player has all safety effects', () => {
let player = new Player(1, 'steve', false)
player.addPositive("ANTIVIRUS")
player.addPositive("FIREWALL")
expect(player.objectives.getDefensiveBonus()).toEqual(10)
})
test('player has no virus', () => {
let player = new Player(1, 'steve', false)
expect(player.objectives.getCleanBonus()).toEqual(10)

describe('defensiveBonus', () => {
test('player has antivirus', () => {
let player = new Player(1, 'steve', false)
player.addPositive("ANTIVIRUS")
expect(player.objectives.getDefensiveBonus()).toEqual(10)
})
test('player has firewall', () => {
let player = new Player(1, 'steve', false)
player.addPositive("FIREWALL")
expect(player.objectives.getDefensiveBonus()).toEqual(5)
})
test('player has scan', () => {
let player = new Player(1, 'steve', false)
player.addPositive("SCAN")
expect(player.objectives.getDefensiveBonus()).toEqual(0)
})
})
test('player has virus', () => {
let player = new Player(1, 'steve', false)
player.addNegative('VIRUS')
expect(player.objectives.getCleanBonus()).toEqual(0)

describe('cleanBonus', () => {
test('player has no malware', () => {
let player = new Player(1, 'steve', false)
let stack = {getTop: mockValue(repeat)}
expect(player.objectives.getCleanBonus({cards: [{isMimic: false}]}, [stack])).toEqual(10)
})
test('player has virus', () => {
let player = new Player(1, 'steve', false)
let stack = {getTop: mockValue(virus)}
expect(player.objectives.getCleanBonus({cards: []}, [stack])).toEqual(0)
})
test('player has trojan', () => {
let player = new Player(1, 'steve', false)
expect(player.objectives.getCleanBonus({cards: [{isMimic: true}]}, [])).toEqual(0)
})
test('player has negative effect', () => {
let player = new Player(1, 'steve', false)
player.addNegative('RANSOM', 0)
expect(player.objectives.getCleanBonus({cards: []}, [])).toEqual(0)
})

})

test('has a complete stack', () => {
let objectives = new Objectives({})
let stacks = [complete, notComplete]
let stacks = [complete, complete, notComplete]
expect(objectives.getCompleteBonus(stacks)).toEqual(10)
})
test('does not have a complete stack', () => {
Expand Down

0 comments on commit 117c886

Please sign in to comment.