Question
How to handle a single player game with computer using C program.
Please suggest some of the concept for which i can implement it in my program.Thanks.
All Answers (9)
-
Please elaborate. -
I am doing a Game project in C program in which a user can play the game with computer.In otherwords, first the user will enter the value and according to that the computer enter the value but i can't understand that how the computer will give the value.please suggest me some idea.Thanks.
-
From what you described, you can take two approaches
1. Generate the computer's move randomly
2. Generate the computer's move based on the move made by human. If you want the computer to apply its best efforts to win, you must make an "intelligent" agent. For this, you need to go through the classical search techniques of Artificial Intelligence. In that your program will be searching through an immense set of possible moves to select the best one.
Hope that makes sense. -
But i don't know Artificial Intelligence.So is there any simple way to handle it and if it is there then please provide me some article or pdf etc.Thank you.
-
If you don't want to program an intelligent game than just use some random approach to generate the next move.
You can simply do it by generating a random number in the desired range and the encoding it into the computer's next move. -
It seems like you have an idea, even though you didn't explain it very well, but you lack the skill to implement it. Consider working on you skills first (C, AI or whatever) before you jump into game development (or any software development at all).
-
If you want to mainly improve on your C skills, try something very simple - such as rock, scissors, paper or tic-tac-toe.
Tic-tac-toe is nice for implementing recursion (such as a tree of possible moves) and the evaluation of each move. -
Hi, Stefan.
I got it what you want to say but my main goal is to implement a single player game with computer in C program.
so, if you know some technique then please share with me.
Thank you.
Regards,
Salman. -
You can arrange all possible moves (independent of a single game) in a tree, the trunk being the game before the first move. Each node traversed represents one move. At the "leafs", the game is either a win, a loss or a draw for the computer side; since a win or loss can happen before all fields are filled, the tree is somewhat asymmetrical.
Obviously, not all possible moves are of equal quality, so the tree should be marked from bottom to top:
As soon as the computer side arrives at a move choice where one of the moves leads to a win, this is a "1 round sure win".
This can be propagated into a 2 round sure win:
If one move choice leads - regardless of the opponent's moves - always to a node of a one-round sure win, you have a two-round sure win. And so on.
Vice versa with a sure loss.
The main effort is properly calculating the tree. Then the CPU player just has to avoid moves (subtrees) which lead to a sure loss, take subtrees which lead to a sure win and you have a strong computer player.
Hope this helps - I won't go into more detail, it's your programming exercise.