The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Magicle on February 05, 2010, 03:35:46 PM

Title: Solitaire in assembly
Post by: Magicle on February 05, 2010, 03:35:46 PM
So just a few questions here....

what will be the easiest language to build this solitaire game?
I know pascal, could i combine pascal and ASM?
if so, any tips how to do it? or any tutorials or well explained pages?
What approaches should i take before starting this application

if you have any insight or additional material on this, please post
because i cant seem to find anything on google  :(

Thanks in advance !!! <:
Title: Re: Solitaire in assembly
Post by: BlackVortex on February 05, 2010, 03:53:23 PM
Is it gonna be a 32-bit windows application ?
Title: Re: Solitaire in assembly
Post by: Magicle on February 05, 2010, 03:58:19 PM
Ye <:
Title: Re: Solitaire in assembly
Post by: oex on February 05, 2010, 04:07:23 PM
Solitaire is not massively graphically wanting, you could probably write it in javascript/html, flash, java or vb quite easily, vb if it's a 32 bit application....
Title: Re: Solitaire in assembly
Post by: Magicle on February 05, 2010, 04:53:18 PM
So assembly is mainly for graphical requiring programs?

I don't know visual basic nor java...
Will pascal do? Maybe without the graphicas aspect, just text output...

And on another note, code-wise if someone could point out strategies to confront the coding of solitaire..
It probably is really easy to most of you but i'm having trouble thinking how to build my functions\procedures..
the shuffling, that it will be 4 stacks of 1 (ace) to 13 (king) and pick randoms ,
the stacks of cards, maybe arrays containing the randoms assigned in the shuffles?

Well as you can see im pretty damn lost , if anyone maybe has a solitaire code i'd love to take a look at that, figure out how you did it.

btw, im sorry if this isnt the right forum to ask this..

thanks
Title: Re: Solitaire in assembly
Post by: oex on February 05, 2010, 05:04:42 PM
It is best to start with a text version in Pascal/PHP/Perl etc, a higher level language and use ASM for things that need lots of processing time like graphics. C would probably also be easier to do solitaire in.... ASM might be a bit fiddly for an early card game app.... Having said that you could do a basic console mode version reasonably easily....
Title: Re: Solitaire in assembly
Post by: Magicle on February 05, 2010, 05:10:05 PM
that was so vague from my point of view lol <:

any ideas on how to 'shuffle' 52 cards, with just values between 1 to 13? (and only 4 of each of course)
and card stack, is it best to address them with arrays?
Title: Re: Solitaire in assembly
Post by: redskull on February 05, 2010, 05:16:24 PM
Most of the graphics can be done by the functions in cards.dll, which comes with Windows.  It contains all the card pictures, and ways to draw them and animate them.  As far as data structures go, a straightforward way would be to create a 52 'card' data structures, containing suit/value information, and 9 linked lists (one for each pile, 1 for the face-down deck, and 1 for the 'turnover' pile).  Then, repositioning cards is as simple as changing the list the card is attached to; e.g. "dealing three" involves changing the fourth card on the deck list to be the head node, and switching the first card to be the end node of the pile list.

Obviously there are many different ways to do it.  A good place to start is getting it working in text mode, just printing out the information, and then "windowize" it

-r
Title: Re: Solitaire in assembly
Post by: dedndave on February 05, 2010, 05:20:50 PM
my brother once wrote some code that emulated a real shuffle - lol
you know, sometimes 1, 2, 3, or 4 cards fall from the left, then from the right, etc...
Title: Re: Solitaire in assembly
Post by: Magicle on February 05, 2010, 05:25:07 PM
I hate pascal lol, i'm starting to feel its really limited (after looking at C)
Title: Re: Solitaire in assembly
Post by: BlackVortex on February 05, 2010, 06:06:05 PM
Isn't Pascal a dead language ?
Title: Re: Solitaire in assembly
Post by: Magicle on February 05, 2010, 06:24:48 PM
Ahh, let me clarify.
I honestly don't know if it is being used nowadays for actual programming, but I am a freshmen in Computer Engineering
in the university, just started this year and we are programming in pascal.
I started learning assembly just on my own a week ago or so (lol), and well, honestly, I will probably begin to learn C pretty soon as well.
Title: Re: Solitaire in assembly
Post by: TmX on February 05, 2010, 06:27:49 PM
Quote from: BlackVortex on February 05, 2010, 06:06:05 PM
Isn't Pascal a dead language ?

Nope. Not yet.
FPC (Free Pascal Compiler) is still being actively developed.
And AFAIK it's user base is pretty big.
Title: Re: Solitaire in assembly
Post by: raymond on February 06, 2010, 03:09:01 AM
Here's my procedure for shuffling a deck of cards.

a) At the start of the program, pick a "random" seed and OR it with 1 to make sure it's odd. One good source for that seed may be the lower dword returned by QueryPerformanceCounter. (This may not be necessary if the random number generator you intend to use does not need a seed.)

For shuffling later on,
- get a random number N between 1 and 52 (or 0-51 if you prefer 0-based), remove the Nth card from those remaining and transfer it to the end of the deck.
- get a random number N between 1 and 51, remove that Nth card from those remaining and transfer it to the end of the deck.
- get a random number N between 1 and 50, remove that Nth card from those remaining and transfer it to the end of the deck.
- etc continue until only one card remains.

Repeat the above half a dozen times or so, and you get a well shuffled deck of cards (even from a "new" deck where all the card are in order). Keep a copy of that shuffled deck and use it the next time you need to shuffle.
Title: Re: Solitaire in assembly
Post by: hutch-- on February 06, 2010, 03:19:33 AM
I wonder why you guys do these things the hard way, to shuffle a deck of 52 cards, stuff them into an array and start from the beginning swapping each card with a randomly selected other card in the 52 card array. There is an example in the masm32 example code "exampl10" called "shuflarr" that does it with string arrays, what you are after is really simple to do.
Title: Re: Solitaire in assembly
Post by: dedndave on February 06, 2010, 03:37:33 AM
i always generated the number randomly, testing to see if it is already present in the array
if it is - go back and pick another one - not very fast, i guess - lol

i guess it should be something like Hutch mentioned
you might pick both element indicies at random and swap
Title: Re: Solitaire in assembly
Post by: Magicle on February 06, 2010, 07:05:23 PM
Thanks for all the suggestions and methods, that was what I was looking for!  :U
@Dave, that's the way I was thinking of doing it....
@Hutch, I'll take a look, big thanks.

Title: Re: Solitaire in assembly
Post by: Slugsnack on February 07, 2010, 04:38:19 PM
To answer your question on language of choice, I would personally go with Java for ease of use of the graphics programming. On top of that an application like this would be well suited to an OOP design.
Title: Re: Solitaire in assembly
Post by: PBrennick on February 13, 2010, 08:52:25 PM
Here isy example of Solitaire writen in Java. It does not use cards.dll (overkill). It uses a GIF which contains all the components necessary to build any card. I forgot who showed me that but I use it all the time now; Cribbage for example.

Paul