othello-danyo
v1.0.4
Published
Othello utility with min/max and reinforcement learning algorithms
Downloads
11
Readme
Othello
Othello is a Node.js implementation of the classic board game Othello (also known as Reversi). This package includes game logic, a Minimax AI, and reinforcement learning capabilities.
Features
- Full Othello game implementation
- Minimax algorithm for AI decision-making
- Reinforcement learning (Q-learning) for AI training
- Board representation using FEN notation
Installation
You can install this package using npm:
npm install othello-danyoUsage
Importing the Module
const Othello = require('othello-danyo');Creating a Game Instance
const game = new Othello();
console.log(game.board); // Prints the initial boardChecking Valid Moves
const validMoves = game.getValidMoves(game.board, 1); // Get valid moves for player 1
console.log(validMoves);Making a Move
const [row, col] = [2, 3];
game.makeMove(game.board, row, col, 1);
console.log(game.board);Checking for Game Over
if (game.gameOver(game.board)) {
console.log("Game Over!");
}Using Minimax AI
const [bestRow, bestCol] = game.minimaxDecision(game.board, 1);
console.log(`Best move for player 1: (${bestRow}, ${bestCol})`);Training with Reinforcement Learning
const [qTableWhite, qTableBlack] = game.train(game.board, 1000);
console.log("Training complete!");Board Representation (FEN Notation)
The game board is represented as a string in FEN notation, where:
brepresents black pieceswrepresents white pieces- Numbers represent consecutive empty spaces
/separates rows- The last character indicates the current player(
borw)
Example:
"bbbbbbbb/bbbbbbbb/bbbbbbbb/bbbbbbbb/bbbbbbbb/bbbbbbbb/bbbbbbbb/wwwwwwww w"License
This project is licensed under the MIT License.
