1
Fork 0

fsharp(ygosim): feat: deckouting

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-07 19:56:20 +02:00 committed by prescientmoon
parent eab212c039
commit 6e0c6dbf5b
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
2 changed files with 15 additions and 5 deletions

View file

@ -22,17 +22,24 @@ module Player =
open Side open Side
open Card open Card
type PlayerState =
| InGame
| Won
| Lost of reason: string
type Player = type Player =
{ lifePoints: int { lifePoints: int
side: Side side: Side
hand: CardInstance list } hand: CardInstance list
state: PlayerState }
let inflictDamage (player: Player) amount = { player with lifePoints = player.lifePoints - amount } 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 }
module Turn = module Turn =
type Phase = type Phase =
@ -64,7 +71,7 @@ module Board =
let emptyBoard = let emptyBoard =
{ players = (initialPlayer 8000, initialPlayer 8000) { players = (initialPlayer 8000, initialPlayer 8000)
turn = 0 turn = 0
phase = Draw } phase = Turn.Draw }
module Game = module Game =
open Board open Board
@ -74,7 +81,7 @@ module Game =
let draw (player: Player) = let draw (player: Player) =
match player.side.deck with match player.side.deck with
| [] -> player // TODO: makes this end the game | [] -> { player with state = Lost "deckout" }
| card :: deck -> | card :: deck ->
{ player with { player with
hand = card :: player.hand hand = card :: player.hand

View file

@ -8,7 +8,6 @@
let board = Board.emptyBoard let board = Board.emptyBoard
let sampleCard = Spell ({name= "sampleCard"; text="something"}, {spellType = Card.ContinuosSpell}) let sampleCard = Spell ({name= "sampleCard"; text="something"}, {spellType = Card.ContinuosSpell})
let (first, second) = board.players
let secondBoard = withCurrentPlayer <| Game.toDeckBottom sampleCard <| board let secondBoard = withCurrentPlayer <| Game.toDeckBottom sampleCard <| board
printfn "%A" secondBoard printfn "%A" secondBoard
@ -17,4 +16,8 @@
printfn "%A" thirdBoard printfn "%A" thirdBoard
let lastBoard = List.fold (fun b _ -> doTurn b) thirdBoard [0..5]
printf "%A" lastBoard
0 0