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.

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 .

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

intsg(intx,inty){if((x==1&&y==1)){return0;/// (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{returngrandy_value[x][y];}set<int>s;for(inti=0;i<4;i++){intnewx=x+dx[i];intnewy=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));}}intmex=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]returngrandy_value[x][y];/// return grandy_value}

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

## Chessboard Game, Again!

You are viewing a single comment's thread. Return to all comments →

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 .