#include #include #include "StructureDefinitions.h" #include "SolutionListOperations.h" #include "NQueensChecker.h" #pragma warning(disable:4996) typedef int bool; #define true 1 #define false 0 //Variables workingCandidate, openList, closedList candidateSolution workingCandidate;// this one will hold the soltion we arecurrently considering candidateList openList; // this list will store all the soltion we;ve created but not examined yet candidateList closedList; // this is where we will store all the ones we're done with int firstValueToAdd; //************************ don't edit anything above this line***********************// int main(int argc, const char * argv[]) { /* the next set of variables get used within our main function * but aren't declared globally becuase we don't want the other functions to change them inadvertently */// int indexOfSolutionWeAreLookingAt=0; //index in list of current solution being examined int currentRow=0; // used when we extend the working candidate bool goalReached = false; // used to indicate when to stop searching for new candidates int numRead=0;//used to read the inputs //start off by emptying the lists of candidate solutions CleanListsOfSolutionsToStart(); CleanWorkingCandidate(); /* So now let's start by creating our first solution * which we do by filling the values into the variable we declared as the workingCandidate * We'll begin by putting the first queen into column ), or specified from the command line */ firstValueToAdd = 0; if(argc==2) { numRead=sscanf(argv[1],"%d",&firstValueToAdd); if (numRead != 1 || firstValueToAdd >=N || firstValueToAdd <0) { #ifdef ONDEWIS extern void printInvalidInputFeedbackAndExit(void); printInvalidInputFeedbackAndExit(); #else PrintThisMessageAndExit("Invalid Input"); #endif } }
please correct this code I need help.
/*
* File: main.c
* Author: j4-smith
*N-Queens example in C
* First Created on 25 April 2014, 18:42
* Modified in light of student progress
* Rewritten Oct 2015 to use more generic solution structures
* and functions with NQueens-specific names that call the functions that modify the
* modified still further 2018
*/
#include <stdio.h>
#include <stdlib.h>
#include "StructureDefinitions.h"
#include "SolutionListOperations.h"
#include "NQueensChecker.h"
#pragma warning(disable:4996)
typedef int bool;
#define true 1
#define false 0
//Variables workingCandidate, openList, closedList
candidateSolution workingCandidate;// this one will hold the soltion we arecurrently considering
candidateList openList; // this list will store all the soltion we;ve created but not examined yet
candidateList closedList; // this is where we will store all the ones we're done with
int firstValueToAdd;
//************************ don't edit anything above this line***********************//
int main(int argc, const char * argv[])
{
/* the next set of variables get used within our main function
* but aren't declared globally becuase we don't want the other functions to change them inadvertently *///
int indexOfSolutionWeAreLookingAt=0; //index in list of current solution being examined
int currentRow=0; // used when we extend the working candidate
bool goalReached = false; // used to indicate when to stop searching for new candidates
int numRead=0;//used to read the inputs
//start off by emptying the lists of candidate solutions
CleanListsOfSolutionsToStart();
CleanWorkingCandidate();
/* So now let's start by creating our first solution
* which we do by filling the values into the variable we declared as the workingCandidate
* We'll begin by putting the first queen into column ), or specified from the command line
*/
firstValueToAdd = 0;
if(argc==2)
{
numRead=sscanf(argv[1],"%d",&firstValueToAdd);
if (numRead != 1 || firstValueToAdd >=N || firstValueToAdd <0)
{
#ifdef ONDEWIS
extern void printInvalidInputFeedbackAndExit(void);
printInvalidInputFeedbackAndExit();
#else
PrintThisMessageAndExit("Invalid Input");
#endif
}
}
// we are using a constructive solution so first we have to add a queen.
// There is a different function to move a queen.
AddQueenToNextRowInColumn(firstValueToAdd);
//this shows you how to print the current working cnadidae if you need to for debugging
PrintWorkingCandidate();
//this is the functgion that tests whether a partial solution is feasible or not
CalculateNumberOfVulnerableQueensForWorkingCandidate(); //should score zero because there is only one queen :)
//and we can put this as our first item in the list to start the process
AddWorkingCandidateToOpenList();
///**********DONT CHANGE ANYTHING ABOVE THIS LINE
//**** YOUR DEPTH_FIRST SEARCH CODE GOES HERE ***////
///**** YOU MUST CALL PrintFinalSolutionAndExit() to get a mark from the system
Function breadth ()
{
queue = []; // initialize an empty queue
state = root_node; // initialize the start state
while (true)
{
if is_goal (state)
then return SUCCESS
else add_to_back_of_queue (successors (state));
if queue == []
then report FAILURE;
state = queue [0]; // state = first item in queue
remove_first_item_from (queue);
}
}
PrintFinalSolutionAndExit();
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps