Skip to content

Racket

Converting Blog from Frog to MkDocs

I wrote in 2020 about converting my blog from Wordpress to Racket's Frog. After five years, I decided to switch to a different static site generator. This was essentially the result of nerd sniping myself :) I'm getting ready for this year's Advent of Code, so I'll probably be making a blog post or two in advance of the festivities. So, naturally, I might as well completely change my blogging infrastructure first! ;)

Chess: Forsyth-Edwards Notation

FEN - Forsyth-Edwards Notation

Part of the How to Program a Chess Engine in Lisp series.

Now that we have pieces and a board, we need a convenient way of setting pieces on the board in specific positions. We'll use this, not only for the initial position of a game, but also to configure a board with specific game scenarios for testing and debugging.

The standard way to do this is to use FEN, or Forsyth-Edwards Notation: [Wikipedia] [Chess Programming Wiki]

Here is the source for fen.rkt

Chess: the chess board

The Chess Board

Part of the How to Program a Chess Engine in Lisp series.

One of the most significant design decisions for a chess engine is how to model the chess board. I think the most competitive engines use a bitboard representation; however, for our purposes, a mailbox representation is more intuitive and easy to visualize. In particular, we will use a 10 x 12 board.

Here is the source for board.rkt

Chess: the chess piece

The Chess Piece

Part of the How to Program a Chess Engine in Lisp series.

Donald Knuth is credited with the statement:

...We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

Chess programming is most assuredly in the 3%! Our challenge in this series will be to strike a reasonable balance between efficiency and clarity. Our first opportunity to that end is the chess piece.

Here is the source for piece.rkt

How to Program a Chess Engine in Lisp

Last updated 2024-11-29 18:48

Table of Contents

  1. The Chess Piece
  2. The Chess Board
  3. FEN - Forsyth-Edwards Notation
  4. The Chess Move
  5. Move Generation

Introduction

Programming a competent chess engine in lisp has been a goal of mine for some time. I finally did so in 2021, and it was a lot of fun! My new goal is to rewrite the code in a step by step way that emphasizes clarity, and to present it as a clear tutorial for writing a chess engine, and as a general Racket tutorial.

Advent of Code 2023-Day 7: Camel Cards

#lang iracket/lang #:require racket
(require "../advent.rkt")

Day 7 involves simulating a card game. Our input looks like:

...
8J833 494
6AJT8 318
AA4QQ 125
62KK6 876
7A7QK 241
...

The left side is our card hand. The right side is our bid amount. As always, we begin with parsing. For our purposes of illustration, I'll skip the first 20 hands to get to a more interesting one with a J:

Advent of Code 2023-Day 5: Seeds

#lang iracket/lang #:require racket
(require "../advent.rkt")

Day 5 involves a typical Advent of Code scenario where Part 1 is easy, and a naive modification to Part 1 to get Part 2 is easy; however, the naive Part 2 solution will take far too long to run! :)

After solving Part 1 to get a star, I re-implemented the code to solve Part 2, and then Part 1 was simply making the Part 1 input conform to what Part 2 needed, and call Part 2.

The "trick" for Part 2 was to process the seed ranges as ranges, and not attempt to convert the seed ranges into lists of individual seeds.