From 931cb9d2373e13496ba0123c769681d19f111dad Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 15 Jan 2023 14:22:14 -0500 Subject: [PATCH] genChapter4 --- src/lib/store/genNextBattle.js | 28 ++++++++++++++++++++++++++++ src/lib/store/genNextBattle.test.js | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/lib/store/genNextBattle.js b/src/lib/store/genNextBattle.js index 34acce8..4f599a5 100644 --- a/src/lib/store/genNextBattle.js +++ b/src/lib/store/genNextBattle.js @@ -102,6 +102,32 @@ export function genChapter3Battle(battles) { }; } +export function genChapter4Battle(battles) { + const chapter = 4; + + const scenario = 'The Last Battle'; + + const cities = R.difference( + battles + .slice(0, 6) + .filter(({ status }) => status !== 'lost') + .map(R.prop('city')), + battles.slice(6).map((b) => b.city.selection), + ); + + const characters = battles.slice(0, 6).map(R.prop('character')); + + return { + scenario, + city: { choices: cities, selection: R.first(cities) }, + status: 'ongoing', + additionalCharacters: R.range(0, 3).map((i) => ({ + choices: characters, + selection: characters[i], + })), + }; +} + export function genNextBattle(battles = []) { let chapter = R.clamp(1 + parseInt(battles.length / 2), { min: 1, max: 4 }); @@ -110,4 +136,6 @@ export function genNextBattle(battles = []) { if (chapter === 2) return genChapter2Battle(battles); if (chapter === 3) return genChapter3Battle(battles); + + return genChapter4Battle(battles); } diff --git a/src/lib/store/genNextBattle.test.js b/src/lib/store/genNextBattle.test.js index b184b9c..3369994 100644 --- a/src/lib/store/genNextBattle.test.js +++ b/src/lib/store/genNextBattle.test.js @@ -4,6 +4,7 @@ import { genNextBattle, genChapter2Battle, genChapter3Battle, + genChapter4Battle, } from './genNextBattle.js'; test('generate for the first chapter', () => { @@ -66,3 +67,20 @@ test('chapter 3, second battle', () => { expect(result.additionalCharacters[0].selection).toEqual('two'); expect(result.additionalCharacters[1].selection).toEqual('four'); }); + +test.only('chapter 4, first battle', () => { + const result = genChapter4Battle([ + { character: 'one', city: 'a' }, + { character: 'two', city: 'b', status: 'lost' }, + { character: 'three', city: 'c' }, + { character: 'four', city: 'd' }, + { character: 'five', city: 'e' }, + { character: 'six', city: 'f' }, + ]); + + expect(result.additionalCharacters[0].selection).toEqual('one'); + expect(result.additionalCharacters[1].selection).toEqual('two'); + expect(result.additionalCharacters[2].selection).toEqual('three'); + + expect(result.city.choices).not.toContain('b'); +});