Skip to content

lostjared/Knights_Tour

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knights Tour Simulation

board

This project implements a Knights Tour simulation using Rust and SDL2. The goal of the simulation is to move a knight around a chessboard, touching each square exactly once.

Features

  • Displays an 8x8 chessboard
  • Moves the knight to each square on the board exactly once
  • Shows the current state of the tour and indicates when the tour is complete
  • Allows users to restart the tour by pressing Enter

Requirements

  • Rust
  • SDL2
  • SDL2_ttf

Installation

  1. Ensure you have Rust installed. If not, you can install it from rust-lang.org.
  2. Install SDL2 and SDL2_ttf on your system. For installation instructions, refer to SDL2 Installation Guide.
  3. Clone this repository:
git clone https://github.com/lostjared/Knights_Tour.git
cd Knights_Tour/knights_tour
  1. Build the project using Cargo:
cargo build --release
  1. Run the executable:
cargo run --release

board2

Usage

  • Press Space to move the knight to the next position.
  • Press Enter to restart the tour.
  • Press Escape to exit the simulation.

Code Structure

  • Position: Represents the knight's position on the board.
  • drawboard: Draws the chessboard on the SDL2 canvas.
  • drawknight: Draws the knight at its current position on the board.
  • clearboard: Clears the board for a new tour.
  • nextmove: Calculates the knight's next move using Warnsdorff's rule.

Assets

  • data/font.ttf: The font used for rendering text.
  • data/knight.bmp: The knight image used for the simulation.

Contributing

If you would like to contribute to this project, please fork the repository and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgments

This project uses the following libraries and resources: