Giter Site home page Giter Site logo

santiagoalvz / hillclimbingnqueen Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 6 KB

Solution to the N-Queen problem, using a Hill Climbing approach

Home Page: https://santiagoalvz.wordpress.com/2022/12/29/what-are-hill-climbing-algorithms/

C++ 100.00%
algorithms hill-climbing n-queen

hillclimbingnqueen's Introduction

N-Queen Problem (with Hill Climbing)

This program solves the N-Queen problem on a board with user-specified size. It solves it with Hill-Climbing, using the number of collisions (pairs of queens that can attack each other) as a heuristic.

Demonstration of the program, for a 16x16 board

Usage

When running the compiled program, the user will be prompted for the size of the chessboard.

After entering it, the solution for a board of that size will be displayed (where 0 stands for empty cell, and 1 for cell with a queen on it), alongside the number of collisions on said board and the number of steps taken by the Hill Climbing process.

Notes

  • For simplicity purposes, the inner mechanics of the code handle the queens positions as a numeric array of size N, where every item represents a row, and the number inside of it represents the column on which the queen sits. In other words, every row has one and only one queen on it, by design, which also simplifies the neighbor generation and collision count.
  • To count collisions on the diagonals, two small tricks are used. Adding the row and column number of a given cell helps identify the ascending (โ†—) diagonals, since two cells on the same diagonal will always have the same sum. For descending (โ†˜) diagonals, subtracting the the column number from the row number achieves the same thing.

This code is based on the solution by prasantkpatel posted on the Geeks for Geeks website.

hillclimbingnqueen's People

Contributors

santiagoalvz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.