PDA

ygfperson
09-04-2002, 09:19 PM
Topic: Solitaire Solver
Directions: Create a game which intelligently plays Solitaire.

There will not simply be an array of cards to choose from, because that would make cheating very easy. There will be arrays of cards, showing only the ones that are facing up. (The ones facing down are invisible to the programmer.)

card_array[0][0] might contain the card on the top of pile 1. card_array[1][1] might contain the second card down from the top of pile 2.

So it's: int card_array[pile][card in pile going from top downward]

Piles 0-6 will be the normal solitaire piles. Piles 7-10 will be the ones on the top where you put them last. Pile 11 will be the discard pile, which would show the card just served off the deck. All piles are read from left to right. Cards 0-12 are diamonds, the next 13 are hearts, the next 13 are clubs, and the last 13 are spades. (So, red cards are 0-25, the black cards are 26-51). This is a global variable. (I would've made it local, but that's too much work for something like this.) If a card turns up -1, that means that card does not exist, and you've probably gone to the end of that pile. (If the first card in a pile is -1, that means that pile is empty.)

Some functions:
int new_card(void);
This function takes a card from the serving pile (I forget the technical name) and places it in the discard pile. You can assume that each time it's only one card this is happening to. The value returned will be either the value of the card returned (cards are valued 0 to 51) or -1 if it has reached the end of the pile. It will automatically reset if it's at the end of the pile.

int move_card(pile number card is in, pile number card is moved to, number of cards moved);
This returns a 1 if successful, and a 0 for failure. Reasons for failure include breaking the rules or incorrect pile numbers.

Any possible functions i missed?

Your (the contestant's) function will be called:
int make_best_choice(void);
Inside it you will move cards, draw new cards, and basicly interact with the game so that you win. You are encouraged to use all the resources at your disposal to win, but it's impossible to peek. You can count cards that have already gone by, if you want to factor it into your decision.

After deciding the right move the program should call the move function. Then everything is automatically updated and you go through the process again until you win or lose.

It's up to your program to decide whether or not to lose. A winning scenario is easy to spot, but a losing scenario requires that you concede defeat yourself. Return a 0 for a defeat, and a 1 for a win.
Criteria:
efficiency -- use computer resources efficiently
elegance -- make your code neat and understandable. The structure and planning put into your program is key
portability -- how many computers can your code compile across? (especially important, cause i got to link with the code)
Special Criteria:
Interface -- make your interface user-friendly and idiot-proof
Success rate/Intelligence -- Does this game win more often than normal?
Stability/Garbage Collection -- does your game clean up after itself? (ie: memory leaks?) when will it crash? how stable is it?

Time Limit: For this one i'll be generous and say that all entries need to be in by September 24.

Signed up Contestants: 8 slots left
vasanth
troll king

Signed up Judges: all slots filled
ygfperson
civix
xds4xl
klinerr1

Send all entries to geoschnee2@thetruth.com or ygfperson@cprogramming.com
You can also submit your entry at the web site, contests.cprogramming.com

Remember, above all, make sure your program works. :D

civix
09-04-2002, 09:35 PM
I'd be more than happy to judge, if you didnt have a problem with that, ygf.

xds4lx
09-04-2002, 09:42 PM
Id also like to judge .

black
09-04-2002, 09:49 PM
only C or C++ programs allowed ?

xds4lx
09-04-2002, 10:01 PM

vasanth
09-04-2002, 10:04 PM
Sign me up.. I am in....

ygfperson
09-04-2002, 10:11 PM
only C or C++ programs allowed ?
yep.

Hammer
09-05-2002, 10:29 AM
Originally posted by ygfperson
only C or C++ programs allowed ?

yep.
What, I can't enter my REXX version then? Goddammit, ygf, I've been coding that for ages too. :rolleyes: :D

Driveway
09-05-2002, 01:23 PM
games must restrict the player(s) to a
?

ygfperson
09-05-2002, 05:48 PM
Congradulations. You found my momentary lapse of reason.

What I mean is that all players must be restricted in their movement and playing so they can't break the rules of the game.

moi
09-05-2002, 06:11 PM
Originally posted by ygfperson
Write a card game program. The card game can be any reasonable game (not 52-pickup).

what is 52-pickup??????

Hammer
09-05-2002, 06:13 PM
>what is 52-pickup??????
You never played 52 card pickup ? wow! It's an school trick, you get someone to agree to play it, then just throw the deck of cards in the air, and watch the poor sod pick up all the cards. If they refuse, they get the raps, or they did in my days at school. I suppose you've never heard of the raps either?! :D

ygfperson
09-05-2002, 08:59 PM
the web page has been updated with the same info as is on here. soon i'll add file-uploading support.

ygfperson
09-05-2002, 09:24 PM
File-Uploading support has been integrated. Just surf to the contest web page, click on the right link, and don't forget to include your name.

vasanth
09-06-2002, 04:55 AM
Yes that is waht i have been trying to say all these days.. Make the contest more specialized and not general so no onee can copy the cource...... I had recomended a function contest for specoialized problems.. So rethink the contest idea... TO submit a contest that has been happening all these time it just requires 10 minutes.. Go to a site download a source submit it... No idea how many have done it...

I am also off this contest if the idea remains same...

xds4lx
09-06-2002, 10:13 AM
First off, there needs be no rules for the features to be included other thatn the basic requirements to play the game. The developer can then add anything he/she wants to make theirs stand out. While "any card game" is a broad range of different games I think it makes no difference, no matter what game is selected there will always be some jerk out there who has to cheat and download someone elses code and try to pass it off as his/her own. But I can assure you that as a judge I will compare any and all entries against code found readily available on the net.

ygfperson
09-06-2002, 04:21 PM
ok. i'll lengthen the contest to 2 weeks, ending on the saturday midnight 2 weeks from now. (no idea what day that is... i'll check it soon)

Whoever makes these contests needs to slow down on the caffiene
i'm not the one posting 4 messages in a 15 minute period... ;)

if you want the contest specialized, suggest a game. better yet, put up a poll and let people vote for it.

a functional contest sounds intriguing... but how would it be implemented?

i am not worried over people posting copied source code. from reading the code i doubt anyone has done it yet.

Troll_King
09-06-2002, 04:30 PM
Okay, sign me up, but I'm not sure which card game I'll make. If you are more specific abour the requirements, than it will reduce the ability to grab code off the internet.

ygfperson
09-06-2002, 05:04 PM
lemme suggest a possible game... poker? any version would do. it would also let people try their hands at the multiplayer aspect

Troll_King
09-07-2002, 04:28 AM
What are the rules of poker?

ygfperson
09-07-2002, 10:02 AM

here are its rules:
http://www.conjelco.com/faq/poker.html

vasanth
09-08-2002, 09:12 AM
Well ithough of doing a simple card game called memory.. The player has to keep track of the position of cards opened... Well when he open 2 cards with the same value say Hearts A and Clubs A.. he takes it... well sometin like this..

Well i decided to do a poker game..(i dint know what poker was..) and after going through some of the poker games.. i still could not undestand it properly..(I never played poker..) then after figuring it out.. It seems like it will take me a month to complete it.. since i am hardly free for more than 2 hrs a day... So it looks like i will be out of the contest... But in case the card game criteria changes...(Where the programmer chooses the card game he wants to do..) i am in.... But in case not i will surely contest in the next contest and try my luck...

Bye
Vasanth

ygfperson
09-08-2002, 10:53 AM
alright. so...

the programmer chooses the game he/she wants (card game, has to be fairly well known, not 52 pickup).

vasanth, i don't know how to implement your idea of specializing the contest through functions only... can you clarify what you mean?

btw, for all contestants, the contest is on hold until we figure out a definite plan.

vasanthm
09-08-2002, 10:03 PM
Well i dint mean an entire program inside a function.. What i meant was a specialized problem that can be anything.. like say the function should evaluate wheather an given equation can be formed or not... And you can even have contests where for example the function should take a big word as argument and should write all possible words that can be formed out of it in a file and so on.....(similar to dictionary..)...

The contest can even be like say complex drawings.. WHere the user can use any graphics library.. The function should take a definite amount of numbers as argument and draw the complex drawing..(Can be fixed as 3d mesh etc etc...)

The contest can also be say take some numbers representing a maze or something and should return the shortest route possible from position 1 to b as the asnwer. The argements sent here can be a char array like

a - d
d - g
d -h
h - a
h - f
g - f
f - b

