-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add room and round test. also refactor
- Loading branch information
1 parent
7512ffb
commit 78513b8
Showing
10 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule ViralSpiral.Room.State.Deck do | ||
alias ViralSpiral.Room.State.Deck | ||
alias ViralSpiral.Room.State.Change | ||
|
||
defstruct available_cards: nil, | ||
dealt_cards: nil | ||
|
||
@type change_opts :: [type: :remove | :shuffle] | ||
@type t :: %__MODULE__{ | ||
available_cards: MapSet.t(), | ||
dealt_cards: MapSet.t() | ||
} | ||
|
||
@doc """ | ||
todo : datastructure of cards, optimized for game operations | ||
""" | ||
def new(cards) do | ||
%Deck{ | ||
available_cards: MapSet.new(cards), | ||
dealt_cards: MapSet.new() | ||
} | ||
end | ||
|
||
defimpl Change do | ||
@doc """ | ||
Handle changes to the deck. | ||
Possible changes : | ||
- Make card unavailable for drawing. Implemted by change type :remove | ||
- Shuffle card. Implemented by change type :shuffle | ||
""" | ||
@spec apply_change(Deck.t(), Deck.change_opts()) :: Deck.t() | ||
def apply_change(%Deck{} = deck, opts) do | ||
case opts[:type] do | ||
:remove -> | ||
Map.put(deck, :available_cards, MapSet.difference(deck.available_cards, opts[:target])) | ||
|
||
:shuffle -> | ||
Map.put(deck, :availabe_cards, Enum.shuffle(deck)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters