Skip to content

Commit 70a5e68

Browse files
committed
condition delivering to 5th floor
1 parent 3be8ea0 commit 70a5e68

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

src/services/WindowStates.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export default class WindowStates {
5757
public getBestMatchingDeliveryWindow(flowers: Flower[]) : WindowState|undefined {
5858
// get all defined windows that are not fully delivered yet, already ordered in bot's priority
5959
const windows = this._windowStates.value.filter(w => w.deliveries.length < 4)
60+
// do not deliver to the 5th Floor unless match at least two flowers
61+
.filter(w => w.floor < 5 || flowers.length >= 2)
6062
.toSorted((a, b) => {
6163
const matchA = getFlowerMatchCount(a.flowers, flowers)
6264
const matchB = getFlowerMatchCount(b.flowers, flowers)

tests/unit/services/BotActions.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,9 @@ describe('services/BotActions', () => {
755755
const botActions = new BotActions(navigationState)
756756

757757
const action = botActions.actions[0]
758-
// floor 1 has RED, garden has YELLOW → 0 matches but floor 5 might be better
759-
// floor 5 has all 5 flowers, garden has YELLOW → 1 match → 2 VP
760-
// Actually the best match is floor 5 (1 match vs floor 1 with 0 match)
761-
expect(action.vp).to.eq(2)
758+
// floor 1 has RED, garden has YELLOW → 0 matches
759+
// floor 5 is excluded because only 1 flower available (needs >= 2)
760+
expect(action.vp).to.eq(0)
762761
})
763762

764763
it('XP only includes flowers present in current season', () => {

tests/unit/services/WindowStates.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,55 @@ describe('services/WindowStates', () => {
249249
expect(result?.windowSelection).to.eq(WindowSelection.LEFT)
250250
})
251251

252+
it('getBestMatchingDeliveryWindow-skips5thFloorWithSingleFlower', () => {
253+
const dw = WindowStates.fromPersistence([
254+
{ floor: 5, windowSelection: WindowSelection.LEFT, flowers: [Flower.ORANGE, Flower.BLUE, Flower.YELLOW, Flower.PURPLE, Flower.RED], deliveries: [] },
255+
{ floor: 2, windowSelection: WindowSelection.LEFT, flowers: [Flower.RED, Flower.BLUE], deliveries: [] }
256+
])
257+
258+
// only 1 flower → 5th floor should be skipped, picks floor 2
259+
const result = dw.getBestMatchingDeliveryWindow([Flower.RED])
260+
261+
expect(result?.floor).to.eq(2)
262+
expect(result?.windowSelection).to.eq(WindowSelection.LEFT)
263+
})
264+
265+
it('getBestMatchingDeliveryWindow-allows5thFloorWithTwoFlowers', () => {
266+
const dw = WindowStates.fromPersistence([
267+
{ floor: 5, windowSelection: WindowSelection.LEFT, flowers: [Flower.ORANGE, Flower.BLUE, Flower.YELLOW, Flower.PURPLE, Flower.RED], deliveries: [] },
268+
{ floor: 2, windowSelection: WindowSelection.LEFT, flowers: [Flower.RED, Flower.BLUE], deliveries: [] }
269+
])
270+
271+
// 2 flowers → 5th floor is allowed, both match 2, floor 2 has 0 missing vs floor 5 has 3 missing → floor 2 wins
272+
const result = dw.getBestMatchingDeliveryWindow([Flower.RED, Flower.BLUE])
273+
274+
expect(result?.floor).to.eq(2)
275+
expect(result?.windowSelection).to.eq(WindowSelection.LEFT)
276+
})
277+
278+
it('getBestMatchingDeliveryWindow-skips5thFloorWithSingleFlower-noOtherWindows', () => {
279+
const dw = WindowStates.fromPersistence([
280+
{ floor: 5, windowSelection: WindowSelection.LEFT, flowers: [Flower.ORANGE, Flower.BLUE, Flower.YELLOW, Flower.PURPLE, Flower.RED], deliveries: [] }
281+
])
282+
283+
// only 1 flower and only 5th floor available → no match
284+
const result = dw.getBestMatchingDeliveryWindow([Flower.RED])
285+
286+
expect(result).to.be.undefined
287+
})
288+
289+
it('getBestMatchingDeliveryWindow-allows5thFloorWithTwoFlowers-only5thFloor', () => {
290+
const dw = WindowStates.fromPersistence([
291+
{ floor: 5, windowSelection: WindowSelection.LEFT, flowers: [Flower.ORANGE, Flower.BLUE, Flower.YELLOW, Flower.PURPLE, Flower.RED], deliveries: [] }
292+
])
293+
294+
// 2 flowers and only 5th floor → 5th floor is allowed
295+
const result = dw.getBestMatchingDeliveryWindow([Flower.RED, Flower.BLUE])
296+
297+
expect(result?.floor).to.eq(5)
298+
expect(result?.windowSelection).to.eq(WindowSelection.LEFT)
299+
})
300+
252301
it('getBestMatchingUndefinedWindow-picksHighestUndefined', () => {
253302
// only floor 5 left is defined, all others undefined
254303
const dw = WindowStates.new()

0 commit comments

Comments
 (0)