15
3
Create a deterministic program to play nd tic-tac-toe with the other contestants.
Your program should work when n
(width) and d
(dimension number) are in these ranges:
n∈[3,∞)∩ℕ ie a natural number greater than 2
d∈[2,∞)∩ℕ ie a natural number greater than 1
n = 3; d = 2
(32 ie 3 by 3):
[][][]
[][][]
[][][]
n = 3; d = 3
(33 ie 3 by 3 by 3):
[][][]
[][][]
[][][]
[][][]
[][][]
[][][]
[][][]
[][][]
[][][]
n = 6; d = 2
(62 ie 6 by 6):
[][][][][][]
[][][][][][]
[][][][][][]
[][][][][][]
[][][][][][]
[][][][][][]
And so on.
Input:
Input will be to STDIN. The first line of input will be two numbers, n
and d
in the form n,d
.
After this will be a line consisting of coordinates specifying the moves that have been done. Coordinates will be listed in the form: 1,1;2,2;3,3
. The upper left corner is the origin ( 0,0 for 2D). In the general case, this list will be like 1,2,...,1,4;4,0,...,6,0;...
where the first number represents left-right-ness, the second up-down-ness, the third through the 3rd dimension, etc. Note that the first coordinate is X
s first turn, the second is O
s first turn, ....
Should this be the first move, the input will a number followed by 1 blank line.
For consistency, the input will always end with a newline. Sample Input (\n is newline):
10,10\n0,0,0,0,0,0,0,0,0,0;0,2,3,4,5,6,7,8,9,0;0,1,2,3,4,5,6,7,8,9\n
For first move:
10,10\n\n
where \n
is the newline character.
Output:
Output the move you wish to make in the same format as the input (a comma-separated list). An invalid move (ie one that has already been taken) will result in a loss for the game.
Note: You can use a random number generator, as long as you seed it with a value such that each run would be identical given the same conditions. In other words, the program must be deterministic.
Note: only valid moves are allowed.
Winning Games (If you've played enough multi-dimensional tic tac toe, this is the same.)
In order for there to be a win, one player must have all the adjacent squares along a line. That is, that player must have n
moves on a line to be a winner.
Adjacent:
- each tile is a point; for example (0,0,0,0,0) is a point in
d=5
- adjacent tiles are tiles such they are both points on the same unit d-cube. In other words, the Chebyshev distance between the tiles is 1.
- in other words, if a point
p
is adjacent to a pointq
, then every coordinate inp
s corresponding coordinate inq
differs from it by no more than one. Additionally, at least on coordinate pair differs by exactly one.
Lines:
- Lines are defined by vectors and a tile. A line is each tile hit by the equation:
p0 + t
<
some vector with the same number of coordinates as p0>
Simulation and Winning Conditions:
State in your answer if it is ready for grading. That is, clearly indicate whether or not your answer is done.
If your answer is marked as done, it will not be graded until at least 24 hours after the last edit to the code.
Programs must work offline. If a program is found to be cheating, it will automatically receive a score of
-1
, and will not be scored further. (How would anyone end up with their programs cheating?)If your program produces invalid output, it is immediately counted as a loss for the game
If you program fails to produce output after 1 minute it is immediately counted as a loss for the game. If necessary, optimize for speed. I don't want to have to wait an hour to test a program off of another.
Each program will be run against the other programs twice for each
n
in the range[3,6]
and eachd
in the range[2,5]
, once asX
and once asO
. This is one round.For each game a program wins, it gets
+3
to its score. If the program tied (1 win and 1 loss in a single round or ties for both games), then it gets+1
. If the program lost, then it gets+0
(ie no change).The program with the highest score wins. Should there be a tie, then the program with the least number of lost games (out of the tied contestants) wins.
Note: Depending on the number of answers, I may need help running the tests.
Good luck! And may the simulations run ever in your favor!
Win-checker challenge. <---- This challenge is to create programs to check if a certain game is won. It is very related to this challenge. – Justin – 2014-03-01T04:28:18.470
The [tag:self-contained] tag which you just invented doesn't add anything to the tag classification. I think you should remove it. – Howard – 2014-03-02T12:00:11.060
@Howard Okay. I noticed that a lot of questions had that restriction, so I thought a tag would be appropriate. – Justin – 2014-03-02T15:16:41.013
4A strange game. The only winning move is not to play. – german_guy – 2014-04-04T22:27:45.700
is (w,x,y,z) a valid output format? – alexander-brett – 2014-04-12T10:07:13.717
@ali0sha Please output with the given format; this is to give a master program ability to check the answers. – Justin – 2014-04-12T15:58:03.783
So just to be sure you want the input appended with another move? Or just the numbers without brackets? You've specified the input well but for output you just have 'output the move you wish to make' – alexander-brett – 2014-04-12T19:19:59.103
@ali0sha Sorry, I meant comma-separated like the input. Assuming you have some iterable, you could just do
','.join(list)
(this only works if each element in the list is a string.) – Justin – 2014-04-12T19:23:42.507Observation: The search space may be reduced by a factor of (2^d)*d!, which is the number of ways the dimensions can be mirrored and/or transposed. – MrBackend – 2014-05-23T13:01:16.963