Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion balatro-sim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,8 @@ class Hand {
}

if(lines[lines.length - 1].length >= (this.FourFingers ? 4 : 5)) {
straight = lines[lines.length - 1];
const straightRanks = new Set(lines[lines.length - 1].map(card => card[RANK]));
straight = sortedCards.filter(card => straightRanks.has(card[RANK]));
}
}

Expand Down
3 changes: 2 additions & 1 deletion breakdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,8 @@ class Hand {
}

if(lines[lines.length - 1].length >= (this.FourFingers ? 4 : 5)) {
straight = lines[lines.length - 1];
const straightRanks = new Set(lines[lines.length - 1].map(card => card[RANK]));
straight = sortedCards.filter(card => straightRanks.has(card[RANK]));
}
}

Expand Down
39 changes: 39 additions & 0 deletions tests/four-fingers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"use strict";

const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const test = require("node:test");
const vm = require("node:vm");

function loadHand(sourceFile) {
const context = vm.createContext({});
const source = fs.readFileSync(path.join(__dirname, "..", sourceFile), "utf8");
vm.runInContext(source, context, { filename: sourceFile });
return vm.runInContext("Hand", context);
}

function card(rank, suit) {
return [rank, suit, 0, 0, 0, 0, false, 0, 0];
}

for(const sourceFile of ["balatro-sim.js", "breakdown.js"]) {
test(`${sourceFile} scores duplicate ranks in a Four Fingers straight`, () => {
const Hand = loadHand(sourceFile);
const cards = [
card(0, 0),
card(1, 1),
card(1, 2),
card(2, 3),
card(3, 0)
];
const hand = new Hand({ cards });
hand.FourFingers = true;

const [handType, involvedCards] = hand.getTypeOfHand();
const involvedRanks = Array.from(involvedCards, involvedCard => involvedCard[0]).sort((a, b) => a - b);

assert.equal(handType, 7);
assert.deepEqual(involvedRanks, [0, 1, 1, 2, 3]);
});
}