johnameyer / cards-ts

A card game framework and various games in Typescript. The framework allows for bot development and playing card games in the terminal or in a browser.
4 stars 2 forks source link

Validation rework #91

Open johnameyer opened 2 years ago

johnameyer commented 2 years ago

As identified in #62

johnameyer commented 5 months ago

Likely worth thinking through whether we can re-use handlers in a generic way as well - i.e. discard events all are handled the same way.

johnameyer commented 5 months ago

Likely we should also use these validations in some form for the game-params i.e. type / range or other things that could be passed onto inquirer.

johnameyer commented 5 months ago

Core: isTurn, hasCard, nonnull, hasLength, isSuit

Situational: followSuit?

Composition: allOf/eachOf (asserting on each in array of values)

Others: not? (i.e. not(isSuit(H)))

A big question here is how the validators are parameterized - e.g. if we want to make sure the player follows suit, how is that suit provided? (long term - would it be done client side?) In situational occurrences do we pre-compute?

Additionally, there is the question of how to handle more complicated validations e.g. making sure a card cannot be played on any meld. While we could ad-hoc define these, that then limits the universality.

johnameyer commented 5 months ago

There's also a thought that since playing a card removes it from the hand there is a close relationship between the validation and the handling