Simple games on comp

Hello.
I'd like to get some hints for a game. I'm not getting how to start with the problem:

Matchstick game that comp should win always.
Out of 21 matchsticks initially user gets to pick 1-4 sticks first. Then is comp's turn to pick, randomly. Whoever picks last, loses.

Also, please guide me for making a prog for towers of hanoi with n discs.

Thanks for reading the problems (and answering, if possible).
Last edited on
At first you must find winning and losing conditions formula.
Also, you know if the player plays right they will always win...so I am asumming you mean if the player messes up then the computer will always win. Other then that, do what Hazer said.
for the hanoi...You can use recursive function.If you know for n-1,you can know for n.look at this code(it's C code from a quite old book)

1
2
3
4
5
6
7
8
9
10
11
void hanoi (int n,int a,int b,int c)
{
if(n==1){printf("disc 1 from:%c on %c",a,b);
getchar();
return;
}
hanoi (n-1,a,bc);
printf("disc %n from %c to %c:",n,a,b);
getchar();
hanoi (n-1,c,b,a);
}


Last edited on
Topic archived. No new replies allowed.