Forum C# How to implement rounds with different rules

How to implement rounds with different rules

Postby pmanacas » June 24th, 2010, 11:28 am

Hi all,

I'm taking my first steps in C#.

I'm building a turned based cards game that goes through several rounds and each round has different rules than the one before.

These rules are known beforehand. In some rounds there are suits that the player cant play, in other rounds there are trump suits. In each round 4 players take turns playing all 13 cards they have each. Then the deck is reshuffled / re dealt and a new round with different rules starts.

I'm a bit stuck in trying to model this in C#

I have my basic Card / Deck classes done with the usual shuffle deck and deal hand methods, but I'm struggling on the best way to implement this rounds system.

Can you help with the class /function modelling. I can code it from there.

thanks!
Pedro
pmanacas
 
Posts: 3
Joined: January 29th, 2010, 9:48 pm

Re: How to implement rounds with different rules

Postby Oliver » June 24th, 2010, 1:34 pm

Hi Pedre,

There are multiple ways to accomplish what you're describing. The best solution depends on how many different types of rounds there are, and how different they are.

If there are a low number of different round types that are mostly almost the same, i would suggest just using some if(type==RoundType.A){...} and switch() statements to handle the differences in logic.

If they are very different, you can encapsulate the concept of "A RoundType" into a an abstract class, and have different roundtype implementations for each round type. It's a very simple version of the Strategy Pattern.

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: How to implement rounds with different rules

Postby pmanacas » June 24th, 2010, 3:52 pm

Hey Oliver thanks for the quick reply.

I think the abstract class you mention would be the way to go.

Because all the rounds share some base rules like:
- must follow leading suit
- higher card wins trick
- certain cards give you negative points (although those cards change between rounds and their respective points as well)
- in some rounds the players gets positive points for wining tricks in others he gets negative points.

Here's some more details about the rounds:

round_1 (each trick = -20)
round_2 (each heart = -20, can't lead with hearts if has other suit)
round_3 (each queen = -30)
round_4 (each jack or king = -20)
round_5 (king of hearts = -180, can't lead with hearts if has other suit)
round_6 (2 last tricks of round = -90 each)

Then there are 4 open rounds whose type depends on an auction before each one.
Types of rounds can be:

"positives_with_trump" (each trick = +25, there is a trump suit)
"positives_no_trump" (each trick = +25, no trump suit)
"nills" (each trick = -75)
pmanacas
 
Posts: 3
Joined: January 29th, 2010, 9:48 pm

Re: How to implement rounds with different rules

Postby pmanacas » June 25th, 2010, 11:30 am

Im finding it a bit dificult to get my head arround this strategy patern...

Could you possibily exemplify with some basic class / interface declaration examples?

If not, your help has been great already :)
thanks
pmanacas
 
Posts: 3
Joined: January 29th, 2010, 9:48 pm


Return to C#



cron