TicTacToe with AI implemented via minimax algorithm
- Make AWS Lambda into HTTP API
- Build Frontend web with React JS
The function is deployed on AWS Lambda.
Request with the following body:
{
"state": "000000000",
"botIsX": 0 or 1
}
state represents the current board of the tic-tac-toe table.
Play | State Number |
---|---|
O | 1 |
X | 2 |
Empty | 0 |
For instance the board below would be represented with the following state string:
{
"state": "012020100"
}
botIsX represents whether the box is X or O. If the bot is playing as X value is 1, otherwise the value is 0.
{
"botIsX": 1
}
Response would look like the following:
{
"action": 5,
"status": "Success",
"error": null
}
action represents where the bot would play next. It will return -1 if there is an error.
status shows rather the request was successful or not.
error will show what the exact error is. The following are type of errors that can happen:
Errors | Expected |
---|---|
State Length Error | State should always be 9 digits long |
Invalid State Error | State should either be 0, 1, or 2 |
Invalid BotIsX Error | BotIsX should always be 0 or 1 |