// Class: NQueensApp
//
// Author: Alyce Brady
//
// License Information:
//   This class is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation.
//
//   This class is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.

import java.awt.Color;

import javax.swing.JMenu;

import edu.kzoo.grid.display.ColorBlockDisplay;
import edu.kzoo.grid.display.DisplayMap;
import edu.kzoo.grid.gui.GridAppFrame;
import edu.kzoo.grid.gui.nuggets.BasicHelpMenu;
import edu.kzoo.grid.gui.nuggets.MinimalFileMenu;
import edu.kzoo.util.ValidatedInputReader;

/**
 *  Grid-Based Applications:<br>
 *
 *    The NQueensApp class implements the N Queens puzzle.
 *
 *  @author Alyce Brady
 *  @version 1 September 2002 (updated Dec 2025 to ask user for N)
 **/

public class NQueensApp
{
    // Specify dimensions of grid display and individual cell size.
    private static final int DISPLAY_WIDTH = 400;
    private static final int DISPLAY_HEIGHT = 400;
    private static final int MIN_CELL_SIZE = 20;

    // Specify the grid's background color and highlight color.
    private static final Color BACKGROUND_COLOR = new Color(0, 155, 255);
    private static final Color HIGHLIGHT_COLOR = Color.red;

    /**
     *  Starts the N Queens program.
     *  The String arguments (args) are not used in this application.
     **/
    public static void main(String[] args)
    {
        // Construct the graphical user interface for the N Queens puzzle.
        GridAppFrame display = new GridAppFrame();
        display.includeMenu(new MinimalFileMenu());
        JMenu helpMenu = new BasicHelpMenu("NQueens",
            "Your Name Here",
            "with assistance from (whom? e.g., Alyce Brady)",
            "Date, e.g., 1 October 2025");
        display.includeMenu(helpMenu);
        display.includeSpeedSlider();
        display.constructWindowContents("N Queens Problem", BACKGROUND_COLOR, 
                                DISPLAY_WIDTH, DISPLAY_HEIGHT, MIN_CELL_SIZE);
        Queen.setQueenColor(HIGHLIGHT_COLOR);

        // Specify how to display queens in the grid.
        DisplayMap.associate("Queen", new ColorBlockDisplay());
        // OR, DisplayMap.associate("Queen", new ScaledImageDisplay("GoldCrown.gif"));

        // Ask the user for the value of N to put N queens in an N x N grid.
        int n = ValidatedInputReader.getInteger(
                "Enter N (number of queens and size of N x N grid): ",
                1, 20, 8, "Please enter an integer between 1 and 20: ");

        // Solve the N Queens puzzle, if possible.
        NQueens queens = new NQueens(n, display);
        boolean wasSolved = queens.solve();

        // Report result.
        String result = "The " + n + " Queens problem ";
        result +=  wasSolved ?  "has been solved." : "cannot be solved.";
        System.out.println(result);
    }

}
