Evil By Design

99

Transcript of Evil By Design

type Box = | Yellow | Green | Red | Blue | White | Purple

1

2

3

4

5

6

type RandomNumber = | Num1 | Num2 | Num3 | Num4 | Num5 | Num6

match rnd with| Num1 -> Yellow | Num2 -> Green| Num3 -> Red| Num4 -> Blue | Num5 -> White| Num6 -> Purple

1

2

3

4

5

6

Lose

Lose

Win!

Lose

Lose

Lose

type BoxValue = | Win of Multiplier | Loss

and Multiplier = decimal

match box with| Red -> Win 6M| _ -> Loss

1

2

3

4

5

6

Lose

Lose

Win!

Lose

Lose

Lose

let box = rng() |> toBoxlet value = box |> toValue

{ Box = box; Value = value }

1

2

3

4

5

6

Lose

Lose

Win!

Lose

Lose

Lose

1

2

3

4

5

6

Lose

Lose

Win!

Lose

Lose

Lose

let run times f =[ 1 .. times ] |> Seq.map(fun _ -> f())

1/6

1/6

1/6

1/6

1/6

1/6

let payout bets wins = match bets with| 0M -> 1M| _ -> wins / bets

let houseEdge bets wins = match wins with| 0M -> 1M| _ -> bets / wins

House edge

0%

Payout

100%

match box with| Red -> Win 5M| _ -> Loss

House edge

16%

Payout

84%

1

2

3

4

5

6

Lose

Lose

Win!

Lose

Lose

Lose

1 2

3

4 5 6

Lose

Lose

Win!

Lose

Lose

Lose

match rnd with| Num1 | Num2 -> Green | Num3 -> Red| Num4 | Num5 | Num6 -> Blue

0/6

2/6

1/6

3/6

0/6

0/6

House edge

16%

Payout

84%

public interface IStatefulAggregate<TState>{

TState State();}

public interface IEventRecordingAggregate{

IEnumerable<object> Events();}

new Scenario<Player, PlayerState>().Given(() => Player.Register("1", "jef")).When(sut => sut.Lock()).ThenState(new PlayerState(){ Id = "1", Locked = true, Nickname = "jef" }).ThenEvent(new PlayerRegistered("1", "jef")).ThenEvent(new PlayerLocked("1")).Run();

@