// Two players changing chairs. const test = require("node:test"); const assert = require("node:assert"); const { Betting, HoldemState, makeTable, chipsOnTable } = require("./load"); test("the whole seat moves", () => { const state = makeTable({ seatCount: 6, seated: [0, 1, 2], stack: 100 }); state.seats[0].name = "Ann"; state.seats[0].cards = ["AS", "KD"]; state.seats[0].stack = 175; state.seats[4].name = ""; HoldemState.swapSeats(state, 0, 4); assert.equal(state.seats[4].name, "Ann"); assert.deepEqual(state.seats[4].cards, ["AS", "KD"]); assert.equal(state.seats[4].stack, 175); assert.equal(state.seats[0].name, ""); }); test("what they have in the pot goes with them", () => { const state = makeTable({ seatCount: 6, seated: [0, 1, 2], stack: 100 }); Betting.beginHand(state); const posted = state.seats.map(p => p.committed); const before = chipsOnTable(state); HoldemState.swapSeats(state, 1, 4); assert.equal(state.seats[4].committed, posted[1]); assert.equal(state.seats[1].committed, posted[4]); assert.equal(chipsOnTable(state), before, "a swap never creates or destroys a chip"); }); test("the button stays on the chair, not on the player", () => { // A card room moves the button around the table, not around the people. Somebody // who sits down in the big blind's chair is the big blind. const state = makeTable({ seatCount: 6, seated: [0, 1, 2], stack: 100, dealerSeatIndex: 0 }); state.seats[0].name = "Ann"; HoldemState.swapSeats(state, 0, 2); assert.equal(state.dealerSeatIndex, 0); assert.notEqual(state.seats[0].name, "Ann"); }); test("the blinds follow the chairs too", () => { const state = makeTable({ seatCount: 6, seated: [0, 1, 2, 3], stack: 100, dealerSeatIndex: 0 }); Betting.beginHand(state); const before = HoldemState.getBlindSeats(state); HoldemState.swapSeats(state, before.sbIndex, before.bbIndex); const after = HoldemState.getBlindSeats(state); assert.equal(after.sbIndex, before.sbIndex); assert.equal(after.bbIndex, before.bbIndex); }); test("swapping a seat with itself does nothing and says so", () => { const state = makeTable({ seatCount: 6, seated: [0, 1], stack: 100 }); const before = JSON.stringify(state); assert.equal(HoldemState.swapSeats(state, 1, 1), false); assert.equal(JSON.stringify(state), before); }); test("a chair that isn't there is refused rather than swallowed", () => { const state = makeTable({ seatCount: 6, seated: [0, 1], stack: 100 }); const before = JSON.stringify(state); assert.equal(HoldemState.swapSeats(state, 0, 99), false); assert.equal(HoldemState.swapSeats(state, -1, 0), false); assert.equal(JSON.stringify(state), before); }); test("swapping twice puts everything back", () => { const state = makeTable({ seatCount: 6, seated: [0, 1, 2, 3], stack: 100 }); Betting.beginHand(state); const before = JSON.stringify(state); HoldemState.swapSeats(state, 1, 3); HoldemState.swapSeats(state, 1, 3); assert.equal(JSON.stringify(state), before); }); test("moving into an empty chair leaves an empty chair behind", () => { const state = makeTable({ seatCount: 6, seated: [0, 1], stack: 100 }); state.seats[1].name = "Ben"; HoldemState.swapSeats(state, 1, 5); assert.equal(state.seats[5].name, "Ben"); assert.equal(state.seats[5].inHand, true); assert.equal(state.seats[1].inHand, false); });