Buy Me A Coffee

chess_interface_dart

Complete chess functionalities including FEN initialization, en-passant, checkmate and draw rules. This is a pure dart package for backend and doesn't include flutter components for front-end. Visit chess_interface for complete front-end package

Features

  • ✅ Built-in move validation for all standard piece types
  • 🔄 Supports en passant, castling, and pawn promotion logic
  • 📐 Interface-driven board interaction for flexible state management
  • ⏱️ Countdown stream for both players.

Getting Started

Add the package to your pubspec.yaml:

dependencies:
  chess_interface_dart:
    git:
      url: https://github.com/mryadavdilip/chess_interface_dart.git

OR

dependencies:
  chess_interface_dart: ^1.1.0

Then import the pure Dart API:

import 'package:chess_interface_dart/logical_interface/interface.dart';

Note: chess_interface_dart is backend/rules only and does not ship any Flutter widgets or assets.

Example

For a runnable example, see:

  • example/main.dart
  • example/README.md
import 'package:chess_interface_dart/arbiter/arbiter.dart';
import 'package:chess_interface_dart/logical_interface/interface.dart';
import 'package:chess_interface_dart/logical_interface/move_validator.dart';
import 'package:chess_interface_dart/logical_interface/position.dart';

void main() {
  final game = ChessBoardInterface(
    fen: 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
    timeLimit: const Duration(minutes: 10),
  );

  final arbiter = Arbiter(
    onGameOver: (gameOverBy) {
      print('Game ended: $gameOverBy');
    },
  );

  arbiter.countdownSpectator(game);
  arbiter.checkForGameEnd(game);

  // Example move validation + move.
  final from = Position(row: 6, col: 4); // e2
  final to = Position(row: 4, col: 4);   // e4

  if (MoveValidator.isValidMove(game, from, to)) {
    game.move(from, to);
  }
}

Move Validation

Use MoveValidator.isValidMove() to validate legal chess moves:

bool isValid = MoveValidator.isValidMove(ChessBoardInterface game, Position from, Position to);

It supports:

  • All standard chess moves
  • Pawn special rules
  • Castling logic (including history tracking)
  • En passant and double pawn pushes

Arbiter

Arbiter to handle events like game over, time out and pawn promotion:

And more..

File Structure

  • arbiter.dart – Game over, timeOut, and promotion handler
  • interface.dart – Board interaction interface
  • move_validator.dart – Move legality checker
  • piece.dart – Piece model and asset loader

Contributing

Contributions are welcome! Please open issues and pull requests to help improve this Package.

License

MIT License. See LICENSE for details.