# 08jun25 Software Lab. Alexander Burger

      PicoLisp Chess
      ==============

The PicoLisp 'chess' game is minimalistic. Nevertheless, it plays some slow
(though hopefully correct) chess.

It comes both as a CLI (text) version and as a web application. In addition, a
PilBox app (based on the web version) is available.

You can download it from https://software-lab.de/chess.tgz


   === CLI-Version ===

Start the CLI version as:

   $ pil chess/cli.l -main +
      +---+---+---+---+---+---+---+---+
    8 |<R>|<N>|<B>|<Q>|<K>|<B>|<N>|<R>|
      +---+---+---+---+---+---+---+---+
    7 |<P>|<P>|<P>|<P>|<P>|<P>|<P>|<P>|
      +---+---+---+---+---+---+---+---+
    6 |   | - |   | - |   | - |   | - |
      +---+---+---+---+---+---+---+---+
    5 | - |   | - |   | - |   | - |   |
      +---+---+---+---+---+---+---+---+
    4 |   | - |   | - |   | - |   | - |
      +---+---+---+---+---+---+---+---+
    3 | - |   | - |   | - |   | - |   |
      +---+---+---+---+---+---+---+---+
    2 | P | P | P | P | P | P | P | P |
      +---+---+---+---+---+---+---+---+
    1 | R | N | B | Q | K | B | N | R |
      +---+---+---+---+---+---+---+---+
        a   b   c   d   e   f   g   h

For a local installation, supply instead of "pil" the actual path like "./pil"
or "../pil21/pil".

The pieces are indicated by the letters 'K'ing, 'Q'ueen, 'R'ook, 'B'ishop,
k'N'ight and 'P'awn, with black pieces in angular brackets.

You can enter your moves with the field names (in lower case) for the "from" and
"to" positions:

: (go e2 e4)

Castling may be entered by just specifying the king's move:

: (go e1 g1)

To promote a pawn to some piece other than a queen, you can specify a class:

: (go h7 h8 +Knight)

To undo one or several moves, enter

: (go -)

and to redo them

: (go +)

To switch sides (and have the computer play against itself), call 'go' without
arguments:

: (go)

The initial board position can be restored with

: (main)

The global variable '*Depth' holds the maximal depth of the alpha-beta tree
search. It defaults to 5. You may change it to some smaller value for a faster
response, or to a larger value for a deeper search:

: (setq *Depth 7)

The same effect can be achieved by passing the desired depth as the first
argument to 'main':

: (main 7)

The second (optional) argument to 'main' is your color ('NIL' for white and 'T'
for black).

To setup some given board position, call 'main' with a list of triples, with
each describing:

   1. The field
   2. The piece's classes
   3. An optional flag to indicate that the piece did not move yet

: (main 5 NIL
   (quote
      (a2 (+White +Pawn) T)
      (b1 (+White +King))
      (d4 (+Black +King)) ) )
   +---+---+---+---+---+---+---+---+
 8 |   | - |   | - |   | - |   | - |
   +---+---+---+---+---+---+---+---+
 7 | - |   | - |   | - |   | - |   |
   +---+---+---+---+---+---+---+---+
 6 |   | - |   | - |   | - |   | - |
   +---+---+---+---+---+---+---+---+
 5 | - |   | - |   | - |   | - |   |
   +---+---+---+---+---+---+---+---+
 4 |   | - |   |<K>|   | - |   | - |
   +---+---+---+---+---+---+---+---+
 3 | - |   | - |   | - |   | - |   |
   +---+---+---+---+---+---+---+---+
 2 | P | - |   | - |   | - |   | - |
   +---+---+---+---+---+---+---+---+
 1 | - | K | - |   | - |   | - |   |
   +---+---+---+---+---+---+---+---+
     a   b   c   d   e   f   g   h

At any time, you can print the current board position in the above format to a
file with

: (ppos "file")

which later can be restored with

: (load "file")


   === PilBox and Web App ===

If you have the PilBox App installed on your Android device, just type "chess"
in the settings and press the "Download" button.

The Web application runs as a demo on

   https://picolisp.com/chess

To start it on your own machine, use

   $ pil chess/main.l -main -go +

Alternatively, you can start it with German localization as

   $ pil chess/main.l -'main "DE" "de"' -go +

then point your browser to http://localhost:8080

In both cases you can interact with the chess board in this way:

   * To enter a move, drag a piece to the new field.
   * A click on the board does an auto-move and then switches sides.
   * A doule click does the same, but as a "quick" (half search depth) move.
   * The search depth can be changed with a drop-down menu.
   * The "New" button starts a new game, and the "Undo" and "Redo" buttons
     navigate in the history.
   * The text "White" or "Black" indicate who is to move next. It changes to
     "White ..." or "Black ..." while the computer is thinking.
   * After a move, the moved piece and the old and new positions are indicated
     above that text.
   * "Save" and "Load" allow a single (!) save/restore of a game position.

The "Setup" button switches to edit mode and allows you to change the position
manually:

   * A click on a piece removes it from the board.
   * Dragging a piece moves it to another field.
   * A new piece can be placed on the board by dragging it from the setup area.
   * The "Clear" button removes all pieces from the board.
   * The "New" button sets up all pieces for a new game.
   * The "Game" button switches back to play mode.

As in any PilBox app, you can go to the settings (wheel icon on top right) and

   * switch to another language in the "Language" tab or
   * view the App's source code by clicking on the app name "chess" in the
     "PILs" tab.


   === Credits and Copying ===

The pieces and board colors are from https://chessboardjs.com

The icon is from
   https://commons.m.wikimedia.org/wiki/File:Chess logo.PNG

(MIT/X11 License)
