Skip to content

davidjohnson50/pandemic-chess-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pandemic Chess BASIC

A small chess program written in GW-BASIC during the pandemic, with a later QB64 / FreeBasic-compatible version.

This is a personal historical/programming project rather than a modern chess engine. The goal was to write a complete playable chess program from scratch in BASIC, including legal move handling, castling, en passant, pawn promotion, opening books, alpha-beta search, simple move ordering, and a basic evaluation function.

Why GW-BASIC?

The original version was written in GW-BASIC for several reasons:

  1. GW-BASIC is now open source, which made it interesting to revisit a classic programming environment.
  2. Writing the program in GW-BASIC helped avoid leaning on someone else's chess implementation.
  3. The constraints were part of the challenge: line numbers, global variables, GOSUB / RETURN, and a non-recursive minimax routine.
  4. A text-only interface kept the project focused on the chess logic rather than graphics.
  5. The project was simply a test of whether a working chess program could be written this way.

Files

  • PANCHESS.BAS — original GW-BASIC version.
  • PCHESS32.BAS — QB64 / FreeBasic-compatible version. The DEF FN calls from PANCHESS.BAS were rewritten for compilation.
  • MYBOOK.TXT — opening book for Black.
  • WMYBOOK.TXT — opening book for White.
  • LICENSE — repository license.

GWBASIC.EXE is not included in this repository. The original interpreter is available from Microsoft's open-source GW-BASIC release and related community builds.

Running the Program

The original GW-BASIC version can be run with a GW-BASIC interpreter. It may be slow under DOSBox. Running under FreeDOS or similar environments may provide a better experience.

The PCHESS32.BAS version is intended for compilation with QB64 or FreeBasic. For FreeBasic, use QB compatibility mode, for example:

fbc -lang qb PCHESS32.BAS

Program Features

The program includes:

  • non-recursive minimax search
  • alpha-beta pruning
  • simple move ordering
  • a simple quiescent-search extension
  • simple passed-pawn evaluation
  • basic king-and-rook versus king mop-up logic
  • castling
  • en passant
  • pawn promotion to queen
  • optional opening-book use

The search depth increases once the board material drops below a chosen value. This allows deeper searches later in the game while keeping move times more reasonable.

Evaluation Notes

The program uses Tomasz Michniewski's simplified piece-square tables as a starting point:

It also uses endgame pawn and rook tables from the PeSTO evaluation approach, with values scaled by a factor of 1.5:

Commands

The main commands in PANCHESS.BAS are:

Command Meaning
DEPTH Set the initial search depth.
SWAP Swap sides with the computer. Repeated use allows the computer to play itself.
WHITE Set White as the side for the next entered move.
BLACK Set Black as the side for the next entered move.
EDIT Edit the board manually.
CLEAR Clear the board.
LOAD / SAVE Load or save a board position.
SUGGEST Ask the program to suggest a move for either side.
XMOVE Move a piece directly without invoking the AI.
EXIT Quit the program.

Board Editing

When using EDIT, pieces are entered by piece index and board position.

White pieces use negative values:

Piece Value
White pawn -1
White knight -2
White bishop -3
White rook -4
White queen -5
White king -6

Black pieces use positive values:

Piece Value
Black pawn 1
Black knight 2
Black bishop 3
Black rook 4
Black queen 5
Black king 6

An empty square is entered as 0.

Examples:

-3,C4   places a White bishop on C4
4,A5    places a Black rook on A5

Sample Game

The following sample game was played with PANCHESS.BAS as Black at depth 4. The opponent was ChatGPT playing White.

PANCHESS PLAYS BLACK, DEPTH=4
E2E4 B8C6 G1F3 G8F6 B1C3 E7E6 D2D4 F8B4 F1D3 E8G8 E1G1 B4C3 B2C3 D8E8
E4E5 F6G4 H2H3 G4F2 F1F2 A7A6 C1A3 D7D6 E5D6 E8D7 D6C7 F8E8 D3A6 A8A6
D1D3 A6A3 F2E2 D7C7 D3E3 C7D6 E3E6 E8E6 E2E6 D6E6 A1E1 E6D7 C3C4 A3A2
E1B1 A2C2 B1B7 C8B7 F3G5 C6D4 G5F7 D4F3 G2F3 D7D1 CHECKMATE!

This game is not intended as a benchmark or rating estimate. It is included as a simple demonstration that the GW-BASIC version can play complete legal games, find tactical continuations, coordinate active pieces, and finish with mate.

License

See LICENSE.

About

A small GW-BASIC chess engine with alpha-beta search, opening books, and a QB64/FreeBasic-compatible version.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors