19
2
There is a game called Get Home that is played on the a chess board. In this game there is a single piece that is moved by both players in turns. There are some rules to how the piece can be moved. On a turn a player must make one of the following moves for positive n.
n spaces up
n spaces to the left
n spaces up and to the left (a diagonal)
The player who moves the piece into the top left corner of the board wins the game.
Now we will define the concept of a losing square. In this video (from where I got the idea) a losing square is defined as a square on which, any player starting their turn will be forced to make a move allowing their opponent to force a win. The simplest example of a losing square would be the square at (1,2). A piece at (1,2) can move to any of the following places.
All of which have a direct path to victory for the next player.
It also follows that any square that has a one move path to a losing square allows the player starting on that square to force a win. This means that any square that is not one move away from a losing square is also a losing square.
This brings us to this rather neat definition of a losing square:
A losing square is a square from which no move can arrive on another losing square and (0,0) is a losing square.
Task
Given the coordinates of a square on an arbitrarily sized chess board determine if it is a losing square. Output two values one for losing squares and one for others.
This is code-golf so answers will be scored in bytes with less bytes being better.
Test Cases
Here are all the losing squares on a regular 8 by 8 chess board (marked with 0).
0 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1
1 0 1 1 1 1 1 1
1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 0
1 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 1
Here is an image of a 100 by 100 board with losing squares marked in black (each square is 2 pixels by 2 pixels).
2I don't think there are enough test cases to find a pattern.I think I see a pattern, but I couldn't say for sure. Is
10, 7
a losing square? Is10, 8
? What about15, 11
? – James – 2017-08-17T17:04:54.880@DJMcMayhem I will update with an image showing the pattern. The current test cases are there to verify answers. I believe you are correct in your assertions of further losing squares. – Post Rock Garf Hunter – 2017-08-17T17:12:38.053
1@WheatWizard Do you mind making the image a bit larger? – Erik the Outgolfer – 2017-08-17T17:27:14.277
@EriktheOutgolfer Its now 100 by 100, is that better? It takes a while to do this because I'm making the image by hand. – Post Rock Garf Hunter – 2017-08-17T17:31:17.123
1@WheatWizard I meant larger pixels...e.g. 5x5 pixels instead of 1x1, possibly some grid too if not too hard (btw thanks for the 100x100) – Erik the Outgolfer – 2017-08-17T17:32:11.100
@EriktheOutgolfer I've made each pixel 2x2. I felt 5x5 was way too large. Unfortunately I am not skilled enough with gimp to make a grid. – Post Rock Garf Hunter – 2017-08-17T17:36:37.270
Correction: this is closely related to https://codegolf.stackexchange.com/q/95604/194 , but that's a heuristic rather than an exact question.
– Peter Taylor – 2017-08-17T17:36:43.1172Also related (return optimal move or signal that the position is losing). – Zgarb – 2017-08-17T17:42:55.097
Is the "arbitrary size" allowed to be limited by floating point inaccuracies (i.e. if we are using a square root or a floating-point golden ratio) or must we really support arbitrary size (up to physical limitations) if our language supports arbitrarily large integers? – Jonathan Allan – 2017-08-17T19:11:34.353
@JonathanAllan I don't know at the moment if you can give me a bit to think it over I can make a binding ruling. But until I permit it I will say it is not allowed. Is there a meta about floats? This seems to be a common issue, if there is one I'll go with the consensus. – Post Rock Garf Hunter – 2017-08-17T19:16:07.720
1I think it is normal to allow floating point inaccuracies to hinder performance even with arbitrarily large integer capability... – Jonathan Allan – 2017-08-17T19:30:39.727
I don't know about the meta consensus, but a reasonable argument to allow it was given to me by Dennis here for a similar task.
– Jonathan Allan – 2017-08-17T19:35:22.993@WheatWizard I believe the consensus is approximately that the algorithm should work if the language didn't have limitations. So an answer which says (0,0) is a losing square and all other inputs are not, with the justification being "The language doesn't support integers, only bits" would be invalid, but if an algorithm that works for arbitrary numbers but is implemented in a language that only supports 8-bit integers would be valid. – Kamil Drakari – 2017-08-17T19:35:29.220
@JonathanAllan I don't think Dennis' argument caries over here but I will allow it. So long as answers work for values under 500. – Post Rock Garf Hunter – 2017-08-17T19:46:17.140
@WheatWizard Here is the relevant post in forbidden loopholes. Perhaps concluding from there that floating point inaccuracies don't need to be handled unless specifically relevant is a stretch, but it indicates that answers that would need more than trivial modification if their language suddenly improved the data type are invalid and otherwise you can keep the limits to what your language supports
– Kamil Drakari – 2017-08-17T19:46:26.743Strangely related – xnor – 2017-08-17T21:34:18.393
I'm not sure how to interpret the task: "Output two values one for losing squares and one for others." Wouldn't the output simply be yes/no? Oh, I think I get it now, the output should be one of two possible values. You don't want us to output two values, only one. – Octopus – 2017-08-17T22:20:50.917
@Octopus Yes. This is a decision problem. Yes and no are fine. – Post Rock Garf Hunter – 2017-08-17T22:42:12.643
The name of this game in formal mathematics is Wythoff's game – boboquack – 2017-08-18T00:25:36.023