Giter Club home page Giter Club logo

neelrshah / 8-queens-problem Goto Github PK

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

In the game of chess, the queen can attack any piece that lies on the same row, on the same column, or along a diagonal. The eight-queens is a classic logic puzzle. The task is to place eight queens on a chessboard in such a fashion that no queen can attack any other queen.

C 100.00%
8 queens-problem datastructures backtracing backtracking-algorithm c recursive-algorithm queens-puzzle github miniproject

8-queens-problem's Introduction

8-queens-problem

In the game of chess, the queen can attack any piece that lies on the same row, on the same column, or along a diagonal. The eight-queens is a classic logic puzzle. The task is to place eight queens on a chessboard in such a fashion that no queen can attack any other queen.There are many different solutions for this puzzle. Hence we use backtracking techniques to solve this puzzle.

Algorithm:

 Place the queens column wise, start from the left most column  If the placement within the column does not lead to a solution, the queen is removed and moved down the column.  when all rows in a column have been tried ,the call terminates and backtracks to the previous call in previous column.  If a queen cannot be placed into column I, then do not try to place one onto column i+1, rather, backtrack to column i-1 and move the queen that had been placed there, using this approach we can reduce the number of potential solutions even more.  If all queens are placed. o return true and print the solution matrix.  Else o Try all the rows in the current column. o Check if queen can be placed here safely if yes mark the current cell in solution matrix as Q and try to solve the rest of the problem recursively. o If placing the queen in above step leads to the solution return true. o If placing the queen in above step does not lead to the solution , BACKTRACK, mark the current cell in solution matrix as * and return false.  If all the rows are tried and nothing worked, return false and print NO SOLUTION.

8-queens-problem's People

Contributors

neelrshah 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.