1
Fork 0

fsharp(ygosim): feat: added basic effect types

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-09 11:44:05 +02:00 committed by prescientmoon
parent 6e0c6dbf5b
commit 6ea2d71082
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
3 changed files with 134 additions and 86 deletions

View file

@ -1,14 +1,14 @@
module Board module Board
module Side = module Side =
open Card open Card.Card
type Side = type Side<'s> =
{ field: CardInstance option { field: CardInstance<'s> option
monsters: CardInstance list monsters: CardInstance<'s> list
spells: CardInstance list spells: CardInstance<'s> list
graveyard: CardInstance list graveyard: CardInstance<'s> list
deck: CardInstance list } deck: CardInstance<'s> list }
let emptySide = let emptySide =
{ field = None { field = None
@ -20,27 +20,27 @@ module Side =
module Player = module Player =
open Side open Side
open Card open Card.Card
type PlayerState = type PlayerState =
| InGame | InGame
| Won | Won
| Lost of reason: string | Lost of reason: string
type Player = type Player<'s> =
{ lifePoints: int { lifePoints: int
side: Side side: Side<'s>
hand: CardInstance list hand: CardInstance<'s> list
state: PlayerState } state: PlayerState }
let inflictDamage (player: Player) amount = { player with lifePoints = player.lifePoints - amount }
let initialPlayer lp = let initialPlayer lp =
{ lifePoints = lp { lifePoints = lp
side = emptySide side = emptySide
hand = [] hand = []
state = InGame } state = InGame }
// module Side =
module Turn = module Turn =
type Phase = type Phase =
| Draw | Draw
@ -60,24 +60,45 @@ module Turn =
| End -> (Draw, turn + 1) | End -> (Draw, turn + 1)
module Board = module Board =
open Player
open Turn open Turn
open Card
type Board = type Player = Player.Player<Board>
and Board =
{ players: Player * Player { players: Player * Player
turn: int turn: int
phase: Phase } phase: Phase }
type Card = Card.Card<Board>
type CardInstance = Card.CardInstance<Board>
type Effect = Effect.Effect<Board>
type Condition = Effect.Condition<Board>
type Action = Effect.Action<Board>
let emptyBoard = let emptyBoard =
{ players = (initialPlayer 8000, initialPlayer 8000) { players = (Player.initialPlayer 8000, Player.initialPlayer 8000)
turn = 0 turn = 0
phase = Turn.Draw } phase = Draw }
module Game = module Game =
open Board open Board
open Turn open Turn
open Player open Player
open Card
type PlayerAction =
| Pass
| NormalSummon
| InitialDraw
| Activate
| Set
// let canDoInitialDraw (board: Board) =
let draw (player: Player) = let draw (player: Player) =
match player.side.deck with match player.side.deck with

View file

@ -1,77 +1,104 @@
module Card module Card
// TODO: actually implement it
type BaseCard =
{ name: string
text: string }
type SpellCardType = module Effect =
| NormalSpell type Condition<'s> = 's -> bool
| Field
| Equip
| ContinuosSpell
| QuickPlay
| Ritual
type TrapCardType = type Action<'s> =
| NormalTrap { condition: Condition<'s>
| Counter resolution: 's -> 's }
| ContinuosTrap
type Attribute = type EffectType =
| Dark | Trigger
| Light | Ignition
| Water
| Fire
| Earth
| Wind
| Divine
type Race = type Effect<'s> =
| Aqua { cost: Action<'s>
| Beast resolve: Action<'s>
| BeastWarrior _type: EffectType }
| Creator
| Cyberse
| Dinosaur
| DivineBeast
| Dragon
| Fairy
| Fiend
| Fish
| Insect
| Machine
| Plant
| Psychic
| Pyro
| Reptile
| Rock
| SeaSerpent
| Spellcaster
| Thunder
| Warrior
| WingedBeast
| Wyrm
| Zombie
type SpellCardDetails =
{ spellType: SpellCardType }
type TrapCardDetails =
{ trapType: TrapCardType }
type MonsterCardDetails = module Card =
{ attack: int open Effect
defense: int
attribute: Attribute type BaseCard<'s> =
level: int } { name: string
text: string
effects: Effect<'s> list }
type SpellCardType =
| NormalSpell
| Field
| Equip
| ContinuosSpell
| QuickPlay
| Ritual
type TrapCardType =
| NormalTrap
| Counter
| ContinuosTrap
type Attribute =
| Dark
| Light
| Water
| Fire
| Earth
| Wind
| Divine
type Race =
| Aqua
| Beast
| BeastWarrior
| Creator
| Cyberse
| Dinosaur
| DivineBeast
| Dragon
| Fairy
| Fiend
| Fish
| Insect
| Machine
| Plant
| Psychic
| Pyro
| Reptile
| Rock
| SeaSerpent
| Spellcaster
| Thunder
| Warrior
| WingedBeast
| Wyrm
| Zombie
type SpellCardDetails =
{ spellType: SpellCardType }
type TrapCardDetails =
{ trapType: TrapCardType }
type Card = type MonsterCardDetails =
| Monster of BaseCard * MonsterCardDetails { attack: int
| Spell of BaseCard * SpellCardDetails defense: int
| Trap of BaseCard * TrapCardDetails attribute: Attribute
level: int }
// TODO: actually make this do what its supposed to
type CardInstance = Card type Card<'s> =
| Monster of BaseCard<'s> * MonsterCardDetails
| Spell of BaseCard<'s> * SpellCardDetails
| Trap of BaseCard<'s> * TrapCardDetails
// TODO: actually make this do what its supposed to
type CardInstance<'s> = Card<'s>
module Decklist =
type Decklist =
{ main: int list
side: int list
extra: int list }

View file

@ -4,9 +4,9 @@
open Game open Game
[<EntryPoint>] [<EntryPoint>]
let main argv = let main _ =
let board = Board.emptyBoard let board = Board.emptyBoard
let sampleCard = Spell ({name= "sampleCard"; text="something"}, {spellType = Card.ContinuosSpell}) let sampleCard = Card.Spell ({name= "sampleCard"; text="something"; effects = []}, {spellType = Card.ContinuosSpell})
let secondBoard = withCurrentPlayer <| Game.toDeckBottom sampleCard <| board let secondBoard = withCurrentPlayer <| Game.toDeckBottom sampleCard <| board