Skip to content

Commit

Permalink
rerack recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Oct 22, 2023
1 parent 9dd06eb commit 601f9dd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/diagram.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/utils/rack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Rack {
}

static cueBall(pos) {
return new Ball(pos, 0xfaebd7)
return new Ball(Rack.jitter(pos), 0xfaebd7)
}

static diamond() {
Expand Down Expand Up @@ -114,7 +114,7 @@ export class Rack {
.filter((b) => b !== table.cueball)
.filter((b) => b !== key)
.forEach((b) => {
b.pos.copy(tp.shift()!)
b.pos.copy(Rack.jitter(tp.shift()!))
b.state = State.Stationary
})
if (table.overlapsAny(key.pos, key)) {
Expand Down
40 changes: 37 additions & 3 deletions test/rules/fourteenone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ import { RerackEvent } from "../../src/events/rerackevent"

initDom()

const jestConsole = console

beforeEach(() => {
global.console = require("console")
})

afterEach(() => {
global.console = jestConsole
})

describe("FourteenOne", () => {
let container: Container
let broadcastEvents: GameEvent[]
Expand Down Expand Up @@ -61,15 +71,14 @@ describe("FourteenOne", () => {
}

function playShotWaitForOutcome() {
container.table.cue.aim.angle = -Math.PI / 4
container.table.cue.aim.power = 0.1
container.table.cue.aim.angle = -Math.PI / 2
container.table.cue.aim.power = 1
container.table.cue.aim.pos.copy(container.table.balls[0].pos)
container.inputQueue.push(new Input(0.1, "SpaceUp"))
container.processEvents()
expect(container.controller).to.be.an.instanceof(PlayShot)
container.advance(1)
container.processEvents()
expect(container.controller).to.be.an.instanceof(Aim)
}

it("Pot penultimate ball, causing rerack", (done) => {
Expand All @@ -80,6 +89,8 @@ describe("FourteenOne", () => {
expect(container.table.balls.filter((b) => b.onTable())).to.be.length(3)

playShotWaitForOutcome()
expect(container.controller).to.be.an.instanceof(Aim)

const watchEvent = broadcastEvents[3] as WatchEvent
expect(watchEvent.json.rerack).to.be.true
expect(container.recoder.shots[1].type).to.be.equal("RERACK")
Expand All @@ -89,7 +100,30 @@ describe("FourteenOne", () => {
rerack.applyToController(container.controller)
const after = container.table.shortSerialise()
expect(before).to.be.deep.equal(after)
done()
})

it("play shot after rerack, check recording", (done) => {
bringToAimMode()
expect(container.controller).to.be.an.instanceof(Aim)

setupTableWithTwoBallsRemaining()
expect(container.table.balls.filter((b) => b.onTable())).to.be.length(3)

playShotWaitForOutcome()
expect(container.controller).to.be.an.instanceof(Aim)

const watchEvent = broadcastEvents[3] as WatchEvent
expect(watchEvent.json.rerack).to.be.true
expect(container.recoder.shots[1].type).to.be.equal("RERACK")

// play second hit (cueball into pocket)
container.advance(1)
container.processEvents()
playShotWaitForOutcome()
container.advance(1)
container.processEvents()
expect(container.controller).to.be.an.instanceof(PlaceBall)
done()
})
})

0 comments on commit 601f9dd

Please sign in to comment.