Pusoy Dos core lib
2nd attempt at a pusoy dos library
Aims
- simple external interface
- configurable rulesets (support Pickering rules and standard Pusoy Dos)
The idea around the game/round relationship is that the game (totally breaks the SRP) is a container which acts as a general purpose api for the consumer of the library. It also has the responsibility of keeping track of the initial attributes of the game as a whole (ruleset, options, players).
The Round
is a snapshot of the current state of the game. There are some ownership issues (which I have short term deferred thinking about by blindly cloning) and some parts of Game
may do better split out, but that's the rationale behind this PR.
I think cards only need to have rank and suit, and possibly joker/wildcard flag.
{
rank: enum,
suit: enum,
joker?: boolean,
}
Feels a bit dirty having the joker flag, and before a joker is played, it has no rank or suit, so maybe the rank and suit enum can contain a Joker
type. Then a joker would be
{
rank: Rank.Joker,
suit: Suit.Joker
}
~~If we assume that joker is always the strongest possible card, the comparisons don't even need to know anything extra like intended rank and suit. Not sure how feasible this is though, seems tricky to make the comparison function work out the best value for the joker, and would probably cause confusion amongst players if we didn't display a real value.~~
Maybe best is to do it this way but have a separate struct for PlayedCard
which has intended rank/suit value.
Currently rules are made up of suit order
and reversed
boolean.
Might be worth thinking about having the rules made up of suit order
and rank order
.
Then instead of setting reversed = true
we would just reverse the suit order
and rank order
arrays.
Seems a little more complicated, but it simplifies comparison, and allows for potential complex rulesets,
e.g. suits reverse but ranks stay the same, 3's become top card, or "chess mode" where kings are the weakest.
Probably we don't need such complicated game rules, but if it isn't too difficult to implement, then there are no downsides compared to the current way.
Actually rules also include hands, and player order, though they feel different to the comparison rules. If we could incorporate a way to represent them too in the rules, then potentially we could have very different games using the same code, just by writing new rules.
Opened for comment, not looking to get this merged straight away.
https://github.com/soydos/pusoy_dos2/blob/8acbbef5a7f245c6c226af75806d9b18557d053f/.travis.yml#L16
Here too same as https://github.com/soydos/wasm-pusoy-dos/issues/3
Made a start on removing cards from players hand. I didn't know if it was best to update the current struct or return a new one, so I did both. We can change that if needs be.
Also returns an error if the player doesn't have any of the cards that are attempted to play.
Also added a couple of small tests to comparisons.