An unbeatable game of tic tac toe.
A simple game. Or is it!? Try your skill at http://perfecttictactoe.herokuapp.com/
Along with the game there is a "Tic Tac Toe" API, simply post a JSON request indicating the current board state and the "turn" piece. The response will be an updated board state.
API End Point
POST /api/v2/playExample Request
{
"player_piece":"o",
"opponent_piece":"x",
"board":[
{
"id":"top-left",
"value":""
},
{
"id":"top-center",
"value":""
},
{
"id":"top-right",
"value":"x"
},
{
"id":"middle-left",
"value":""
},
{
"id":"middle-center",
"value":"o"
},
{
"id":"middle-right",
"value":""
},
{
"id":"bottom-left",
"value":"x"
},
{
"id":"bottom-center",
"value":"o"
},
{
"id":"bottom-right",
"value":"x"
}
]
}Example Response
Note the addition of "o" in the top-center and that the player and opponent has switched. Also any spaces in a "winning" line are indicated as such with the attribute "winning_space": true.
{
"status":"success",
"data":{
"player_piece":"x",
"opponent_piece":"o",
"board":[
{
"id":"top-left",
"value":""
},
{
"id":"top-center",
"value":"o"
},
{
"id":"top-right",
"value":"x",
"winning_space": true
},
{
"id":"middle-left",
"value":""
},
{
"id":"middle-center",
"value":"o",
"winning_space": true
},
{
"id":"middle-right",
"value":""
},
{
"id":"bottom-left",
"value":"x"
},
{
"id":"bottom-center",
"value":"o",
"winning_space": true
},
{
"id":"bottom-right",
"value":"x"
}
]
}
}###Development This game was built on top of my sinatra-boilerplate app. Specifics to that boilerplate can be found at its repository.
###Notes on Testing Tests are best executed using the rake tasks:
rake testrake systemrake js (Run javascript unit tests via jasmine on phantomjs.)rake build_full (For all the tests.)This is due to conditional configuration based on test type to improve the execution speed. You may run tests directly with the rspec command but this will include all dependencies.
To start a development server and guard simply run:
bundle exec guard
To start a jasmine server to view the results of javascript tests in the browser run:
bundle exec rake jasmine
###Room for Improvement
##License
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .License located in LICENSE.md
##Change Log
###2.1.1 - March 28, 2015
###2.1.0 - January 23, 2014
###2.0.0 - January 10, 2014
No open issues yet, or sync has not completed.