Skip to content

This repo features a Rust implementation of the BSQ algorithm to find the largest square in a map with obstacles. It utilizes bitfields for space optimization and includes detailed explanations of the algorithm.

Notifications You must be signed in to change notification settings

GameboyColor32/bsq_rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust BSQ

This program was one of the first ones I did in my first year of university, where we had to implement it in C. While learning Rust, I thought it would be cool to reimplement these first programs, and indeed it was a good idea. I discovered a lot of new methods that make the development of these programs easier.

How it Works

  1. The first part of the program generates a random map with obstacles with a certain density. The map is a bitfield, where a bit is set to 1 if it is an obstacle. I used bitfields to use less space, so the size will be x * y / 8 + ((x * y % 8) ? 1 : 0) instead of x * y.

  2. The generated map is then passed to the algorithm, which generates the same map but with integers. From there, it clones the map to retain the positions of the obstacles, since the program will then do some computations to facilitate and accelerate the search for the biggest square.

  3. After all the information has been found and stored, the final part of the algorithm is to actually find the biggest square. It will be a classic brute-force approach but with a smarter way to check if a square can enter a given coordinate, all with the help of the information gathered in step 2.

Implementation Details

This program is implemented in Rust, and bitfields are used to optimize the space used to store the generated maps.

Resources

Conclusion

This program was a great opportunity to reimplement a classic algorithm while learning new techniques in Rust. The use of bitfields was an interesting optimization, and the program performs well even with large maps.

About

This repo features a Rust implementation of the BSQ algorithm to find the largest square in a map with obstacles. It utilizes bitfields for space optimization and includes detailed explanations of the algorithm.

Resources

Stars

Watchers

Forks

Languages