OthelloServer is a backend API for playing Othello (Reversi) online. It is built using Node.js, Express, and MySQL (via Sequelize ORM).
- Create and manage Othello (Reversi) game sessions.
- Validate and process legal moves.
- Store game states in a MySQL database.
- REST API for interacting with the game.
Ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/luisplata/Reversi_Backend.git cd Reversi_Backend -
Install dependencies:
npm install
-
Set up the environment variables:
Create a.envfile in the root directory and configure it with your database settings:DB_NAME=your_database_name DB_USER=your_database_user DB_PASSWORD=your_database_password DB_HOST=your_database_host DB_PORT=3306
-
Run database migrations (if needed):
node index.js
- Production Mode:
npm start
- Development Mode (with auto-restart using nodemon):
npm run dev
To check for linting issues:
npm run lintTo auto-format the code:
npm run formatPOST /gameCreates a new Othello game with the initial board state.
{
"id": 1,
"board": [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 2, 0, 0, 0],
[0, 0, 0, 2, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
],
"currentPlayer": "black",
"status": "ongoing"
}GET /game/:idFetches the current game state.
{
"id": 1,
"board": [[...]],
"currentPlayer": "black",
"status": "ongoing"
}GET /game/:id/valid-movesReturns a list of valid moves for the current player.
{
"validMoves": [
{ "x": 2, "y": 3 },
{ "x": 3, "y": 2 },
{ "x": 4, "y": 5 },
{ "x": 5, "y": 4 }
],
"player": "black"
}POST /game/:id/moveExecutes a move for the current player.
{
"x": 3,
"y": 5
}{
"id": 1,
"board": [[...]],
"currentPlayer": "white",
"status": "ongoing"
}GET /game/:id/statusReturns whether the game is ongoing or finished.
{
"status": "ongoing",
"current_turn": "black"
}Pull requests are welcome. For major changes, please open an issue first.
This project is licensed under the GNU General Public License. See LICENSE for more details.
Developed by Luis Plata (PeryLoth)
GitHub: @luisplata