Poker Nim :
This game is played as a standard Nim Game, but players have option to
either substracting stones(like in standard Nim Game) or adding more
stones in a pile but not exceeding the original number of stones in that
pile. To ensure the game termination, each player is allowed to add stones
at most k(a finite number of) times.
Solution :
If you already have a winning position in standard Nim Game, then when
your opponent adds some stones to a pile, all you have to do is reverse
your opponent’s move by removing the exact number of stones he/she
added to that pile, thus restoring your winning position. Hence, this kind
of game can be viewed as standard Nim Game.
Conclusion :
The “not exceeding the original number of stones in that pile” part is not
neccesary in this game, one can have the same winning strategy despite of
the number of stones added by the opponent.
This type of Nim Game where players can add stones is called Bogus Nim.
Coding Part :
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, k;
cout << "Enter Number of Piles : ";
cin >> n;
cout << "Enter Maximum Number of Times an Individual Player Can add Stone : ";
cin >> k;
int a[n], xor_sum = 0;
cout << "Enter Number of Stone in Each Pile : ";
for(int i=0;i<n;i++)
{
cin >> a[i];
xor_sum ^= a[i];
}
if(xor_sum > 0)
cout << "First Player Win." << "\n";
else
cout << "Second Player Win." << "\n";
return 0;
}
Comments
Post a Comment