Original Post
Hi all, this is my first post though I've been browsing these forums for a long time. I've never really had anything to ask.
I'm sure there's a lot of you coders familier with the game of Nim. I'm going to make it as a basic first game, I'm doing a console version first so I can work out the kinks, and I've got it all working fine for two players, but it's playing against the computer I'm having trouble with.
The idea is to have the computer win every time. I've read a lot about xoring and have made a few attempts, but the computer doesn't always pick the right amount to take away.
ok, a, b and c are the piles of stones. Take is how much it should take. x is there to make things simpler. Here's a part of the code:
int a=3, b=5, c=8, take, x;
x = a^b^c;
if ((a^x) <= a) {
take = a^x;
take = a - take;
}
if ((b^x) <= b) {
take = b^x;
take = b - take;
}
if ( (c^(a^b^c)) <= c) {
cout << (c^x);
take = c - (c^x);
}
[edited by - Xalzar on May 10, 2004 2:57:41 AM]