We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

# Chessboard Game, Again!

# Chessboard Game, Again!

+ 0 comments Too difficult for me

+ 1 comment A good one . If You understand grandy theorem of game theory , then it is very easy for you to solve recursively .When our possible moves from a co-ordinate of chess-board has been given .We can compute grandy-value recursively using the help of memoization .

My full solution here https://github.com/joy-mollick/Game-Theory-Problems/blob/master/HackerRank-Chessboard%20Game%2C%20Again!.cpp

Here is the part of my code to compute grandy value of every co-ordinate by given input .

int sg(int x,int y) { if((x==1&&y==1)) { return 0; /// (1,1) it is base case ,because from here there is no move,so grandy value of this state is zero } if(grandy_value[x][y]!=-1) /// if grandy value is already computed just return it , no need to calculate it { return grandy_value[x][y]; } set<int>s; for(int i=0;i<4;i++) { int newx=x+dx[i]; int newy=y+dy[i]; if(newx>=1&&newy>=1&&newx<=15&&newy<=15)///if newx and newy is beyond (1,1) then this recursion will be recursively run ,there is no end .So (1,1) should be the terminal point { s.insert(sg(newx,newy)); } } int mex=0; while(s.find(mex)!=s.end()) mex++; grandy_value[x][y]=mex;///assigning mex [not included minimum element in the set of grandy value of possible co-ordinates] return grandy_value[x][y];/// return grandy_value }

+ 0 comments What? A cell can contain more than one coin. Ok, when can not a player make a new move?

+ 0 comments this question is full of ambiguities.. who plays first? how can I know that?

+ 0 comments Created board using Grundy -- Time taking solution. But Works!

static int[][] chess= { {0,0,1,1,0,0,1,1,0,0,1,1,0,0,1}, {0,0,2,1,0,0,1,1,0,0,1,1,0,0,1}, {1,2,2,2,3,2,2,2,3,2,2,2,3,2,1}, {1,1,2,1,4,3,2,3,3,3,2,3,3,3,1}, {0,0,3,4,0,0,1,1,0,0,1,1,0,0,1}, {0,0,2,3,0,0,2,1,0,0,1,1,0,0,1}, {1,1,2,2,1,2,2,2,3,2,2,2,3,2,1}, {1,1,2,3,1,1,2,1,4,3,2,3,3,3,1}, {0,0,3,3,0,0,3,4,0,0,1,1,0,0,1}, {0,0,2,3,0,0,2,3,0,0,2,1,0,0,1}, {1,1,2,2,1,1,2,2,1,2,2,2,3,2,1}, {1,1,2,3,1,1,2,3,1,1,2,1,4,3,1}, {0,0,3,3,0,0,3,3,0,0,3,4,0,0,1}, {0,0,2,3,0,0,2,3,0,0,2,3,0,0,2}, {1,1,1,1,1,1,1,1,1,1,1,1,1,2,1} }; static String chessboardGame(int[][] coins) { int xor = 0; for (int[] Y : coins) { int x = Y[0]-1; int y = Y[1]-1; xor^=chess[x][y]; } if (xor == 0) return "Second"; return "First"; }

Load more conversations

Sort 15 Discussions, By:

Please Login in order to post a comment