Skip to content

The classic n-queens problem, turned into a game that users can play!

Notifications You must be signed in to change notification settings

AnkitSinghGTHB/N-queens-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 

Repository files navigation

N-Queens Game

๐Ÿ“Œ Overview

This is a C++ console-based game based on the N-Queens problem, where the player must place queens on an N ร— N chessboard without any queen attacking another. The game ends immediately if a queen is placed in an attackable position.

๐ŸŽฎ How to Play

  1. Run the program and enter the board size N.
  2. Enter queen positions in the format: row column (0-based index).
  3. Type help to highlight all attackable positions on the board.
  4. The game ends if a queen is placed in an attackable position.

โœจ Features

โœ… Custom Board Size - Choose any value for N. โœ… Live Attack Zone Highlighting - Type help to see under-attack positions (X). โœ… Chessboard Formatting - Row and column numbers improve readability. โœ… Instant Game Over - Placing a queen under attack ends the game immediately.

๐Ÿ–ฅ๏ธ Installation & Execution

  1. Clone the repository:
    git clone https://github.com/your-username/NQueensGame.git
    cd NQueensGame
  2. Compile the program:
    g++ -o nqueens nqueens.cpp
  3. Run the game:
    ./nqueens

๐Ÿ“œ Code Structure

  • NQueensGame class handles board mechanics and user input.
  • printBoard() displays the chessboard with proper formatting.
  • isUnderAttack() checks if a position is under attack.
  • play() runs the game loop and takes user input.

๐Ÿ–ผ๏ธ Example Gameplay

Enter board size (N): 5
Enter position: 2 3
     0  1  2  3  4
   ---------------
 0|  .  .  .  .  .
 1|  .  .  .  .  .
 2|  .  .  .  Q  .
 3|  .  .  .  .  .
 4|  .  .  .  .  .

๐Ÿ† Contributions

Feel free to submit issues or pull requests to improve the game! ๐Ÿš€

๐Ÿ“œ License

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

About

The classic n-queens problem, turned into a game that users can play!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages