**PROBLEM LINKS:**

**DIFFICULTY:**

DIFFICULT

**EXPLAINATION**

The chess-game can be considered to two independent chess games, where in first only a knight is present and the queen in other.

Now each game is equivalent to single nim heap in the nim game.

Now we will calculate the grundy values for each game interdependently (which is the minimum excluded value, mex, for each position).

For Knight game, where knight is at (x, y),

grundyKnight(x, y) = mex(grundyKnight(x-1, y-2), grundyKnight(x-2, y-1))

Similarly for Queen game, with queen at (x, y)

grundyQueen(queen) = mex( grundyQueen(x-i, y), grundyQueen(x-i, y-i), grundyQueen(x, y-i)) , where 1 <= i <= 50

So the grundy value of both game combined (original game) is the nim sum of both games.

grundy(knight-game + queen-game) = grundyKnight(knight-position) xor grundyQueen(queen-position)

Since, according to sprague grundy theorem, the game can be won if grundy value is a positive value.