1
Fork 0

fsharp(ygosim): fix: covered some edge cases with tributting

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-15 01:30:17 +02:00 committed by prescientmoon
parent ed384b45da
commit d48af38573
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
2 changed files with 42 additions and 6 deletions

View file

@ -56,6 +56,7 @@ module Player =
f player.lastNormalSummon <&> fun v -> { player with lastNormalSummon = v }
let inline deck f player = (side << Side.deck) f player
let inline monsters f player = (side << Side.monsters) f player
let initialPlayer lp id =
{ lifePoints = lp
@ -111,6 +112,7 @@ module Board =
let inline currentPlayerDeck f board = (currentPlayer << Player.deck) f board
let inline currentPlayerHand f board = (currentPlayer << Player.hand) f board
let inline currentPlayerLastNormalSummon f board = (currentPlayer << Player.lastNormalSummon) f board
let inline currentPlayerMonsters f board = (currentPlayer << Player.monsters) f board
let inline firstPlayer f board = (players << _1) f board
let inline secondPlayer f board = (players << _2) f board
@ -119,6 +121,8 @@ module Board =
type CardInstance = Card.CardInstance<Board>
type Monster = Card.Monster<Board>
type Effect = Effect.Effect<Board>
type Condition = Effect.Condition<Board>
@ -152,29 +156,58 @@ module Client =
module Zone =
open Player
open Side
open Board
let freeMonsterZones player = List.filter Option.isNone player.side.monsters
let freeMonsterZones (player: Player) = List.filter Option.isNone player.side.monsters
let freeMonsterZoneCount = freeMonsterZones >> List.length
let hasFreeMonsterZones = (>=) << freeMonsterZoneCount
let hasFreeMonsterZone player = hasFreeMonsterZones player 1
module Summon =
open Card.Card
open Card
open Board
open Zone
open Client
module Normal =
let inline numberOfTributes monster =
let inline numberOfTributes (monster: Monster) =
let level = monster ^. Card.level
if level <= 4 then 0
elif level <= 6 then 1
else 2
let isNormalSummonable board maybeMonster =
match maybeMonster with
| Some monster ->
let requiredTributes = numberOfTributes monster
let possibleTributes =
board ^. Board.currentPlayerMonsters
|> List.filter Option.isSome
|> List.length
let freeZones = 5 - possibleTributes + requiredTributes
Some(requiredTributes <= possibleTributes && freeZones > 0)
| None -> None
let hasNormalSummonableMonster board =
let hand = board ^. Board.currentPlayerHand
let result =
List.tryFind <| (monster
>> (isNormalSummonable board)
>> Option.isSome)
<| hand
Option.isSome result
let canNormalSummon board =
hasFreeMonsterZone <| board ^. Board.currentPlayer
&& board ^. Board.currentPlayerLastNormalSummon < board ^. Board.turn
hasNormalSummonableMonster board && board ^. Board.currentPlayerLastNormalSummon < board ^. Board.turn
let performNormalSummon client board =
let free = freeMonsterZones <| board ^. Board.currentPlayer
@ -187,10 +220,8 @@ module Summon =
let turn = board ^. Board.turn
board |> Board.currentPlayerLastNormalSummon .-> turn
module Game =
open Turn
open Player

View file

@ -123,6 +123,11 @@ module Card =
| Spell of BaseCard<'s> * SpellCardDetails
| Trap of BaseCard<'s> * TrapCardDetails
let monster card: option<Monster<'s>> =
match card with
| Monster m -> Some m
| _ -> None
module Card =
let inline baseCard f card = _1 f card
let inline cardDetails f card = _2 f card