[FREE/OS] Chess Extension — Full Chess Board with AI Opponent

[FREE/OS] Chess Extension — Full Chess Board with AI Opponent :collision: :heart_on_fire:

A complete chess extension for MIT App Inventor and Niotron with built-in AI opponent, full FIDE rules, and interactive board rendering.


Overview

This extension brings a fully functional chess game into your App Inventor projects. It includes a complete chess engine with all official FIDE rules, a built-in AI opponent with adjustable difficulty, and an interactive board with piece selection and move highlighting.

Whether you’re building a chess learning app, a chess puzzle trainer, or just want to add a chess game to your project — this extension handles everything out of the box.

Version: 1.0
Package: io.devxhorizon.chess
Price: Free and open source
Compatibility: MIT App Inventor 2, Niotron, Kodular, AndroidBuilder


Features

  • Complete FIDE chess rules — en passant, castling (kingside & queenside), pawn promotion, check, checkmate, stalemate
  • Draw detection — 50-move rule, threefold repetition, insufficient material
  • Built-in AI opponent using negamax search with alpha-beta pruning
  • AI difficulty is adjustable — depth 1 (beginner) to 6 (strong)
  • Interactive board — tap to select pieces, see legal moves, make moves by tapping
  • Move highlighting — last move is highlighted, check is shown with a red border
  • Board locks during AI’s turn — prevents accidental input while the AI thinks
  • FEN import/export — load and save positions using standard FEN strings
  • Undo move — undo your last move (undoes AI move too if AI is enabled)
  • Programmatic move making — make moves from blocks for puzzles or automation
  • Configurable colors — customize light squares, dark squares, selection highlight, and check indicator
  • Algebraic notation support
  • No external dependencies — pure Java, lightweight

How It Works

Setup

  1. Drag the Chess component (non-visible) to your screen
  2. Add an Arrangement (e.g., VerticalArrangement) where you want the board
  3. Call InitializeView with the arrangement in Screen1.Initialize

Playing

  • Tap a piece to select it — green highlight appears on the selected square
  • Legal moves are shown as small dots (quiet moves) or red rings (captures)
  • Tap a highlighted square to make the move
  • The board automatically detects check, checkmate, and draws

AI Mode

Set PlayAgainstAI to True and configure the difficulty:

  • AIDepth — search depth from 1 (fast, weak) to 6 (slow, strong). Default is 4.
  • AISide — which side the AI plays: 0 = Black (you play White), 1 = White (AI plays first), 2 = None (two-player mode)

When it’s the AI’s turn, the board locks and the AI thinks in the background. The AI’s move is highlighted automatically when it’s done.

AIDepth
AISide
PlayAgainstAI


Blocks

All Blocks

Methods

Block Description
InitializeView Mount the chess board into an arrangement
ResetGame229x30 Reset to starting position
LoadFEN215x55 Load a position from FEN string
GetFEN206x26 Export current position as FEN
UndoMove230x26 Undo the last move
PromotePawnTo271x55 Choose promotion piece (0=Q, 1=R, 2=B, 3=N)
Make a move programmatically
GetPieceAt241x76 Get piece at a specific row/column
GetLastMove248x26 Get the last move as square names
GetGameState261x26 Get full game state as a list
IsBlackTurn237x26 Check if it’s black’s turn
IsKingInCheck256x26 Check if king is in check
IsCheckmate247x26 Check for checkmate
IsStalemate239x26 Check for stalemate
IsDraw202x26 Check for any draw condition

Events

Block Description
OnPieceMoved334x85 Fired after any move is made
OnCheck222x85 A king was put in check
OnCheckMate259x85 Checkmate — game over
OnStalemate52x60 Stalemate — draw
OnDraw215x85 Draw occurred (repetition, 50-move, or insufficient material)
OnPawnPromoted87x85 Pawn reached last rank — call PromotePawnTo()
OnGameReset263x60 Game was reset
OnAIMove334x85 AI made a move

Properties

Block Description
PlayAgainstAI363x30 Enable/disable AI opponent
AIDepth290x30 AI search depth (1-6)
AISide277x30 Which side AI plays (0=Black, 1=White, 2=None)
LightSquareColor310x70 Light square color
DarkSquareColor310x70 Dark square color
SelectedSquareColor310x70 Selection highlight color
PerspectiveAngle310x70 Board tilt angle (0=flat, 30=max)

Example: Basic Chess Game

Here’s how to set up a basic chess game with AI:

Blocks explained:

  1. When the screen initializes, enable AI, set depth to 4, set AI to play Black, and initialize the board
  2. When a piece is moved, update a label with the move info
  3. When checkmate happens, show who won
  4. When a draw happens, show the reason

Demo AIA: Chess.aia (67.0 KB)


FEN Support

The extension supports full FEN (Forsyth-Edwards Notation) for position setup and export.

Load a position

LoadFEN("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1")

Export current position

GetFEN()  →  "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"

Starting position FEN

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

Supported Chess Rules

Rule Status
All piece movements :white_check_mark:
En passant :white_check_mark:
Castling (kingside + queenside, both colors) :white_check_mark:
Pawn promotion (Queen, Rook, Bishop, Knight) :white_check_mark:
Check detection :white_check_mark:
Checkmate detection :white_check_mark:
Stalemate detection :white_check_mark:
50-move rule :white_check_mark:
Threefold repetition :white_check_mark:
Insufficient material draw :white_check_mark:
Legal move filtering (pins, discovered checks) :white_check_mark:

AI Details :speech_balloon:

The built-in AI uses:

  • Negamax search with alpha-beta pruning
  • Quiescence search to avoid the horizon effect
  • Iterative deepening with 5-second time control
  • MVV-LVA move ordering with killer move heuristic
  • Piece-square tables for positional evaluation

The AI searches on a copy of the board, so the UI never flickers during computation. Touch input is disabled while the AI is thinking.


Open Source :collision:

The extension is fully open-sourced and was made with the vision to not only implement the chess game, but understand what is happening in the backend and under the hood.

Download

Download the latest .aix file from GitHub:
:backhand_index_pointing_right: https://github.com/HorizonXDev/Chess-Extension/releases/latest

Direct download: io.devxhorizon.chess.aix (64.8 KB)


Developed with :heart: by Horizon

1 Like