Book Image

Clojure Data Structures and Algorithms Cookbook

By : Rafik Naccache
Book Image

Clojure Data Structures and Algorithms Cookbook

By: Rafik Naccache

Overview of this book

Table of Contents (14 chapters)
Clojure Data Structures and Algorithms Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Playing a round of checkers


Now, it's time to take a break and play checkers. For this recipe, we are going to implement an artificial intelligence kernel capable of analyzing a checkers board, determining, under the game rules, where to move while staying out of the reach of the opponent's attacks, and spotting the opportunity as to when it can capture some of the enemy's soldiers.

Let's go through a little refresher of the game of checkers. You and your opponent are located on a square chess board, but you are only able to move diagonally over black squares one step at a time. Also, you can only move forward. Both of you can capture an enemy piece if it is situated just one step away from one of your pieces, provided that when you jump over it following the diagonal square piece, the black square where you land is empty. If while doing so, from that new position you're in, you are able to capture another piece, you may go on.

To model the battle scene, we are going to use three sets: one...