here the function has to compute the shortest route from a to b...

So many of these stuff can be done.. Even contests where the function find wheather a given number is prime or not..(here the prime number can be say a 10 digit number..)

But if you have a poll to decide this by only taking votes from the people who have contested so far.. people who dont contest in the contest awill not be intrested in these kinds of contests since it is no fun to them.. they prefer to see games like nibles, pokers etc... They dont care about copying source and stuff... but the contestants will really know what to choose.....

The reason i am insisting specialized programs and to only use functions is to eliminate the indeference in interface,, here only the program logic and how effective the algorithm is counts and not the silly graphics or user interface.. As a programmer it is very important that the programmer is good at algorithms, logics and the working of the program effectively... So these kind of contests will really test the programmer skills..(the contests i have proposed can be made harder..) And it is really challenging unlike other programs where it is already made and it quite easy to get the source.. Even if the programmer dosent copy the source the programmer can get the logic from already done pograms which i consider IT TO BE CHEATING.. wRITING A PROGRAM IN NO BIG DEAL BUT ARRIVING AT a solution is... take for example the nibbles game... Though i did not copy the game i got the logic from some sites which explain how to construct the game.. So this is some waht similar to cheating..(:):)) Here my solution finding skills were not used but just my programming syntax skill...

bye
vasanth

ygfperson
09-09-2002, 12:43 PM
ok. i see what you mean. but there's no reason that a card game contest can't be done. a lot of the stuff you're talking about is a.i., and card games fit right into that.

given a fairly random selection of cards in a solitaire game, organized in a regular solitaire fashion, where each card is represented by a unique ascii char, determine the best possible path to win the game.

too easy? too hard? this is, imho, hard enough to make it challenging, and easy enough to let most people take a crack at it.

any thoughts?

Klinerr1
09-09-2002, 06:56 PM
ill judge (i know 100% sure that ill get the scores in in time)

Klinerr1
09-09-2002, 06:58 PM
Originally posted by moi
what is 52-pickup??????

also known as cowboys and indians (the cards are the indians) the cowboys gotta round them up.

vasanth
09-10-2002, 04:58 AM
Ok this contest is a good one.. Quite hard i should say and really challenging... I am in.

ygfperson
09-10-2002, 01:25 PM
ok. the due date is 2 weeks from today...midnight on the 24th.

i'll post the updated thread later today. basicly:

there will not simply be an array of cards to choose from, because that would make cheating very easy. there will be arrays of cards, showing only the ones that are facing up. (the ones facing down are invisible to the programmer.)

card_array[0][0] might contain the card on the top of pile 1. card_array[1][1] might contain the second card down from the top of pile 2.

so it's: int card_array[pile][card in pile going from top downward]
0-6 will be the normal solitaire piles. pile 7-10 will be the ones on the top where you put them last. pile 11 will be the discard pile, which would show the card just served off the deck. all piles are read from left to right. cards 0-12 are diamonds, the next 13 are hearts, the next 13 are clubs, and the last 13 are spades. (so, red cards are 0-25, the black cards are 26-51). this is a global variable. (i would've made it local, but that's too much work for something like this.) if a card turns up -1, that means that card does not exist, and you've probably gone to the end of that pile. (if the first card in a pile is -1, that means that pile is empty.

some functions:
int new_card(void);
this function takes a card from the serving pile (i forget the technical name) and places it in the discard pile. you can assume that each time it's only one card this is happening to. the value returned will be either the value of the card returned (cards are valued 0 to 51) or -1 if it has reached the end of the pile. it will automaticly reset if it's at the end of the pile.

int move_card(pile number card is in, pile number card is moved to, number of cards moved);
this returns a 1 if successful, and a 0 for failure. reasons for failure include breaking the rules or incorrect pile numbers.

any possible functions i missed?

int make_best_choice(void);
inside it you will move cards, draw new cards, and basicly interact with the game so that you win. you are encouraged to use all the resources at your disposal to win, but it's impossible to peek. you can count cards that have already gone by, if you want to factor it into your decision.

after deciding the right move the program should call the move function. then everything is automatically updated and you go through the process again until you win or lose.

it's up to your program to decide whether or not to lose. a winning scenario is easy to spot, but a losing scenario requires that you concede defeat yourself. return a 0 for a defeat, and a 1 for a win.

