1
Fork 0

fsharp(ygosim): refactor: now using List.choose to remove a lot of complexity in the normal summoning stuff

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-15 02:26:52 +02:00 committed by prescientmoon
parent 4bfc7c050a
commit 6189917e92
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4

View file

@ -179,9 +179,7 @@ module Summon =
elif level <= 6 then 1 elif level <= 6 then 1
else 2 else 2
let isNormalSummonable board maybeMonster = let isNormalSummonable board monster =
match maybeMonster with
| Some monster ->
let requiredTributes = numberOfTributes monster let requiredTributes = numberOfTributes monster
let possibleTributes = let possibleTributes =
@ -193,20 +191,14 @@ module Summon =
printfn "%i" freeZones printfn "%i" freeZones
Some(requiredTributes <= possibleTributes && freeZones > 0) requiredTributes <= possibleTributes && freeZones > 0
| None -> None
let hasNormalSummonableMonster board = let hasNormalSummonableMonster board =
let hand = board ^. Board.currentPlayerHand let hand = board ^. Board.currentPlayerHand
let monsters = List.choose monster hand
let result = List.exists <| isNormalSummonable board <| monsters
List.tryFind <| (monster
>> (isNormalSummonable board)
>> Option.isSome)
<| hand
Option.isSome result
let canNormalSummon board = let canNormalSummon board =
hasNormalSummonableMonster board && board ^. Board.currentPlayerLastNormalSummon < board ^. Board.turn hasNormalSummonableMonster board && board ^. Board.currentPlayerLastNormalSummon < board ^. Board.turn
@ -215,8 +207,6 @@ module Summon =
let free = freeMonsterZones <| board ^. Board.currentPlayer let free = freeMonsterZones <| board ^. Board.currentPlayer
let zone = chooseZone client free let zone = chooseZone client free
let turn = board ^. Board.turn let turn = board ^. Board.turn
board |> Board.currentPlayerLastNormalSummon .-> turn board |> Board.currentPlayerLastNormalSummon .-> turn