I have built a Canasta card game in MS-DOS and I am now stuck on how create a computer competitor. What I need is someone to tell me how the computer should go about his turn in a four-handed partnership game. This game requires two cards to draw and two Canastas to go out. Hoyle rules of the game.
- 2 Contributors
- forum1 Reply
- 61 Views
- 2 Days Discussion Span
- comment Latest Post by Nutster
Is that your address at the end? Please do not include that kind of thing in these forums. That can just be asking for troule. You are already registered and that is enough identification.
I have written computer players for other games before, but I do not know Canasta. For most card games, you will need a part of your program that determines if the move being made is valid in context, which is used for any player, human or computer. The other part is your computer player.
You will need to write out the way that a player of the appropriate level (or as you would play, to keep it simple). The first set of rules you want to include is what constitutes a valid move. This is the same set of rules as the computer already has to prevent humans players from making an invalid move. Mind you, the code for "prevent an invalid move" and "make a valid move" can look considerably different.
For each situtation that the computer player finds itself in, how do you want it to play? You want to define these as general rules as much as possible, and use as few specific situations as possible; this will just make your program smaller and easier to write.
Make sure you have a final rule: if all else fails, play randomly; determine all cards that could be played in this context, then pick one at random to play. This way your computer player is not left with nothing to do if you did not properly anticipate a particular situation.
Once you have written out all the rules and specific situations, then you can start coding the computer player. As you build up the computer player, you may want to just add a few rules (maybe starting with a minimum of how to make a valid move and play randomly) and see how well the computer plays. Generally, a computer player with only a few rules will be fairly easy to beat, and make some surprising moves, both bad and good. Use these play-test results to guide you in adding the next rule that the computer will consider. Generally, you want to add the most general rules first, and then narrow things down.
The more rules that are added, the slower your player will be. You may find that some rules you considered in your planning do not need to be added, or should be tweaked to get a better player.
Have fun building this project.