# Output the correct move as per the XKCD tic-tac-toe cheetsheet! [closed]

## Overview

This is the XKCD tic-tac-toe cheetsheet: It's rather big, I know. But it's also your most valuable resource in your challenge.

## The challenge

Create a program (in your language of choice) that uses the Optimal Move Cheatsheet (henceforth OMC) to output the optimal move when given a sequence of moves.

## The input

Your program will be fed a series of moves in the following fashion:

A3 A2 B2 C2 ...


Where the first combination is always X, the second O, and so on. The letter is the Y coordinate (A-C, A at the top) and the number is the X coordinate (1-3, 1 at the left).

You may assume that the given combination is following the OMC's suggestion for each move at least for the player asking for a recommendation. You can also assume that the input will never be null (at least one move has been made). You must:

1. Figure out whether the next move is for X or O (you don't need to output this)
2. Use the OMC to decide the next move
3. Print the next move in the standard format A3

## Optional:

You may also include the player's chance of winning (as a percentage) for 50 character discount on your score.

• Dec 16 '13 at 4:54
• "The letter is the Y coordinate, and the number is the Y coordinate". Also, do we have to use that sheet, or can we use a different method for optimal moves? Also, your question is a bit confusing. How are we supposed to find the next move if it is already given for us? What is the "percentage chance" bit? Also, should this be tagged code-golf? Dec 16 '13 at 5:49
• @Quincunx Ah! I forgot to fix the Y, Y thing in my edit, and now it would be a minor edit. I think, based on the premise of the question, alternate choices for optimal moves are not valid here. The "percentage chance" is probably the percentage of end-game scenarios from the current position (presuming the player takes the output move) in which the player can win. For example: A1, C3 should return A3 (100%).
– Iszi
Dec 16 '13 at 21:40
• Myself, I'd have made the positions simply 1 through 9. Top: 123, Middle: 456, Bottom: 789. But I'm not sure whether breaking the X/Y coordinates out might actually help things more than I think.
– Iszi
Dec 16 '13 at 21:52
• I'm not sure what's not clear here. Maybe we need to put this on hold while the bugs get worked out in the Sandbox? @Quincunx Only the moves of the current player are assumed to follow OMC. So, any input where X is next to move will start with A1. Any input where O is next to move will start with XY B2 (where XY is any of the possible first moves for X) except for B2 A1. Figuring out whose turn it is is simple. Just take the count of moves in the input, mod 2. Remainder of zero, it's X's turn - remainder of 1, it's O's.
– Iszi
Dec 17 '13 at 16:01