/********************************************************************** Dackral Phillips COMP 7600 - Artificial Intelligence Dr. Dozier Final Project Feb. 27, 2K2 Description: This project deals with how to solve N-queens problem. It uses six different methods to solve the problem, O(N), modified backtracking algorithm, arc consistent look ahead, next and steepest ascent hill climbing, and genetic search algorithms. Queen.java: This file declares a queen object that has 3 variables. XCoord gives the X coordinate where a queen has been placed. YCoord gives the y. Placed is a boolean determining whether a queen has been placed on the board or not. ***********************************************************************/ import java.io.*; // Let me print some stuff! // Begin the Queen class definition public class Queen { // Make me some variables! private int xCoord; private int yCoord; private boolean placed; private int[] free; // Constructors - set x and y to 0 and placed to false initially public Queen() { int n = 4; xCoord = 0; yCoord = 0; placed = false; free = new int[n + 1]; for (int i = 1; i < free.length; i++) { free[i] = -1; } free[0] = 1; } public Queen(int n) { xCoord = 0; yCoord = 0; placed = false; free = new int[n + 1]; for (int i = 1; i < free.length; i++) { free[i] = -1; } free[0] = 1; } // function to place a queen at a specific x and y coordinate public void setQueen(int x, int y) { xCoord = x; yCoord = y; placed = true; } // function to remove a queen from a specific coordinate public void removeQueen(int x, int y) { xCoord = 0; yCoord = 0; placed = false; } // Returns the x coordinate of a queen's position public int getX() { return xCoord; } // Returns the y coordinate of a queen's position public int getY() { return yCoord; } // Tells whether or not the queen has been placed public boolean getPlaced() { return placed; } // Reset the free squares a queen can occupy public void resetFree() { for (int i = 1; i < free.length; i++) { free[i] = -1; } free[0] = 1; } // Set the next available square in the free array public void setFree(int index, int value) { free[index] = value; } // Return the next available square to which the queen can go public int getFree() { int index = free[0]; free[0] += 1; return free[index]; } // Print out the variable states for this queen - useful for debugging public String toString() { String print = new String("\nQueen\n"); print = print + "X Coordinate: " + xCoord + "\n"; print = print + "Y Coordinate: " + yCoord + "\n"; if (placed) print = print + "Placed: True\n"; else print = print + "Placed: False\n"; print = print + "\nFree\n"; for (int i = 0; i < free.length; i++) { print = print + " " + free[i]; } print = print + "\n"; return print; } } // End the class definition