Card and tabletop game engine

by Viktor Chlumský

Coming soon to Steam Windows macOS Linux

On this page, I'd like to demonstrate what making a game in Cardgine is like before you have a chance to try it yourself. It is coming to Steam this winter. As you'll see on this page, any game made in Cardgine can be played in the browser, together with your friends. Before seeing how it was made, feel free to play a round or two of Solitaire.

How was Solitaire made in Cardgine?

1 List card suits and ranks

Enumeration Suit in the Cardgine editor: clubs, spades, diamonds, hearts Enumeration Rank in the Cardgine editor: ace, 2 to 10, jack, queen, king

2 Define shared properties of cards

You can also have multiple "classes" of cards. And they don't actually have to represent cards — they can be board game pieces (see chess) or other visual elements.

Card class Card in the Cardgine editor: double-sided, 63.5 by 88.9 mm, rounded corner radius 3.81 mm, constant properties suit and rank

3 Generate all 52 cards as suits × ranks

No need to list them individually. Card designs are loaded from PNG images placed in the project's asset folder.

Cardset all_cards in the Cardgine editor: every combination of suit and rank becomes a card named card_{suit}_{rank} with the front design {suit}-{rank}.png, 52 cards in total

4 Set up the tabletop layout

Region layout in the Cardgine editor: a preview of the table, the layout tree with the drawing stock, card buffer, four foundation stacks and seven column spreads, and the settings of the selected card stack

5 Write the game rules in CardScript

Scripting is currently required to describe how the game flows and CardScript is a tailor-made language to describe tabletop game actions in the simplest possible way. If you aren't comfortable with scripting, no worries, any AI assistant will be able to help.

The main gameplay script of Solitaire in the Cardgine editor:
# Move "all_cards" (cardset) to "drawing_stock" (layout element)
all_cards -> drawing_stock
# Set up the initial state of the table - run custom "deal_cards" function
deal_cards!
# Acquire the player object
player single_player := first_of active_players

# Let player make moves until they win the game (they cannot lose, only quit/restart)
while not victory_detected:
    # Call the custom player function "play_move"
    single_player play_move!
# If they escaped the loop, victory has been achieved - mark player victorious
single_player win!
# Tidy up remaining cards, which can now be stacked trivially
tidy_up_cards!

This is only the main body of the script, the rest resides in the custom functions. The entire Solitaire game takes just 127 lines of code.

Cardgine is primarily made for online multiplayer games

You can play the game you're working on with friends right from the Cardgine editor. Select "Launch online game" to get a shareable link, and your friends can join from their browser, without installing anything.

You can also playtest a multiplayer game by yourself by taking control of all players. Try it out in the next demo:

One more demo
Number of players: 3

If you'd like to know how this game was made, you can watch the 20-minute-long full walkthrough I made, on YouTube.

A complete game in CardScript

The trailer shows the full script of a game I invented with the goal of making it as simple as possible while still letting players make meaningful choices. The goal of this game is to get rid of all your cards first. Players take turns and on each turn, the player discards one card (any) from their hand. But unless it matches the top card's suit or rank, they have to draw two other cards immediately. The main body of this game's script is:

all_cards -> drawing_stock

drawing_stock shuffle!

# Deal cards
foreach player p in active_players:
    drawing_stock topmost 4 -> p hand

drawing_stock top -> discard_pile

# Game loop
player current_player := first_of active_players

while not any_player_won:
    current_player play!
    current_player := active_player_after current_player

Hover over any individual line for a full explanation.

play! is a user-defined player function, which reads:

choose Card c from hand

boolean match := (
    c suit == discard_pile top suit or
    c rank == discard_pile top rank
)

c -> discard_pile

if not match:
    drawing_stock topmost 2 -> hand

if hand is_empty:
    win!

That is all it takes to implement this fully working game. Try playing it and let me know if it's any good:

Disclaimer: Cardgine currently does not support playing versus the computer. I've just made this demo for this page.

An obvious next feature would be to draw cards through a custom draw function that also checks if the drawing stock ran out and reshuffles the discard pile into it. Do you think you could write it?

Coming soon to Windows macOS Linux

Wishlist on Steam