Skip to content

Commit

Permalink
fix(core): not considering multiple Oops! All 6s
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinfreund committed Mar 26, 2024
1 parent 37e6bee commit be2e6fa
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/lib/balatro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import case025 from './test-files/025.js'
import case026 from './test-files/026.js'
import case027 from './test-files/027.js'
import case028 from './test-files/028.js'
import case029 from './test-files/029.js'

export type TestCase = {
message: string
Expand Down Expand Up @@ -70,6 +71,7 @@ describe('calculateScore', () => {
case026('Pair, The Pillar'),
case027('Lucky Pair'),
case028('Lucky Flush, Bloodstone'),
case029('Lucky Flush, Bloodstone, 4x Oops! All 6s'),
])('$message', ({ initialState, expected }) => {
const score = calculateScore(getState(initialState))

Expand Down
14 changes: 12 additions & 2 deletions src/lib/balatro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,18 @@ function getScore (state: State, luck: Luck): Score {
break
}
case 'lucky': {
const hasOops = state.jokerSet.has('Oops! All 6s')
score.multiplier += luck === 'all' ? 20 : luck === 'none' ? 0 : (hasOops ? 8 : 4)
const denominator = 5
const oopses = state.jokers.filter(({ name }) => name === 'Oops! All 6s')
const minimumNumerator = Math.max(0, Math.min(oopses.length + 1, denominator))

let numerator = minimumNumerator
if (luck === 'all') {
numerator = denominator
} else if (luck === 'none' && minimumNumerator < denominator) {
numerator = 0
}

score.multiplier += 20 * numerator/denominator
log(score, '(+Mult from lucky enhancement)')
break
}
Expand Down
14 changes: 12 additions & 2 deletions src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,18 @@ export const JOKER_DEFINITIONS: Record<JokerName, JokerDefinition> = {
rarity: 'uncommon',
playedCardEffect ({ score, card, state, luck }) {
if (isSuit(card, 'Hearts')) {
const hasOops = state.jokerSet.has('Oops! All 6s')
score.multiplier *= luck === 'all' ? 2 : luck === 'none' ? 1 : 1 + (hasOops ? 2 : 1)/3
const denominator = 3
const oopses = state.jokers.filter(({ name }) => name === 'Oops! All 6s')
const minimumNumerator = Math.max(1, Math.min(oopses.length + 1, denominator))

let numerator = minimumNumerator
if (luck === 'all') {
numerator = denominator
} else if (luck === 'none' && minimumNumerator < denominator) {
numerator = 0
}

score.multiplier *= 1 + numerator/denominator
}
},
},
Expand Down
43 changes: 43 additions & 0 deletions src/lib/test-files/029.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { TestCase } from '#lib/balatro.test.js'

export default (message: string): TestCase => {
return {
message,
initialState: {
hands: 1,
playedCards: [
{ rank: 'King', suit: 'Hearts', enhancement: 'lucky' },
{ rank: 'King', suit: 'Hearts', enhancement: 'lucky' },
{ rank: 'Jack', suit: 'Hearts', enhancement: 'lucky' },
{ rank: 'Ace', suit: 'Hearts', enhancement: 'lucky' },
{ rank: '6', suit: 'Hearts', enhancement: 'lucky' },
],
jokers: [
{ name: 'Sock and Buskin' },
{ name: 'Dusk' },
{ name: 'Lusty Joker' },
{ name: 'Blueprint' },
{ name: 'Bloodstone' },
{ name: 'Oops! All 6s' },
{ name: 'Oops! All 6s' },
{ name: 'Oops! All 6s' },
{ name: 'Oops! All 6s' },
],
},
expected: {
hand: 'Flush',
scoringCards: [
{ rank: 'King', suit: 'Hearts', enhancement: 'lucky' },
{ rank: 'King', suit: 'Hearts', enhancement: 'lucky' },
{ rank: 'Jack', suit: 'Hearts', enhancement: 'lucky' },
{ rank: 'Ace', suit: 'Hearts', enhancement: 'lucky' },
{ rank: '6', suit: 'Hearts', enhancement: 'lucky' },
],
scores: [
{ score: 384131132448, formattedScore: '384,131,132,448', luck: 'none' },
{ score: 384131132448, formattedScore: '384,131,132,448', luck: 'average' },
{ score: 384131132448, formattedScore: '384,131,132,448', luck: 'all' },
],
},
}
}

0 comments on commit be2e6fa

Please sign in to comment.