#ifndef Assignm3_H
#define Assignm3_H
// ------------------------------------------------------------------------------------
#include <vector>
#include <string>
#include <pthread.h>
#include "Path.h"
#include "Maze.h"
#include "ProgramLog.h"
#include "Assignm3_Utils.h"
#include "SubmitMazeSoln.h"
// ------------------------------------------------------------------------------------
namespace Assignm3
{
const int MAX_NO_OF_THREADS = 3;
const std::string THREAD_NAMES [] = {"POOH", "TIGGER", "ROO", "GOLPHER", "KANGA", "LUMPY", "OWL", "RABBIT", "PIGLET",
"POOH0", "TIGGER0", "ROO0", "GOLPHER0", "KANGA0", "LUMPY0", "OWL0", "RABBIT0", "PIGLET0",
"POOH1", "TIGGER1", "ROO1", "GOLPHER1", "KANGA1", "LUMPY1", "OWL1", "RABBIT1", "PIGLET1",
"POOH2", "TIGGER2", "ROO2", "GOLPHER2", "KANGA2", "LUMPY2", "OWL2", "RABBIT2", "PIGLET2",
"POOH3", "TIGGER3", "ROO3", "GOLPHER3", "KANGA3", "LUMPY3", "OWL3", "RABBIT3", "PIGLET3",
"POOH4", "TIGGER4", "ROO4", "GOLPHER4", "KANGA4", "LUMPY4", "OWL4", "RABBIT4", "PIGLET4",
"POOH5", "TIGGER5", "ROO5", "GOLPHER5", "KANGA5", "LUMPY5", "OWL5", "RABBIT5", "PIGLET5"
};
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
struct PathFinderParameterInfo
{
int threadIDArrayIndex;
bool exitThisThreadNow;
Point currentLocation;
std::string threadName;
VectorOfPointStructType travelledPath;
PathFinderParameterInfo (void)
{
currentLocation.x = -1;
currentLocation.y = -1;
threadIDArrayIndex = -1;
exitThisThreadNow = false;
travelledPath = VectorOfPointStructType ();
}
~PathFinderParameterInfo (void)
{
travelledPath.clear ();
}
};
// ------------------------------------------------------------------------------------
struct PathFinderResource
{
pthread_t activeThreadArray [MAX_NO_OF_THREADS];
PathFinderParameterInfo * activeThreadParamArray [MAX_NO_OF_THREADS];
VectorOfPointStructType solutionPath;
VectorOfPointStructType discoveredDangerAreas;
int usedThreadNameIndex;
int noOfDeadEndPathsFound;
int noOfBarriersDiscovered;
int noOfDangerAreaDiscovered;
PathFinderResource (void)
{
usedThreadNameIndex = 0;
noOfDeadEndPathsFound = 0;
noOfBarriersDiscovered = 0;
noOfDangerAreaDiscovered = 0;
solutionPath = VectorOfPointStructType ();
discoveredDangerAreas = VectorOfPointStructType ();
}
~PathFinderResource (void)
{
solutionPath.clear ();
discoveredDangerAreas.clear ();
}
};
PathFinderResource globalPathFinderResource;
// ------------------------------------------------------------------------------------
static Maze * mazeObj;
static Path * pathObj;
static SubmitMazeSoln * submitMazeSolnObj;
static std::fstream logFileStream;
static std::string DefaultLogFilename = "Assignm3Log.txt";
static pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t thread_condition = PTHREAD_COND_INITIALIZER;
static bool mainThreadReportUpdateNow = false;
static bool discoveredASolutionPath = false;
// ------------------------------------------------------------------------------------
static void AllocateProgramsVariableMemory (void)
{
mazeObj = new Maze ();
pathObj = new Path ();
submitMazeSolnObj = new SubmitMazeSoln ();
logFileStream.open (DefaultLogFilename.c_str(), std::fstream::out);
} // end allocateProgramsVariableMemory () ...
// ------------------------------------------------------------------------------------
static void DeallocateProgramsVariableMemory (void)
{
delete mazeObj;
delete pathObj;
delete submitMazeSolnObj;
logFileStream.close ();
pthread_mutex_destroy ( &thread_mutex );
pthread_cond_destroy ( &thread_condition );
} // end deallocateProgramsVariableMemory () ...
// ------------------------------------------------------------------------------------
static void HandleThreadOperationResult (std::ostream & outputStream, const std::string message, const int status)
{
if (status)
{
std::string msg = "Error on : " + message + ", ERROR CODE = " + IntToString (status) + "\n";
// below function 'WriteLogMessage' is defined in 'ProgramLog.h' ...
WriteLogMessage (std::cout, msg);
WriteLogMessage (outputStream, msg);
DeallocateProgramsVariableMemory ();
exit (EXIT_FAILURE);
}
} // end handleThreadOperationResult () ...
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
} // end namespace Assignm3
#endif // Assignm3_H
-----------------------------------------
#ifndef Assignm3_UTILS_H
#define Assignm3_UTILS_H
#include <time.h>
#include <ctime>
#include <vector>
#include <string>
#include <iostream> // cout, endl
#include <sstream> // ostringstream
#include <cstdlib> // srand, rand
// ------------------------------------------------------------------------------------
struct Point
{
int x;
int y;
Point () { x = NULL; y = NULL; }
Point (int x1, int y1) { x = x1; y = y1; }
~Point (void) { }
Point & operator= (const Point &p)
{ x = p.x; y = p.y; return (*this); }
bool operator== (const Point &p)
{ return ( (x == p.x) && (y == p.y) ); }
bool operator!= (const Point &p)
{ return ( (x != p.x) || (y != p.y) ); }
// 2 points are 'connected' but 'different' if they :
// i) share the same 'x' but adjacent 'y' values, OR
// ii) share the same 'y' but adjacent 'x' values!!
bool isConnected (Point &p)
{
return ( ((x == p.x) && ( ((y-1) == p.y) || ((y+1) == p.y) )) ||
((y == p.y) && ( ((x-1) == p.x) || ((x+1) == p.x) ))
);
}
void display (std::ostream &outputStream=std::cout)
{ outputStream << "[" << x << ", " << y << "]"; }
};
// ------------------------------------------------------------------------------------
// type define a vector of Point structs ...
typedef std::vector<Point> VectorOfPointStructType;
// type define a vector of VectorOfPointStructType ...
typedef std::vector<VectorOfPointStructType> VectorOfVectorOfPointStructType;
// ------------------------------------------------------------------------------------
static std::string IntToString (const int intValue)
{
std::ostringstream oss (std::ostringstream::out);
oss << intValue;
return ( oss.str() );
} // end intToString () ...
// ------------------------------------------------------------------------------------
static int GenerateRandomInteger (const int lowerLimit, const int upperLimit)
{
time_t secs;
time (&secs);
std::srand ( (unsigned int) secs );
return ( std::rand () % (upperLimit - lowerLimit + 1) + lowerLimit );
} // end GenerateRandomInteger () ...
// ------------------------------------------------------------------------------------
#endif // Assignm3_UTILS_H
#ifndef MAZE_H
#define MAZE_H
// ------------------------------------------------------------------------------------
#include <iomanip> // setw
#include <string> // for string manipulation ...
#include <iostream> // cout, endl
#include <fstream> // for file i/o ...
#include "Assignm3_Utils.h"
// ------------------------------------------------------------------------------------
namespace Assignm3
{
const char DANGER_CHAR = 'X';
const char BARRIER_CHAR = '#';
const char END_POS_CHAR = 'E';
const char START_POS_CHAR = 'S';
const int DANGER_INT = -10;
const int BARRIER_INT = -11;
const int END_POS_INT = -22;
const int START_POS_INT = -33;
const int UNINITIALIZED_VALUE = -99;
const std::string DefaultMazeFilename = "mazedata.txt";
/*
const std::string DefaultMazeFilename = "High_Casualties.txt";
const std::string DefaultMazeFilename = "Freedom.txt";
const std::string DefaultMazeFilename = "My_Only_Way.txt";
const std::string DefaultMazeFilename = "Horizontals.txt";
const std::string DefaultMazeFilename = "Verticals.txt";
const std::string DefaultMazeFilename = "Diagonals.txt";
const std::string DefaultMazeFilename = "Horizontals1.txt";
const std::string DefaultMazeFilename = "Verticals1.txt";
const std::string DefaultMazeFilename = "Frustration.txt";
const std::string DefaultMazeFilename = "Checkered.txt";
const std::string DefaultMazeFilename = "Choices.txt";
const std::string DefaultMazeFilename = "Checkered_Upsize.txt";
*/
const std::string MAZE_LENGTH_KEYWORD = "Length : ";
const std::string MAZE_BREADTH_KEYWORD = "Breadth : ";
class Maze
{
public:
// Constructor ...
Maze (int length=0, int breadth=0);
Maze (int length, int breadth, Point startLocation, Point endLocation);
// Destructor ...
~Maze (void);
void LoadMaze (const std::string filename=DefaultMazeFilename);
void SaveMaze (const std::string filename=DefaultMazeFilename) const;
VectorOfVectorOfPointStructType getPathVector (void) const;
VectorOfPointStructType getShortestPath (void) const;
int getLength (void) const;
int getBreadth (void) const;
void setStartLocation (Point p);
void setEndLocation (Point p);
Point getStartLocation (void) const;
Point getEndLocation (void) const;
int getNoOfDangerChar (void) const;
int getNoOfBarrierChar (void) const;
void updateMaze (Point p, int data);
bool IsThereDanger (int x, int y) const;
bool IsThereBarrier (int x, int y) const;
bool IsThereDanger (Point aLocation) const;
bool IsThereBarrier (Point aLocation) const;
void AddNewPath (VectorOfPointStructType newPath);
void DisplayInfo (std::ostream &outputStream=std::cout) const;
void DisplayMaze (void) const;
void DisplayMaze (int * mazeArray, std::ostream &outputStream=std::cout, int field_width=1) const;
// display path as graphically via an array of '2D maze' data
void ShowPathGraphically (VectorOfPointStructType & pointStructVector, std::ostream &outputStream=std::cout);
private:
int _length;
int _breadth;
Point _startLocation;
Point _endLocation;
// 1D array representing a 2D maze of chars ...
int * _mazeArray;
// A 'path' consists of a series of Point structs plotting
// a course from _startLocation to _endLocation
//
// Below data structure is used to store all valid paths
// discovered in _mazeArray
VectorOfVectorOfPointStructType _pathVector;
void InitMazeArray (void);
void ReadLengthData (std::string aLine);
void ReadBreadthData (std::string aLine);
void ReadMazeData (std::string aLine, int & currRowIndex);
void SaveMazeArray (int * mazeArray, std::ostream &outputStream) const;
}; // end class Maze ...
} // end namespace Assignm3 ...
#endif // MAZE_H
#ifndef PATH_H
#define PATH_H
// ------------------------------------------------------------------------------------
#include <iostream> // cout, endl
#include "Assignm3_Utils.h"
// ------------------------------------------------------------------------------------
namespace Assignm3
{
class Path
{
public:
// Constructor ...
Path (void);
// Destructor ...
~Path (void);
// returns true of a Point is found in a vector of Points ...
bool isLocationInPath (Point & location, VectorOfPointStructType & pointStructVector) const;
// display path as series of [x, y] coordinates
void displayPath (VectorOfPointStructType & pointStructVector,
std::ostream &outputStream=std::cout,
int maxDataPerLine=8) const;
// check if 2 paths are identical ...
bool arePathsIdentical (VectorOfPointStructType & firstPath, VectorOfPointStructType & secondPath) const;
private:
}; // end class Path ...
} // end namespace Assignm3 ...
#endif // PATH_H
#ifndef PROGRAM_LOG_H
#define PROGRAM_LOG_H
#include <string>
#include <iostream>
#include <errno.h>
// ------------------------------------------------------------------------------------
static void WriteLogMessage (std::ostream & outputStream, std::string message)
{
if (outputStream.good())
outputStream << message << std::endl;
else
{
std::cout << std::endl;
std::cout << "WriteLogMessage Error! outputStream.good() fails! Re-direct Log Msg to screen!" << std::endl;
std::cout << "Log Msg : " << message << std::endl;
std::cout << std::endl;
}
} // end WriteLogMessage () ...
// ------------------------------------------------------------------------------------
#endif // PROGRAM_LOG_H ...
#ifndef SUBMIT_MAZE_SOLN_H
#define SUBMIT_MAZE_SOLN_H
// ------------------------------------------------------------------------------------
#include <string>
#include <vector>
#include <iostream> // cout, endl
#include <pthread.h> // pthread_t
#include "Path.h"
#include "Maze.h"
#include "ProgramLog.h"
#include "Assignm3_Utils.h"
// ------------------------------------------------------------------------------------
//
// How to compile :
//
// E.g. Assume your main program is called "MyProg.cpp", and you want your executable to be called "MyProg" ...
//
// g++ MyProg.cpp SubmitMazeSoln.o Path.o Maze.o -o MyProg -lpthread
//
// Note : the compiled versions of Path.o, Maze.o and SubmitMazeSoln.o are made available to you!
// In addition, the headers Path.h, Maze.h and SubmitMazeSoln.h are also made available to you!
//
// Your task is to concentrate on implementing a multi-threaded program to discover paths
// to barrier, danger area and a solution to travel from Start to End locations !!!
//
// ------------------------------------------------------------------------------------
namespace Assignm3
{
// ------------------------------------------------------------------------------------
const std::string DefaultSolutionFilename = "mazesoln.txt";
struct ThreadStatisticsInfo
{
pthread_t threadID;
VectorOfPointStructType solutionPath;
// A vector of ALL UNIQUE paths to barriers discovered by this thread
VectorOfVectorOfPointStructType submittedPathsToBarriers;
// To check if student follows instructions. By right a thread should only discover
// ONE path to danger area before being destroyed !
VectorOfVectorOfPointStructType submittedPathsToDangerAreas;
// Below var will be incremented, if same path to barrier is submitted again and again
// by this thread!
int noOfDuplicatedPathsToBarrier;
// Below var will be incremented, if same path to danger area is submitted again and again
// by this thread!
int noOfDuplicatedPathsToDangerArea;
ThreadStatisticsInfo (void)
{
noOfDuplicatedPathsToBarrier = 0;
noOfDuplicatedPathsToDangerArea = 0;
solutionPath = VectorOfPointStructType ();
submittedPathsToBarriers = VectorOfVectorOfPointStructType ();
submittedPathsToDangerAreas = VectorOfVectorOfPointStructType ();
}
~ThreadStatisticsInfo (void)
{
solutionPath.clear ();
submittedPathsToBarriers.clear ();
submittedPathsToDangerAreas.clear ();
}
};
// type define a vector of 'ThreadStatisticsInfo' ...
typedef std::vector<ThreadStatisticsInfo> VectorOfThreadStatisticsInfoType;
// ------------------------------------------------------------------------------------
class SubmitMazeSoln
{
public:
// Constructor ...
SubmitMazeSoln (void);
// Destructor ...
~SubmitMazeSoln (void);
// Student should call this method to 'submit' an EXPLORED PATH to danger area 'X'
// discovered by one of his/her generated thread!
//
// Parameter 1 : pthread_t => refers to the id of the thread that explored the path to discover the Danger Area
//
// Parameter 2 : VectorOfPointStructType => refers to a vector of (x, y) Points, containing the path explored by the thread
// from start location to Danger Area's location!
//
// Note : Parameter 2 must contain start location Point at the beginning of the vector (i.e. pathToDangerArea [0]) , AND
// the Danger Area Point at the end of the vector (i.e. pathToDangerArea [size-1] !!)
//
// returns 'true' if the submitted discovery is UNIQUE
// returns 'false' if :
// a) first Point in 'pathToDangerArea' does NOT contain the start location of the maze OR
// b) submitted Danger Area's location is wrong OR
// c) same path has been submitted before OR
// d) points in the path are NOT CONNECTED, or CONTAINS OTHER DANGER / BARRIER or DUPLICATED POINTS OR
// e) threadID is invalid OR
// f) 'pathToDangerArea' is empty
//
bool submitPathToDangerArea (pthread_t threadID, VectorOfPointStructType & pathToDangerArea);
// Student should call this method to 'submit' an EXPLORED PATH to barrier '#'
// discovered by one of his/her generated thread!
//
// Parameter 1 : pthread_t => refers to the id of the thread that explored the path to discover the Barrier
//
// Parameter 2 : VectorOfPointStructType => refers to a vector of (x, y) Points, containing the path explored by the thread
// from start location to Barrier's location!
//
// Note : Parameter 2 must contain start location Point at the beginning of the vector (i.e. pathToBarrier [0]) , AND
// the Barrier Point at the end of the vector (i.e. pathToBarrier [size-1] !!)
//
// returns 'true' if the submitted discovery is UNIQUE
// returns 'false' if :
// a) first Point in 'pathToBarrier' does NOT contain the start location of the maze OR
// b) submitted Barrier's location is wrong OR
// c) same path has been submitted before OR
// d) points in the path are NOT CONNECTED, or CONTAINS OTHER DANGER / BARRIER or DUPLICATED POINTS
// e) threadID is invalid OR
// f) 'pathToBarrier' is empty
//
bool submitPathToBarrier (pthread_t threadID, VectorOfPointStructType & pathToBarrier);
// Student should call this method to 'submit' a SOLUTION PATH to end location 'E'
// discovered by one of his/her generated thread!
//
// Parameter 1 : pthread_t => refers to the id of the thread that explored the path to discover the solution
//
// Parameter 2 : VectorOfPointStructType => refers to a vector of (x, y) Points, containing the path explored by the thread
// from start location to end location!
//
// returns 'true' if the submitted solution is VALID
// returns 'false' if the submitted solution is INVALID ...
//
// A student's solution is valid if his submitted solution :
//
// i) beginning of the 'pathToEndLocation' vector contains the Start Location
// ii) end of the 'pathToEndLocation' vector contains the End Location
// iii) contains a series of 'connected' points from start to end location
// iv) there are no 'barriers' or 'danger' locations in his submitted path
// v) each point in his submitted path is unique (i.e. the path must not travel in loops/circles) ...
// vi) the BEGINNING point must be 'Start Location' and the END point must be 'End Location' ...
bool submitSolutionPath (pthread_t threadID, VectorOfPointStructType & pathToEndLocation);
// Once ALL explored paths and solution are submitted, student MUST call below method,
// to print the details of their solution on screen!
//
// Parameter 1 : 'studentName' => the full name of the student, (without spaces)
// E.g. 'Tan Ah Beng' should be changed to 'TanAhBeng' (without spaces) !!
//
// Parameter 2 : 'studentID' => the admin. or matric. no. of the student
// E.g. '1234567'
//
void printSubmittedSolution (std::string studentName, std::string studentID, std::ostream &outputStream=std::cout);
// Once ALL explored paths and solution are submitted, student MUST call below method,
// to save the details of their solution to a text file!
//
// Parameter 1 : 'studentName' => the full name of the student, (without spaces)
// E.g. 'Tan Ah Beng' should be changed to 'TanAhBeng' (without spaces) !!
//
// Parameter 2 : 'studentID' => the admin. or matric. no. of the student
// E.g. '1234567'
//
void saveSubmittedSolution (std::string studentName, std::string studentID);
private:
Maze * _problemMaze;
Maze * _studentSolnMaze;
int _noOfDuplicatedPathsToBarrierSubmitted;
int _noOfDuplicatedPathsToDangerAreaSubmitted;
VectorOfPointStructType _finalSolutionPath;
VectorOfVectorOfPointStructType _discoveredPathsToBarrier;
VectorOfVectorOfPointStructType _discoveredPathsToDangerArea;
VectorOfThreadStatisticsInfoType _generatedThreadsVector;
int findThreadIndex (pthread_t threadID) const;
// a helper function invoked by other functions (e.g. 'isSolutionValid ()') to check path validity ...
bool checkPathValidity (VectorOfPointStructType aPath) const;
bool isPathUnique (VectorOfPointStructType submittedNewPath, VectorOfVectorOfPointStructType discoveredPaths) const;
void storeThreadInfo ( pthread_t threadID, VectorOfPointStructType & aPath, int typeOfPath );
}; // end class SubmitMazeSoln ...
} // end namespace Assignm3 ...
#endif // SUBMIT_MAZE_SOLN_H
// Statistics to report ...
//
// 1) No. of unique threads generated
//
// 2) No. of danger areas discovered
//
// 3) Count of duplicated paths (to danger areas) submitted
//
// E.g. of threadID ... '3079273328'
//
// To compile this program into an executable named 'testmaze', ...
//
// 1) Ensure all downloaded files are in the SAME folder
//
// 2) Use the following command :
// g++ testmaze.cpp Maze.o -o testmaze
//
#include "Maze.h"
#include "Assignm3_Utils.h"
const std::string filename = "mazedata.txt";
int main (void)
{
Assignm3::Maze *maze = new Assignm3::Maze ();
maze->LoadMaze (filename);
std::cout << std::endl;
std::cout << "Length of maze in '" << filename << "' : " << maze->getLength();
std::cout << std::endl;
std::cout << "Breadth of maze in '" << filename << "' : " << maze->getBreadth();
std::cout << std::endl;
Point startLoc = maze->getStartLocation();
Point endLoc = maze->getEndLocation();
std::cout << "Start Location of maze in '" << filename << "' : ";
startLoc.display();
std::cout << std::endl;
std::cout << "End Location of maze in '" << filename << "' : ";
endLoc.display();
std::cout << std::endl;
std::cout << std::endl;
std::cout << "Displaying Maze contents ...";
std::cout << std::endl;
maze->DisplayMaze ();
std::cout << std::endl;
std::cout << std::endl;
}
#include <pthread.h>
#include "Path.h"
#include "Maze.h"
#include "SubmitMazeSoln.h"
#include "Assignm3_Utils.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// To compile,
// 1) Ensure all the necessary header files (see above) are in the same directory
// 2) g++ Path.o Maze.o SubmitMazeSoln.o TestSubmitMazeSoln.cpp -o TestSubmitMazeSoln.exe -lpthread
// #######################################################################################
int main ()
{
Assignm3::Path path;
Assignm3::SubmitMazeSoln sms;
VectorOfPointStructType pathToBarrier1 = VectorOfPointStructType ();
VectorOfPointStructType pathToBarrier2 = VectorOfPointStructType ();
VectorOfPointStructType pathToBarrier3 = VectorOfPointStructType ();
VectorOfPointStructType pathToBarrier4 = VectorOfPointStructType ();
VectorOfPointStructType pathToBarrier5 = VectorOfPointStructType ();
pathToBarrier1.push_back (Point (1,1));
pathToBarrier1.push_back (Point (0,1));
pathToBarrier2.push_back (Point (1,1));
pathToBarrier2.push_back (Point (1,0));
pathToBarrier3.push_back (Point (1,1));
pathToBarrier3.push_back (Point (1,2));
pathToBarrier3.push_back (Point (0,2));
pathToBarrier4.push_back (Point (1,1));
pathToBarrier4.push_back (Point (1,2));
pathToBarrier4.push_back (Point (1,3));
pathToBarrier4.push_back (Point (1,4));
pathToBarrier5.push_back (Point (1,1));
pathToBarrier5.push_back (Point (1,2));
pathToBarrier5.push_back (Point (1,4));
// path.displayPath (pathToBarrier1);
// path.displayPath (pathToBarrier2);
// path.displayPath (pathToBarrier3);
// path.displayPath (pathToBarrier4);
// path.displayPath (pathToBarrier5);
sms.submitPathToBarrier ((pthread_t) 1234567, pathToBarrier1);
sms.submitPathToBarrier ((pthread_t) 1234567, pathToBarrier2);
sms.submitPathToBarrier ((pthread_t) 1234567, pathToBarrier3);
sms.submitPathToBarrier ((pthread_t) 1234567, pathToBarrier4);
sms.submitPathToBarrier ((pthread_t) 1234567, pathToBarrier5);
VectorOfPointStructType pathToDangerArea1 = VectorOfPointStructType ();
VectorOfPointStructType pathToDangerArea2 = VectorOfPointStructType ();
VectorOfPointStructType pathToDangerArea3 = VectorOfPointStructType ();
VectorOfPointStructType pathToDangerArea4 = VectorOfPointStructType ();
VectorOfPointStructType pathToDangerArea5 = VectorOfPointStructType ();
pathToDangerArea1.push_back (Point (1,1));
pathToDangerArea1.push_back (Point (2,1));
pathToDangerArea1.push_back (Point (3,1));
pathToDangerArea1.push_back (Point (4,1));
pathToDangerArea2.push_back (Point (1,1));
pathToDangerArea2.push_back (Point (2,1));
pathToDangerArea2.push_back (Point (2,2));
pathToDangerArea2.push_back (Point (2,3));
pathToDangerArea2.push_back (Point (3,3));
pathToDangerArea2.push_back (Point (4,3));
pathToDangerArea2.push_back (Point (4,2));
pathToDangerArea2.push_back (Point (4,1));
// pathToDangerArea2.push_back (Point (4,0));
sms.submitPathToDangerArea ((pthread_t) 1234567, pathToDangerArea1);
sms.submitPathToDangerArea ((pthread_t) 1234567, pathToDangerArea2);
VectorOfPointStructType solutionPath = VectorOfPointStructType ();
solutionPath.push_back (Point (1,1));
solutionPath.push_back (Point (1,2));
solutionPath.push_back (Point (1,3));
solutionPath.push_back (Point (2,3));
solutionPath.push_back (Point (2,4));
solutionPath.push_back (Point (2,5));
solutionPath.push_back (Point (3,5));
solutionPath.push_back (Point (4,5));
solutionPath.push_back (Point (4,4));
solutionPath.push_back (Point (4,3));
sms.submitSolutionPath ((pthread_t) 1234567, solutionPath);
sms.printSubmittedSolution ("Tan Ah Beng", "1001001");
sms.saveSubmittedSolution ("Tan Ah Beng", "1001001");
} // end main () ...
// #######################################################################################
/*
TESTED!! -> Point struct '==' and '=' operator overloading ...
Point p (3, 8);
Point p1 (3, 8);
Point p2 (8, 8);
if (p == p1)
{
std::cout << "p "; p.display ();
std::cout << " is EQUAL to p1 "; p1.display ();
std::cout << " !!" << std::endl;
}
else
{
std::cout << "p "; p.display ();
std::cout << " is NOT EQUAL to p1 "; p1.display ();
std::cout << " !!" << std::endl;
}
if (p == p2)
{
std::cout << "p "; p.display ();
std::cout << " is EQUAL to p2 "; p2.display ();
std::cout << " !!" << std::endl;
}
else
{
std::cout << "p "; p.display ();
std::cout << " is NOT EQUAL to p2 "; p2.display ();
std::cout << " !!" << std::endl;
}
Point p3 (8, 8);
Point p4, p5;
p4 = p5 = p3;
// p5 = p4;
std::cout << "p3 is "; p3.display (); std::cout << std::endl;
std::cout << "p4 is "; p4.display (); std::cout << std::endl;
std::cout << "p5 is "; p5.display (); std::cout << std::endl;
*/
// #######################################################################################
/*
TESTED !! -> isConnected() in struct Point ...
Point p (3, 8);
Point pLeft (2, 8);
Point pRight (4, 8);
Point pUp (3, 9);
Point pDown (3, 7);
if (p.isConnected (pLeft))
std::cout << "p is connected to pLeft !!" << std::endl;
if (p.isConnected (pRight))
std::cout << "p is connected to pRight !!" << std::endl;
if (p.isConnected (pUp))
std::cout << "p is connected to pUp !!" << std::endl;
if (p.isConnected (pDown))
std::cout << "p is connected to pDown !!" << std::endl;
if (pLeft.isConnected (pRight))
std::cout << "pLeft is connected to pRight !!" << std::endl;
else
std::cout << "pLeft is NOT connected to pRight !!" << std::endl;
if (pUp.isConnected (pDown))
std::cout << "pUp is connected to pDown !!" << std::endl;
else
std::cout << "pUp is NOT connected to pDown !!" << std::endl;
*/
// #######################################################################################
/*
TESTED!! -> new method in Path.h 'arePathsIdentical ()' ...
Point p (3, 8);
Point p1 (3, 8);
Point p2 (8, 8);
VectorOfPointStructType path1;
path1.push_back (p); path1.push_back (p1); path1.push_back (p2);
VectorOfPointStructType path2;
path2.push_back (p); path2.push_back (p1); path2.push_back (p2);
Assignm3::Path path;
if (path.arePathsIdentical (path1, path2))
std::cout << "path1 is identical to path2 !!" << std::endl;
else
std::cout << "path1 is different from path2 !!" << std::endl;
*/
// #######################################################################################
/*
TESTED !! -> Maze constructor, and new methods () ...
Assignm3::Maze * probMaze = new Assignm3::Maze ();
probMaze->LoadMaze ();
Assignm3::Maze * solnMaze = new Assignm3::Maze (probMaze->getLength(), probMaze->getBreadth(),
probMaze->getStartLocation(), probMaze->getEndLocation());
probMaze->DisplayMaze ();
probMaze->DisplayInfo ();
solnMaze->updateMaze (Point (0,0), Assignm3::BARRIER_INT);
solnMaze->updateMaze (Point (0,1), Assignm3::BARRIER_INT);
solnMaze->updateMaze (Point (1,0), Assignm3::BARRIER_INT);
solnMaze->DisplayMaze ();
solnMaze->DisplayInfo ();
*/
// #######################################################################################
/*
TESTED !! ->
*/
// #######################################################################################