fsharp(ygosim): feat: started working on the normal summons
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
d29343da17
commit
581bf55a93
|
@ -7,8 +7,8 @@ module Side =
|
||||||
|
|
||||||
type Side<'s> =
|
type Side<'s> =
|
||||||
{ field: CardInstance<'s> option
|
{ field: CardInstance<'s> option
|
||||||
monsters: CardInstance<'s> list
|
monsters: CardInstance<'s> option list
|
||||||
spells: CardInstance<'s> list
|
spells: CardInstance<'s> option list
|
||||||
graveyard: CardInstance<'s> list
|
graveyard: CardInstance<'s> list
|
||||||
deck: CardInstance<'s> list }
|
deck: CardInstance<'s> list }
|
||||||
|
|
||||||
|
@ -19,10 +19,12 @@ module Side =
|
||||||
let inline graveyard f side = f side.graveyard <&> fun v -> { side with graveyard = v }
|
let inline graveyard f side = f side.graveyard <&> fun v -> { side with graveyard = v }
|
||||||
let inline deck f side = f side.deck <&> fun v -> { side with deck = v }
|
let inline deck f side = f side.deck <&> fun v -> { side with deck = v }
|
||||||
|
|
||||||
let emptySide =
|
let emptyRow _ = List.init 5 <| fun _ -> None
|
||||||
|
|
||||||
|
let emptySide _ =
|
||||||
{ field = None
|
{ field = None
|
||||||
monsters = []
|
monsters = emptyRow()
|
||||||
spells = []
|
spells = emptyRow()
|
||||||
graveyard = []
|
graveyard = []
|
||||||
deck = [] }
|
deck = [] }
|
||||||
|
|
||||||
|
@ -41,7 +43,8 @@ module Player =
|
||||||
side: Side<'s>
|
side: Side<'s>
|
||||||
hand: CardInstance<'s> list
|
hand: CardInstance<'s> list
|
||||||
state: PlayerState
|
state: PlayerState
|
||||||
id: int }
|
id: int
|
||||||
|
lastNormalSummon: int }
|
||||||
|
|
||||||
module Player =
|
module Player =
|
||||||
let inline lifePoints f player = f player.lifePoints <&> fun v -> { player with lifePoints = v }
|
let inline lifePoints f player = f player.lifePoints <&> fun v -> { player with lifePoints = v }
|
||||||
|
@ -49,15 +52,18 @@ module Player =
|
||||||
let inline hand f player = f player.hand <&> fun v -> { player with hand = v }
|
let inline hand f player = f player.hand <&> fun v -> { player with hand = v }
|
||||||
let inline state f player = f player.state <&> fun v -> { player with state = v }
|
let inline state f player = f player.state <&> fun v -> { player with state = v }
|
||||||
let inline _id f player = f player.id <&> fun v -> { player with id = v }
|
let inline _id f player = f player.id <&> fun v -> { player with id = v }
|
||||||
|
let inline lastNormalSummon f player =
|
||||||
|
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 initialPlayer lp id =
|
let initialPlayer lp id =
|
||||||
{ lifePoints = lp
|
{ lifePoints = lp
|
||||||
side = emptySide
|
side = emptySide()
|
||||||
hand = []
|
hand = []
|
||||||
state = InGame
|
state = InGame
|
||||||
id = id }
|
id = id
|
||||||
|
lastNormalSummon = -1 }
|
||||||
|
|
||||||
module Turn =
|
module Turn =
|
||||||
type Phase =
|
type Phase =
|
||||||
|
@ -82,6 +88,7 @@ module Board =
|
||||||
open Card
|
open Card
|
||||||
open Player
|
open Player
|
||||||
|
|
||||||
|
|
||||||
type Player = Player.Player<Board>
|
type Player = Player.Player<Board>
|
||||||
|
|
||||||
and Board =
|
and Board =
|
||||||
|
@ -103,6 +110,7 @@ module Board =
|
||||||
let inline currentPlayerState f board = (currentPlayer << Player.state) f board
|
let inline currentPlayerState f board = (currentPlayer << Player.state) f 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 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
|
||||||
|
@ -121,24 +129,73 @@ module Board =
|
||||||
{ players = (initialPlayer 8000 0, initialPlayer 8000 1)
|
{ players = (initialPlayer 8000 0, initialPlayer 8000 1)
|
||||||
moment = 0, Draw }
|
moment = 0, Draw }
|
||||||
|
|
||||||
module Game =
|
module Client =
|
||||||
open Turn
|
|
||||||
open Player
|
open Player
|
||||||
|
open Turn
|
||||||
|
open Card.Card
|
||||||
open Board
|
open Board
|
||||||
|
|
||||||
type Log =
|
type Log =
|
||||||
| CardToHand of string
|
| CardToHand of string
|
||||||
| NewPhase of Phase
|
| NewPhase of Phase
|
||||||
| StateChanged of PlayerState * PlayerState
|
| StateChanged of PlayerState * PlayerState
|
||||||
|
| ChooseZone of int list
|
||||||
|
|
||||||
type Client = Log -> int
|
type Client = Log -> int
|
||||||
|
|
||||||
|
let rec chooseZone client free =
|
||||||
|
let freeIndices = List.mapi (fun i _ -> i) free
|
||||||
|
let command = ChooseZone freeIndices
|
||||||
|
let result = client command
|
||||||
|
|
||||||
|
if List.contains result freeIndices then free.[result]
|
||||||
|
else chooseZone client free
|
||||||
|
|
||||||
|
module Zone =
|
||||||
|
open Player
|
||||||
|
open Side
|
||||||
|
|
||||||
|
let freeMonsterZones player = List.filter Option.isNone player.side.monsters
|
||||||
|
let freeMonsterZoneCount player = List.length <| freeMonsterZones player
|
||||||
|
let hasFreeMonsterZones player count = freeMonsterZoneCount player >= count
|
||||||
|
let hasFreeMonsterZone player = hasFreeMonsterZones player 1
|
||||||
|
|
||||||
|
module Summon =
|
||||||
|
open Board
|
||||||
|
open Zone
|
||||||
|
open Client
|
||||||
|
|
||||||
|
module Normal =
|
||||||
|
let canNormalSummon board =
|
||||||
|
hasFreeMonsterZone <| board ^. Board.currentPlayer
|
||||||
|
&& board ^. Board.currentPlayerLastNormalSummon < board ^. Board.turn
|
||||||
|
|
||||||
|
let performNormalSummon client board =
|
||||||
|
let free = freeMonsterZones <| board ^. Board.currentPlayer
|
||||||
|
|
||||||
|
printfn "%A" free
|
||||||
|
|
||||||
|
let zone = chooseZone client free
|
||||||
|
|
||||||
|
printfn "%A" zone
|
||||||
|
|
||||||
|
let turn = board ^. Board.turn
|
||||||
|
|
||||||
|
board |> Board.currentPlayerLastNormalSummon .-> turn
|
||||||
|
|
||||||
|
|
||||||
|
module Game =
|
||||||
|
open Turn
|
||||||
|
open Player
|
||||||
|
open Board
|
||||||
|
open Summon.Normal
|
||||||
|
open Client
|
||||||
|
|
||||||
let isCurrentPlayer (board: Board) (player: Player) = (board ^. Board.currentPlayerId) = player.id
|
let isCurrentPlayer (board: Board) (player: Player) = (board ^. Board.currentPlayerId) = player.id
|
||||||
|
|
||||||
let canDrawCard (board: Board) (player: Player) =
|
let canDrawCard (board: Board) (player: Player) =
|
||||||
isCurrentPlayer board player && board ^. Board.phase = Draw && board ^. Board.turn <> 0
|
isCurrentPlayer board player && board ^. Board.phase = Draw && board ^. Board.turn <> 0
|
||||||
|
|
||||||
|
|
||||||
let draw (board: Board) =
|
let draw (board: Board) =
|
||||||
match board ^. Board.currentPlayerDeck with
|
match board ^. Board.currentPlayerDeck with
|
||||||
| [] -> board |> Board.currentPlayerState .-> Lost "deckout"
|
| [] -> board |> Board.currentPlayerState .-> Lost "deckout"
|
||||||
|
@ -151,11 +208,18 @@ module Game =
|
||||||
|
|
||||||
let toDeckBottom (card: CardInstance) (player: Player) = over Player.deck (fun d -> card :: d) player
|
let toDeckBottom (card: CardInstance) (player: Player) = over Player.deck (fun d -> card :: d) player
|
||||||
|
|
||||||
|
let handleMainPhase client board =
|
||||||
|
printfn "%b" <| canNormalSummon board
|
||||||
|
if canNormalSummon board then performNormalSummon client board
|
||||||
|
else board
|
||||||
|
|
||||||
let processPhase client board =
|
let processPhase client board =
|
||||||
match board ^. Board.phase with
|
match board ^. Board.phase with
|
||||||
| Draw ->
|
| Draw ->
|
||||||
if canDrawCard board <| board ^. Board.currentPlayer then draw board
|
if canDrawCard board <| board ^. Board.currentPlayer then draw board
|
||||||
else board
|
else board
|
||||||
|
| Main1 -> handleMainPhase client board
|
||||||
|
| Main2 -> handleMainPhase client board
|
||||||
| _ -> board
|
| _ -> board
|
||||||
|
|
||||||
let switchPhases (client: Client) board =
|
let switchPhases (client: Client) board =
|
||||||
|
|
|
@ -16,6 +16,7 @@ module Effect =
|
||||||
type EffectType =
|
type EffectType =
|
||||||
| Trigger
|
| Trigger
|
||||||
| Ignition
|
| Ignition
|
||||||
|
| Maintanence
|
||||||
|
|
||||||
type Effect<'s> =
|
type Effect<'s> =
|
||||||
{ cost: Action<'s>
|
{ cost: Action<'s>
|
||||||
|
@ -125,7 +126,6 @@ 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
|
||||||
|
|
||||||
// TODO: actually make this do what its supposed to
|
|
||||||
type CardInstance<'s> = Card<'s>
|
type CardInstance<'s> = Card<'s>
|
||||||
|
|
||||||
module Decklist =
|
module Decklist =
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
open Board.Player
|
open Board.Player
|
||||||
open Board.Board
|
open Board.Board
|
||||||
open Board.Game
|
open Board.Game
|
||||||
|
open Board.Client
|
||||||
open Card
|
open Card
|
||||||
|
|
||||||
let printState state =
|
let printState state =
|
||||||
|
@ -21,9 +22,14 @@
|
||||||
| StateChanged (s1, s2) ->
|
| StateChanged (s1, s2) ->
|
||||||
printfn "Player 1: %s" <| printState s1
|
printfn "Player 1: %s" <| printState s1
|
||||||
printfn "Player 2: %s" <| printState s2
|
printfn "Player 2: %s" <| printState s2
|
||||||
| NewPhase phase -> printfn "New phse: %A" phase
|
0
|
||||||
| _ -> printfn "Something unkown happened"
|
| NewPhase phase ->
|
||||||
|
printfn "New phse: %A" phase
|
||||||
|
0
|
||||||
|
| ChooseZone free ->
|
||||||
|
List.head free
|
||||||
|
| _ ->
|
||||||
|
printfn "Something unkown happened"
|
||||||
0
|
0
|
||||||
|
|
||||||
game board client
|
game board client
|
||||||
|
|
Loading…
Reference in a new issue