questions? this message will be duplicated in the directions of the beginning post of the thread, and on the contest web site.

Driveway
09-10-2002, 02:24 PM
Those are much better rules.

ygfperson
09-12-2002, 05:02 PM
so everyone's satisfied? good. i'll update the contest web site asap. it still works, mind you, but its information is out of date. if you want to submit anything, go to the web site and submit it. or you can e-mail it to me.

Troll_King
09-12-2002, 05:36 PM
It's not a great idea to actually specify how the game is to be implimented, that should be up to the programmer. What I originally wanted to know is the specific behavior and general rules of the game that the contest designer was after, not how to write the program. The original idea was to make a card game, and that was too vague.

ygfperson
09-12-2002, 10:19 PM
there's still a lot of leeway. the variables and functions are only to allow me to quickly link my source code with any contestant's source code and create a working program. the subject, solving a game of solitaire, allows people to use their own creativity to find the best, most elegant solution.

if i went into too much detail suggesting how to write the program, i'm just helping any newbies figure out how to structure your program. outside of the functions and variables listed, you may use any standard libraries and your own code to do the job.

any other questions?

xds4lx
09-12-2002, 10:48 PM
That kinda makes the idea no fun. Id rather make the whole actual game. But im a judge so ill let my opions go. But what if someone decides to make the whole game? Can they just include an option to have the game solve itself to make it "fit" your criteria?

Troll_King
09-13-2002, 03:29 AM
I'll enter a contest comming up but not this one.Due to College and work, I think that 2 weeks is even too short of time. Obviously College takes precidence over any contests that go on here. I think that 3 week is in the order. In addition, I don't think that it's a great idea to use Windows libraries unless you use a library that is compatible on all platforms. There is only QT and Java. I can't see this happening though. Personally I don't even have MS Windows installed anymore.

ygfperson
09-13-2002, 12:34 PM
Originally posted by xds4lx
That kinda makes the idea no fun. Id rather make the whole actual game. But im a judge so ill let my opions go. But what if someone decides to make the whole game? Can they just include an option to have the game solve itself to make it "fit" your criteria?

i guess that would be fine. i don't see why anyone would want to spend the extra time, though.

In addition, I don't think that it's a great idea to use Windows libraries unless you use a library that is compatible on all platforms. There is only QT and Java. I can't see this happening though. Personally I don't even have MS Windows installed anymore.
i have never mentioned anything windows-specific.

anyway, i'm done altering this idea. if you want a new one, write up an idea thread or bump one you like, and wait for the next contest. we can't spend a week just fine-tuning an idea.

ygfperson
09-24-2002, 04:34 PM
since it looks extremely unlikely anyone else but vasanth is signing up, i'm giving him 1st place and stopping the contest now.

sorry for not notifying you over e-mail, vasanth, your address returned an error message. if you want to submit what code you have so far, i'll display it.

later today i'm starting up a new thread choosing a new contest. since the last 2 contests had little return, i'm going to strongly suggest a algorithm problem this time instead of a game. something even newbies can do, and experts can still excel at. something like a text compressing program.

i'm not forcing any topic, just strongly suggesting... :D
it'll still be democratic

Cshot
09-24-2002, 04:55 PM
Here's my code:

void main()
{
int x = 0;
here:
x++;
goto end;
end:
if(x < 10)
goto here;
return;
}

Yay. If nobody submits code, do I win by default? :D

ygfperson
09-24-2002, 05:05 PM
I'm sorry to say this, cshot, but...

For the first time, ever, your score is actually below zero. Zero would be no submitted entry. 0.00001 would be an intent to submit. That is.... crap. It's at most -5 points. The gotos and void main put you under the bottom and sealed your defeat. May you never code that piece again, if only to spare shame from your children and your children's children.

Of course, you could always submit it to Microsoft for review. They might give you a tidy price for it.

Cshot
09-24-2002, 05:33 PM
Damn. Maybe if I added self-modifying code, I'd score a bit higher.

moi
09-24-2002, 05:43 PM
Originally posted by Cshot
Here's my code:

void main()
{
int x = 0;
here:
x++;
goto end;
end:
if(x < 10)
goto here;
return;
}

Yay. If nobody submits code, do I win by default? :D

should have used gets()