Skip to content

Commit d22be13

Browse files
fix(2022-day-02): record correct score when intending to lose against an opponent playing rock
1 parent 761c31d commit d22be13

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

2022/day-02/rochambeau.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ const strategizeRound = (opponent, outcome) => {
4747
const offset = strategyCodes.indexOf(outcome) - 1
4848
let target = opponentCodes.indexOf(opponent) + offset
4949
if (target >= opponentCodes.length) { target = 0 }
50+
if (target < 0) { target = opponentCodes.length - 1}
5051
return opponentCodes[target]
5152
}
52-
console.debug(scoreShape(findPlay(opponent, outcome)), scoreOutcome)
5353
return scoreShape(findPlay(opponent, outcome)) + scoreOutcome
5454
}
5555

2022/day-02/rochambeau.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const { expect } = require('chai')
33
const { scoreMatch, scoreRound, strategizeMatch, strategizeRound } = require('./rochambeau')
44

5-
describe.only('--- Day 2: Rock Paper Scissors ---', () => {
5+
describe('--- Day 2: Rock Paper Scissors ---', () => {
66
describe('Part 1', () => {
77
describe('scoreRound', () => {
88
it('calculates the score of a round based on what the opponent played and what you played', () => {
@@ -32,6 +32,8 @@ describe.only('--- Day 2: Rock Paper Scissors ---', () => {
3232
expect(strategizeRound('A', 'Y')).to.equal(4)
3333
expect(strategizeRound('B', 'X')).to.equal(1)
3434
expect(strategizeRound('C', 'Z')).to.equal(7)
35+
// data from input
36+
expect(scoreRound('A', 'X')).to.equal(3) // Opponent played Rock and self should lose
3537
})
3638
})
3739
describe('strategizeMatch', () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy