Page 1 of 1

Card Racing

#1 modi123_1   User is online

  • Suitor #2
  • member icon

Reputation: 16405
  • View blog
  • Posts: 65,116
  • Joined: 12-June 08

Posted 25 September 2021 - 04:17 PM

Visual Studio 2019

.NET Core 3.1

Github Link:

This spawned from a video of a card game seen here:

The rules seem fairly straight forward.

Standard 52 card deck.
Arrange the aces in a horizontal line face up.
Shuffle the deck.
Pull out 5 cards, face down, and arrange them vertically (perpendicular) to the aces. Start one row above the aces.
Each turn consists of:
-- pulling the top card from the draw pile,
-- revealing the card
-- move the corresponding suit's ace up one row.

The win condition: first ace to cross the line wins.

Extra rules:
When one ace is the last in a given row, and there is a face down row card, show that card.
Move that corresponding suit's ace BACK one spot.
Discard the card.

Key Concept - implied values

The application of the rules was a bit tricky, but ultimately this was a fun exercise. It leans heavily into the concept that a list of 52 integers can singularly represent all the cards in a deck for value and suit.

The face value is determined using 'mod 13', and the suit by comparing the value for every 13 values.

Integer 0 mod 13 is 0 so we know that's an Ace. Same as 13 mod 13 is 0, 26 mod 13 is 0 and 39 mod 13 is 0.

34 mod 13 is 8; the face value.
49 mod 13 is 11; a Jack!

The suit is all about between.

0 >= 0 and 0 < 13 so we can determine that 0 is a club.
22 >= 13 and 22 < 26 so that plunks 22 down in Diamonds territory.
34 >= 16 and 34 < 39 so that plunks 34 down in Hearts territory.
45 >= 39 and 45 < 52 so that plunks 45 down in Spades territory.

The fun part is this concept is transportable to most any other 52 card based games, like War, Solitaire, poker, Spades, etc.


The design is a little broad, but not too deep.

Everything is controlled in the backend by the numerical 0-51 values, and only displayed pretty in the print statements. This is all housed in the Utilities_Cards class, and, for hte most part, can be plunked down in any future project.


TheGame class contains the lists (or "decks") for cards to draw, the discard pile as well as the board. This is all tightly coupled to this specific game's rules.


MyBoard class is all about tracking the aces, the hidden row cards, and the GUI display. Again, this is tightly coupled with this specific game's display and rules.


The crux of the game rules are applied in the TheGame class's method 'RunTheGame'.

Here is an example of a run:

The initial display:
  C  D  H  S | START
            | C1
            | H3
            | H4
            | H2
            | D7
            | FINISH
Press any key for the turn;


** Not for gambling or drinking purposes **

Is This A Good Question/Topic? 0
  • +

Page 1 of 1