TDD Kata (3): TaTeTíTomek

Anterior Post  
Siguiente Post 


El sábado pasado estuve participando del Google Code Jam. El ejercicio A fue TicTacToeTomek:


https://code.google.com/codejam/contest/2270488/dashboard


Problem

Tic-Tac-Toe-Tomek is a game played on a 4 x 4 square board. The board starts empty, except that a single ‘T’ symbol may appear in one of the 16 squares. There are two players: X and O. They take turns to make moves, with X starting. In each move a player puts her symbol in one of the empty squares. Player X’s symbol is ‘X’, and player O’s symbol is ‘O’.

After a player’s move, if there is a row, column or a diagonal containing 4 of that player’s symbols, or containing 3 of her symbols and the ‘T’ symbol, she wins and the game ends. Otherwise the game continues with the other player’s move. If all of the fields are filled with symbols and nobody won, the game ends in a draw. See the sample input for examples of various winning positions.

Given a 4 x 4 board description containing ‘X’, ‘O’, ‘T’ and ‘.’ characters (where ‘.’ represents an empty square), describing the current state of a game, determine the status of the Tic-Tac-Toe-Tomek game going on. The statuses to choose from are:

  • “X won” (the game is over, and X won)
  • “O won” (the game is over, and O won)
  • “Draw” (the game is over, and it ended in a draw)
  • “Game has not completed” (the game is not over yet)

If there are empty cells, and the game is not over, you should output “Game has not completed”, even if the outcome of the game is inevitable.


Se nos da un archivo de entrada con distintas posiciones de tablero, y tenemos que producir una salida diciendo si X ganó, O ganó, empate, o todavía falta completar el juego.


Lo resolví usando TDD, y pueden ver el resultado en:


https://github.com/ajlopez/TddOnTheRocks/tree/master/TicTacToeTomek


Y la historia, prácticamente con commits por tests, en:


https://github.com/ajlopez/TddOnTheRocks/commits/master/TicTacToeTomek


Fue un ejercicio sencillo, y bien adaptado para TDD. Google me aceptó tanto la solución de un archivo de entrada pequeño, y de otro grande. Tengo que escribir sobre los otros ejercicios (B, C, D), que se complican por:


- Hay que resolver el problema en un tiempo adecuado


- El algoritmo a implementar no es evidente, o no se puede implementar “de a poco”, con “baby steps”, con lo que a veces hay grandes refactor


- A veces, dada la entrada, es difícil calcular la salida correcta, aún manualmente. Entonces, muchos de mis intentos fueron rechazados al subir el archivo solución a Google.


Nos leemos!


Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

This entry was posted in 10549, 11699, 1389, 17837, 5374. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>