Tips for making a Solitaire card game

Community Forums/General Help/Tips for making a Solitaire card game

Ravl(Posted 2014) [#1]
I want to try making a Solitaire-card game, similar to: http://www.bigfishgames.com/download-games/24789/zombie-solitaire/index.html

but I have no idea where to start. I assume you cannot simply randomize the cards. Are there some specific algorithms to make sure that the player has some chances to finish a game?

What should I start looking/learn?


Derron(Posted 2014) [#2]
I think you should do it like you do when creating a sudoku-puzzle.

In my old sudoku puzzler "yourdoku" I created the sudokus and removed a random number: then I checked if the algorithm is able to solve the sudoku without "ambiguity" (a 9 or 1 fits into slot x and the other empty slot y also accepts 9 or 1).
According to the difficulty set up I removed more and more numbers of the field.
Another way to increase difficulty then was how many "steps ahead" the solver must plan to fill things (this decided whether eg simple rules like "scanning cols / rows" finds the next number, or if marking fields with possible numbers is needed).


For solitaire this means:
1. Generate a shuffled deck
2. Try to let your algorithms solve the game
3. if not solveable, generate a new deck


If that "checking" does really take a while, you need to precalculate decks: instead of "random" you use "mersenne twister"-numbers (same initial seed will produce the exact random numbers). Now you check some thousand of seeds if their random numbers generate a valid deck, store the ones which are valid (or store invalid ones...).


So: yes, you have read right: you need a "solver" for your game (this also allows a "hint" at every step in the game). This also allows things like "no possible solution left, want to undo?"


bye
Ron


GfK(Posted 2014) [#3]
I have an editor which allows me to edit the positions of the cards, in layers. The lowest layer is zero, and if I place another card which overlaps an existing card, then it automatically adds it to the next layer above. My editor supports 32 layers (a random number I originally chose for no logical reason), but I don't think I've ever used more than about 7 or 8 layers.

What I end up with from a code point of view, is an array (one element per layer) of TLists. The TList contains all of the cards "slots" (positions) which are on that layer.

I then pre-calculate a list of cards I'm going to populate the level with. The list is exactly the same length as the number of card slots I've defined for that level. You can add in parameters so the flow changes direction after X cards, or jumps to a random card. i.e. you might have in your list:

A, 2, 3, 4, 3, 2, 7, 8, 7, 6, 5, 4, 3, 2, 3, 4, J, Q, K, Q, J, 10, 9, 8...and so on.

Then starting with the lowest layer, I add the first card. Continue adding cards from the list, in order, making sure that I do not add cards to a slot which is above an empty slot on a lower layer. When the list is empty, then also, this means that all the cards slots are populated.

The remaining cards are put into a queue (I think I use a TList) which acts as a stack for the foundation cards. I have a function which shuffles the remaining cards in the stack, by iterating through the list, and adding them to a new list in first or last position randomly. Finally, I make sure that the player has a playable card at the top, if any exist. This becomes the first foundation card.

I'm crap at explaining stuff but that's pretty much it.


Matty(Posted 2014) [#4]
Hmm....when I play patience/solitaire in real life there's no guarantee of winning so why should that be the case in a pc game?


Derron(Posted 2014) [#5]
Because you might have paid for that pc game.

Nobody could guarantee that you would own a demon/devil - but hey, there is Diablo and you are able to kill one.

Do not ask why a pc game differs to the real world. Else you also wont play Super Mario as for sure: red mushrooms with white dots are not that tasty (I know you can eat the younger ones and they are hmm kind of "illusionous").

serious: would you like such a game? you play it for 15 minutes ... press undo multiple times (easy in a "digital game") and try it again without registering, that it is not solveable?

Gfk does something similar to what I have proposed: you spread the cards according to "rules". His rules are, that cards of all slots are somewhat "non blocking" ("if you take them in the right order - which you do not know- you will be able to place all of them on the target slots).

Dunno if this is able for all "variants" but might be easier than a solver. BUT ... like said a solver is able to give you hints for what to do next.


bye
Ron


Ravl(Posted 2014) [#6]
@GfK: I think I understand the process you applied. I also played your game and I see the pattern there. I like your game design and I think is easier to implement than others.

What I cannot understand is this:

I then pre-calculate a list of cards I'm going to populate the level with. The list is exactly the same length as the number of card slots I've defined for that level. You can add in parameters so the flow changes direction after X cards, or jumps to a random card. i.e. you might have in your list:

A, 2, 3, 4, 3, 2, 7, 8, 7, 6, 5, 4, 3, 2, 3, 4, J, Q, K, Q, J, 10, 9, 8...and so on.


how do you 'precalculate' this?

@Matty:
As Derron said. This types of games like other casual games, must be pleasant and easy to play. You must give the user the chance to win it.


GfK(Posted 2014) [#7]
Well, I have a standard set of 52 cards to work from (the "stack"). The first card for the queue is chosen at random, because it's just a starting point - doesn't matter what card it is.

My level editor has a "max run length" parameter - let's say it's "5". That means I can choose a one-higher or one-lower card for the next 5 card choices that I add to the queue. The reason for this parameter is that I can adjust the level difficulty by making the max run length higher (easier) or lower (more difficult).

Each time I add a card to the queue, I remove it from the stack, and a counter increases so I know when I need to throw in a random card - in this case it would be when I've added five cards to the queue. If the max run length was zero, then that basically means that each card added to the queue is completely random - which would make a level extremely difficult as you'd need more foundation cards to complete it.

So to build the queue of cards I'm going to populate the level with, I basically do that. If I remember right, I think I also added in a weighted random somewhere, so even if you set the max run length to 5, it won't *necessarily* add 5 cards before it decides to throw in a random one. Weighted random is as basic as:
If Rand(1,5) = 1
   'add a random card here and reset counter to zero.
EndIf

That would mean that regardless of what max run length is set to, for each card added there is *always* a 20% chance that the logic will put a random card in anyway.

You'll really just have to play around with whatever parameters etc you decide on to see what works best for you - there's no right or wrong way of doing it. Getting the difficulty right is a colossal juggling act, and whatever you do, you'll get people complaining the game is too easy, and other people complaining it's too difficult.


okee(Posted 2014) [#8]
serious: would you like such a game? you play it for 15 minutes ... press undo multiple times (easy in a "digital game") and try it again without registering, that it is not solveable?


Am I getting old or in't that part of the game ? there is always a chance that you will run out of moves. Windows solitaire still does this.
Even if you wrote an algorithm to predetermine whether the game can be won, isn't there a possibility that the player could play the cards in
such a way that they run out of moves.


Matty(Posted 2014) [#9]
Agreed okee....not every game is winnable in patience/solitaire so I don't see why we need to make a pc version winnable. It is part of the game that it is not always able to be won. Winning isn't everything.


GfK(Posted 2014) [#10]
How are we defining "winning"?

In Crime Solitaire 2 (and most other solitaire games I'm aware of), you don't need to remove ALL the cards to win. It psychologically makes "winning" feel much more within reach if you don't have to clear every card in order to do it, because you still have choices at the end.


therevills(Posted 2014) [#11]
I hate solitaire games now... apart from they make me money... so here I go again... :/


Matty(Posted 2014) [#12]
GfK - I've only played solitaire/patience in "real life" and the odd game on Microsoft's solitaire that came with Windows NT but there were many occasions where either through my own decision or the simple ordering of the cards that no further progress could be made and the problem could not be "solved".

i've not played yours or any of the modern casual solitaire clones but I suppose if I were to describe "winning" it would be the same as "solving" a patience/solitaire deck to its perfect completion.

Is that not what winning is in casual solitaire games?


GfK(Posted 2014) [#13]
I hate solitaire games now... apart from they make me money... so here I go again... :/
Really? I've worked on nothing but solitaire games since 2010. I am completely and utterly pig bloody sick of it.

I do have another solitaire game half-finished that I started with that guy who bailed out half way thru, but I don't think my sanity is going to take any more solitaire.

If I do anything else it will have to a complete diversion.

Is that not what winning is in casual solitaire games?
No, and it's kind of a big deal to casual gamers. They don't like to lose, so you can't let them lose. They need to be made to feel like they're winning ALL the time, hence why most games have tons of trophies and achievements and God knows what else.


Matty(Posted 2014) [#14]
Thanks GfK....your description of the casual gamer reminds me of when I was a school teacher where "everyone's a winner baby" ..


GfK(Posted 2014) [#15]
It's completely true. I swear if casual gamers were playing board games, nine games out of ten they'd flip the table.


xlsior(Posted 2014) [#16]