Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

MIPS Chess Engine

A fully functional chess engine implemented in MIPS assembly language using only basic MIPS instructions (add, sub, addi, lw, sw, lb, sb, beq, bne, slt, sll, srl, j, jal, jr, syscall, etc.).

Features

  • Complete chess board representation
  • Coordinate move input (e2-e4, g1-f3, etc.)
  • Move parsing and validation
  • Castling, en passant, and promotion support
  • Check and checkmate detection
  • Basic but functional AI opponent
  • Plays as Black (computer) vs White (human)
  • Standard chess rules implementation for all pieces

Requirements

  • A MIPS simulator such as SPIM, QtSpim, or MARS
  • Terminal access for text input/output

Quick Start

  1. Install a MIPS simulator (SPIM example shown below).
  2. Run the engine:
spim -file chess_engine.asm
  1. Enter moves in coordinate notation (e.g., e2-e4).

For a longer sample session, see EXAMPLES.md.

Usage

Running the Engine

You can run this chess engine using SPIM (MIPS Assembler and Runtime Simulator):

spim -file chess_engine.asm

Playing Chess

The engine runs in text-only mode with no visual board display. You interact with the engine through text-based input and output only.

Input Format

Enter moves in coordinate format (from-to) to match the engine output:

  • e2-e4 - Move a piece from e2 to e4
  • g1-f3 - Move the knight from g1 to f3
  • f1-b5 - Move the bishop from f1 to b5
  • e1-g1 - Castle kingside
  • e1-c1 - Castle queenside

Note: The engine validates that the piece at the source square can legally move to the destination square.

Example Session

$ spim -file chess_engine.asm

MIPS Chess Engine
==================

White's move: e2-e4

Black's move: Computer plays: e7-e5

White's move: d2-d4

Black's move: Computer plays: d7-d5

White's move: c2-c3

Black's move: Computer plays: c7-c5

White's move: [continue playing...]

The game proceeds with text-based input/output only. No visual board is displayed - you track the game state mentally or on a physical board.

Repository Layout

  • chess_engine.asm: MIPS chess engine implementation
  • test_chess.sh: Static checks and usage hints
  • EXAMPLES.md: Extended usage examples

Implementation Details

Board Representation

  • 8x8 board stored as a 64-byte array in memory
  • Each square contains a piece code (0-12)
    • 0 = empty
    • 1-6 = White pieces (Pawn, Knight, Bishop, Rook, Queen, King)
    • 7-12 = Black pieces (Pawn, Knight, Bishop, Rook, Queen, King)

AI Strategy

The computer uses a simple evaluation function based on:

  • Piece hierarchy (prefers higher-value pieces)
  • Captures (small bonus)
  • Greedy algorithm (picks highest value move available)

Constraints

This implementation uses only basic MIPS instructions as specified:

  • Arithmetic: add, sub, addi
  • Logic: and, andi, or, ori
  • Shift: sll, srl
  • Memory: lw, lh, lb, lbu, sw, sh, sb
  • Comparison: slt, slti
  • Branch: beq, bne
  • Jump: j, jal, jr
  • System: syscall

Note: The code uses pseudo-instructions like blt, bgt, bge, ble for readability. These are automatically expanded by SPIM into basic instructions (slt followed by beq/bne). All pseudo-instructions can be manually expanded if needed for assemblers that don't support them.

Known Limitations

  • AI is basic (material-based evaluation only)
  • No visual board display

Testing

A test script is provided:

./test_chess.sh

This will verify the assembly syntax and provide instructions for manual testing.

Technical Notes

  • The engine parses coordinate input for pawn and piece moves
  • Move validation enforces legal moves including special rules
  • The AI evaluates moves based on captures and piece advancement
  • All game state is maintained in MIPS memory (data segment)
  • No external libraries or advanced features are used

Future Enhancements

Possible improvements:

  • Improved AI with positional evaluation
  • Move history and undo functionality
  • Save/load game state
  • Better move notation support

Author

Created as a demonstration of a functional chess engine using only basic MIPS assembly instructions.

About

A text-based chess engine in MIPS assembly with legal-move validation, special moves, check detection, and a basic computer opponent.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages