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

View file

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