# How to properly represent a tic tac toe board to a CNN?

I'm figuring out how to manipulate convolutional neural networks (CNN) in python and I want to apply this kind of NN to an agent player that plays tic tac toe. I know that's weird and the problem doesn't need some elaborate and complex solutions like CNN, but I'm using this environment just to learn better and compare with the training of a MLP that I implemented.

So, I'm trying to think about how to represent the board correctly as an input to the CNN. Unlike the chess board which we can think the input as 8x8x6 (8x8 as the 2d array representing the board and 6 channels which one representing the different pieces of the game), the tic tac toe is a bit more complicated for me because there are just one kind of piece. Is it possible and correct to represent the X and O as different pieces? Has anyone implemented something like this?

• I have implemented this in the past for tic-tac-toe however, I do not have the code right now. But, I can't find the code I sued to generate the ground truths, it was based off the perfect tic-tac-toe implementation. Writing all those iffs is quite time consuming. If you have code to generate ground truth values then I can append my CNN implementation to this problem. Commented May 18, 2018 at 2:45
• Hello @JahKnows, i've implemented a minimax player based on a static function that plays on an optimal way. Maybe with this you can help me. The code is a bit long and I would like to send you as an attachment. Commented May 18, 2018 at 11:54
• Hey @JahKnows, how did you choose the filters you used on your CNN? Commented May 20, 2018 at 23:17
• @Matteus Prandini, tuning hyper-parameters is always tough. In deep learning you want to have enough filters such that the function your network is approximating is sufficiently captured, but not so complex that you need huge (maybe unavailable) amounts of data to train it. I tend to start with 32 or 64 filters. Commented May 21, 2018 at 2:00
• @Matteus Prandini, if you can use your algorithm to produce a .csv file with the each row being an instance, and the column the board positions left to right and top to bottom (9 columns) and the tenth column who's turn it is, and the 11th column the position that should be played. From that dataset we can train this network. Commented May 21, 2018 at 2:02