C # Modeling a step-by-step system of rounds with different rules

I am taking the first steps in C #.

I am creating a card game with a turn that goes through several rounds, and each round has different rules than the previous one.

These rules are known in advance. In some rounds there are costumes that the player cannot play, in other rounds there are trump cards. In each round, 4 players take turns playing all 13 cards that they have. Then the deck is shuffled / redeemed, and a new round begins with different rules.

I am a little stuck in trying to simulate this in C #

I have my main Card / Deck classes, done with a regular deck in random order and hand processing, but I'm trying my best to implement this round system.

Can you help with class / function modeling? I can encode it from there.

thank! Pedro

+3
source share
3 answers

Take a look at the strategy template. http://en.wikipedia.org/wiki/Strategy_pattern

+1
source

You have a base class for your rule and implement each specific rule for each round. Outside of this class, there is some logic that knows what specific rule gives you based on the current round, and then use the general logic (something like IsValidMove?) That you would redefine in each derived class.

public abstract class BaseRule
    {
        public virtual bool IsValidMove(object moveDescription);
    }

    public class Round1Rule : BaseRule
    {
        public override bool IsValidMove(object moveDescription)
        {
            return true;
        }
    }

    public class Round2Rule : BaseRule
    {
        public override bool IsValidMove(object moveDescription)
        {
            return false;
        }
    }
+1
source

Player Table, , Rule .

Table current_rule Rule, .

Rulewill expose methods such as bool is_legal_to_play(Card card, ...)or int get_score_for(Player player, ...), or even methods that make AI easier, such as float rate_move(Card card, ...)(then actually play one with a value of max rate_move).

Tablewill reveal the methods / properties, such as Rule get_current_rules(), Player get_current_player(), Player get_player_to_the_right_of(Player player), ...

Please note: I have no experience in C #; this is a fairly general OOP scheme that does not adhere to any particular pattern. Sue.

Ellipses cover additional parameters that may be required depending on your rules.

0
source

Source: https://habr.com/ru/post/1751541/


All Articles