-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Compute reviews after getting enough fans
- Loading branch information
1 parent
f0c37ee
commit 27303ff
Showing
13 changed files
with
226 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Duets.Cli.Components.Commands.Cheats | ||
|
||
module Index = | ||
let all = | ||
[ LifeCommands.happy | ||
MoneyCommands.motherlode | ||
MoneyCommands.rosebud | ||
TriggerEffectCommands.triggerEffect ] |
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/Duets.Cli/Components/Commands/Cheats/TriggerEffect.Cheats.Commands.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Duets.Cli.Components.Commands.Cheats | ||
|
||
open Duets.Agents | ||
open Duets.Cli | ||
open Duets.Cli.Components.Commands | ||
open Duets.Cli.SceneIndex | ||
open Duets.Entities | ||
open Duets.Simulation | ||
|
||
[<RequireQualifiedAccess>] | ||
module TriggerEffectCommands = | ||
/// Command which triggers the specified effect. Since this requires manually | ||
/// pattern matching against all possible effects, it does not support | ||
/// every effect. | ||
let triggerEffect = | ||
{ Name = "trigger_effect" | ||
Description = "" | ||
Handler = | ||
(fun args -> | ||
match args with | ||
| [ "band_fans"; oldFans; newFans ] -> | ||
let currentBand = Queries.Bands.currentBand (State.get ()) | ||
|
||
BandFansChanged( | ||
currentBand, | ||
Diff(int oldFans, int newFans) | ||
) | ||
|> Effect.apply | ||
| _ -> () | ||
|
||
Scene.World) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Duets.Simulation.Events.Band.Band | ||
|
||
open Duets.Entities | ||
open Duets.Simulation | ||
open Duets.Simulation.Events | ||
|
||
/// Runs all the events associated with bands. For example, when the fan base | ||
/// changes, the engine might generate new reviews for their albums. | ||
let internal run effect = | ||
match effect with | ||
| BandFansChanged(band, Diff(prevFans, currentFans)) when | ||
prevFans < Config.MusicSimulation.minimumFanBaseForReviews | ||
&& currentFans >= Config.MusicSimulation.minimumFanBaseForReviews | ||
-> | ||
[ Reviews.generateReviewsAfterFanIncrease band.Id ] | ||
|> ContinueChain | ||
|> Some | ||
| _ -> None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Duets.Simulation.Events.Band.Reviews | ||
|
||
open Duets.Simulation.Albums | ||
|
||
let generateReviewsAfterFanIncrease bandId state = | ||
ReviewGeneration.generateReviewsForBand state bandId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
module Duets.Simulation.Tests.Events.Band | ||
|
||
open FsCheck | ||
open FsUnit | ||
open NUnit.Framework | ||
open Test.Common | ||
open Test.Common.Generators | ||
|
||
open Duets.Entities | ||
open Duets.Simulation | ||
|
||
let bandFansChanged fansBefore fansAfter = | ||
BandFansChanged(dummyBand, Diff(fansBefore, fansAfter)) | ||
|
||
let stateWithAlbum = | ||
State.generateOne State.defaultOptions | ||
|> State.Albums.addReleased dummyBand dummyReleasedAlbum | ||
|
||
let filterReviewsReceived = | ||
List.filter (function | ||
| AlbumReviewsReceived _ -> true | ||
| _ -> false) | ||
|
||
[<Test>] | ||
let ``tick of band fans changed should not generate reviews if count hasn't gotten past the minimum`` | ||
() | ||
= | ||
Gen.choose (0, Config.MusicSimulation.minimumFanBaseForReviews - 2) | ||
|> Gen.sample 0 100 | ||
|> List.iter (fun previousFans -> | ||
Simulation.tickOne | ||
stateWithAlbum | ||
(bandFansChanged previousFans (previousFans + 1)) | ||
|> fst | ||
|> filterReviewsReceived | ||
|> should haveLength 0) | ||
|
||
[<Test>] | ||
let ``tick of band fans changed should not generate reviews if count has already gotten past the minimum before`` | ||
() | ||
= | ||
Gen.choose ( | ||
Config.MusicSimulation.minimumFanBaseForReviews + 1, | ||
Config.MusicSimulation.minimumFanBaseForReviews + 10000 | ||
) | ||
|> Gen.sample 0 100 | ||
|> List.iter (fun previousFans -> | ||
Simulation.tickOne | ||
stateWithAlbum | ||
(bandFansChanged previousFans (previousFans + 1)) | ||
|> fst | ||
|> filterReviewsReceived | ||
|> should haveLength 0) | ||
|
||
[<Test>] | ||
let ``tick of band fans changed should generate reviews if count has just gotten past the minimum`` | ||
() | ||
= | ||
Gen.choose ( | ||
Config.MusicSimulation.minimumFanBaseForReviews + 1, | ||
Config.MusicSimulation.minimumFanBaseForReviews + 10000 | ||
) | ||
|> Gen.sample 0 100 | ||
|> List.iter (fun updatedFans -> | ||
Simulation.tickOne | ||
stateWithAlbum | ||
(bandFansChanged | ||
(Config.MusicSimulation.minimumFanBaseForReviews - 1) | ||
updatedFans) | ||
|> fst | ||
|> filterReviewsReceived | ||
|> should haveLength 1) | ||
|
||
[<Test>] | ||
let ``tick of band fans changed should generate reviews for all previously released albums`` | ||
() | ||
= | ||
let secondUnreleasedAlbum = | ||
Album.Unreleased.from dummyBand "Test Album 2" dummyRecordedSongRef | ||
|
||
let secondAlbum = | ||
Album.Released.fromUnreleased secondUnreleasedAlbum dummyToday 1.0 | ||
|
||
let thirdUnreleasedAlbum = | ||
Album.Unreleased.from dummyBand "Test Album 3" dummyRecordedSongRef | ||
|
||
let thirdAlbum = | ||
Album.Released.fromUnreleased thirdUnreleasedAlbum dummyToday 1.0 | ||
|
||
let state = | ||
stateWithAlbum | ||
|> State.Albums.addReleased dummyBand secondAlbum | ||
|> State.Albums.addReleased dummyBand thirdAlbum | ||
|
||
Simulation.tickOne | ||
state | ||
(bandFansChanged | ||
(Config.MusicSimulation.minimumFanBaseForReviews - 1) | ||
(Config.MusicSimulation.minimumFanBaseForReviews + 1)) | ||
|> fst | ||
|> filterReviewsReceived | ||
|> should haveLength 3 |
Oops, something went wrong.