All GET requests, very simple, designed for intro students to build a GUI with Greenfoot, if given sufficient scaffolding
Only 4 commands: newgame, move, state, ai
Normally, newgame, move, and ai would be POST requests instead of GET requests, but everything is simplified to make it easier for intro students to test out the server.
/tictactoe/newgame?user=username
JSON response looks like this:
{
"grid": [
" ",
" ",
" "
],
"currentPlayer": "X",
"winner": null,
"gameOver": false
}/tictactoe/move?user=username&row=0&col=0
Make a move by putting an X at row 0, col 0 (top left)
If the move is illegal (out of bounds or something is already there) returns HTTP status code 400 (BAD REQUEST) with an error message.
The server responds with JSON that includes the move the player just made, plus a move by the AI opponent.
The JSON response might be:
{
"grid": [
"X ",
" O ",
" "
],
"currentPlayer": "X",
"winner": null,
"gameOver": false
}/tictactoe/state?user=username
Give the current game state for username. Responds with JSON, for example:
{
"grid": [
"XOX",
"XOO",
"X "
],
"currentPlayer": "O",
"winner": "X",
"gameOver": true
}or
{
"grid": [
"XOX",
"XOO",
"OXO"
],
"currentPlayer": "O",
"winner": "Tie",
"gameOver": true
}/tictactoe/ai/[random|smart]?user=username
Sets the AI player that player username will play against to either smart (always makes the best move) or random (plays randomly).
The default is random.
Responds with 400 BAD REQUEST and an error if the opponent parameter is anything else.