Skip to content

Commit

Permalink
test rerack
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Oct 22, 2023
1 parent dc7c8c1 commit 5820e43
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/rules/fourteenone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import { expect } from "chai"
import { Container } from "../../src/container/container"
import { GameEvent } from "../../src/events/gameevent"
import { initDom } from "../view/dom"
import { PocketGeometry } from "../../src/view/pocketgeometry"
import { R } from "../../src/model/physics/constants"
import { Vector3 } from "three"
import { State } from "../../src/model/ball"
import { Aim } from "../../src/controller/aim"
import { BeginEvent } from "../../src/events/beginevent"
import { PlaceBall } from "../../src/controller/placeball"
import { Input } from "../../src/events/input"
import { PlayShot } from "../../src/controller/playshot"
import { WatchEvent } from "../../src/events/watchevent"

initDom()

Expand All @@ -22,4 +32,51 @@ describe("FourteenOne", () => {
expect(container.table.balls).to.be.length(4)
done()
})

function bringToAimMode() {
container.eventQueue.push(new BeginEvent())
container.processEvents()
expect(container.controller).to.be.an.instanceof(PlaceBall)
container.inputQueue.push(new Input(0.1, "SpaceUp"))
container.processEvents()
expect(container.controller).to.be.an.instanceof(Aim)
container.advance(1)
container.processEvents()
}

const edge =
PocketGeometry.pockets.pocketS.pocket.pos.y +
PocketGeometry.middleRadius +
0.01 * R

it("Pot penultimate ball, causing rerack", (done) => {
bringToAimMode()
expect(container.controller).to.be.an.instanceof(Aim)

const balls = container.table.balls
for (let i = 3; i < balls.length; i++) {
balls[i].pos.copy(PocketGeometry.pockets.pocketS.pocket.pos)
balls[i].state = State.InPocket
}
balls[0].pos.copy(new Vector3(0, edge + R * 2, 0))
balls[1].pos.copy(new Vector3(0, edge, 0))

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

container.table.cue.aim.angle = -Math.PI / 4
container.table.cue.aim.power = 0.1
container.table.cue.aim.pos.copy(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)

const watchEvent = broadcastEvents[3] as WatchEvent
expect(watchEvent.json.rerack).to.be.true

expect(container.recoder.shots[1].type).to.be.equal("RERACK")
done()
})
})

0 comments on commit 5820e43

Please sign in to comment.