Skip to content

CodeVerse-ir/N-queen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

N-queen

Below is a sample README file for your GitHub project that describes the N Queens problem, which involves placing N queens on a chessboard (size ranging from 4 to 20) using random placement and employing algorithms like Hill Climbing, Genetic Algorithms, and CSP (Constraint Satisfaction Problems). The README provides an overview of the project, how to use it, and details about the algorithms utilized.

# N Queens Problem Solver

This project aims to solve the classic N Queens problem, where N queens are placed on an N x N chessboard such that no two queens threaten each other. This implementation allows the user to select the number of queens (between 4 and 20) and generates random placements of the queens. The project utilizes various algorithms, including Hill Climbing, Genetic Algorithms, and Constraint Satisfaction Problems (CSP) to find solutions.

## Features

- **Dynamic Queen Selection**: Choose the number of queens to place on the board (from 4 to 20).
- **Generate Random Placements**: Place queens randomly on the chessboard.
- **Algorithms Implemented**:
  - **Hill Climbing**: A local search algorithm that continuously moves towards a neighboring state with a higher value.
  - **Genetic Algorithm**: A heuristic search algorithm inspired by the process of natural selection to evolve solutions.
  - **Constraint Satisfaction Problem (CSP)**: A method to find states that satisfy a set of constraints.

## Usage

1. **Clone the repository**:
   ```bash
   git clone https://github.com/yourusername/n-queens-solver.git
   cd n-queens-solver
  1. Install dependencies (if any).

  2. Run the program:

    • Choose the number of queens (between 4 and 20).
    • Click the "Generate" button to create a random configuration of queens on the board.
    • Use selected algorithms to find and visualize solutions.

Algorithms Explained

Hill Climbing

Hill Climbing is a local search algorithm that iteratively makes small changes to the current solution. It evaluates neighboring queen placements and moves to the one that improves the overall solution (i.e., reduces the number of conflicts between queens). The algorithm stops when it reaches a local maximum where no neighboring placement results in fewer conflicts.

Genetic Algorithm

The Genetic Algorithm simulates the process of natural evolution. It uses a population of potential solutions represented as chromosomes (arrays of queen positions). The algorithm applies selection, crossover, and mutation operations to evolve the population toward better solutions over multiple generations.

  1. Selection: The fittest solutions (with fewer conflicts) are selected for reproduction.
  2. Crossover: Two parent solutions combine to produce offspring solutions.
  3. Mutation: Random changes are applied to some offspring to maintain genetic diversity.

Constraint Satisfaction Problems (CSP)

CSP approaches involve defining the problem as a set of variables and constraints. Each queen's position can be a variable, and constraints ensure that no two queens share the same row, column, or diagonal. The algorithm systematically searches for assignments that satisfy all constraints, often using backtracking.

Contributions

Feel free to contribute to this project by opening issues to report bugs or submitting pull requests with enhancements.

License

This project is licensed under the MIT License.


### Notes:
- Adjust the repository URL under "Clone the repository" to point to your actual GitHub repository.
- Modify sections regarding installation instructions or dependencies as necessary based on your project setup.
- You can add additional sections like "Testing" or "Screenshots" if relevant to provide more context for users. 

If you need any further details or specific adjustments, let me know!