diff --git a/C++/Astar/.vs/Astar/v16/.suo b/C++/Astar/.vs/Astar/v16/.suo new file mode 100644 index 00000000..208ce925 Binary files /dev/null and b/C++/Astar/.vs/Astar/v16/.suo differ diff --git a/C++/Astar/.vs/Astar/v16/Browse.VC.db b/C++/Astar/.vs/Astar/v16/Browse.VC.db new file mode 100644 index 00000000..b37ad15c Binary files /dev/null and b/C++/Astar/.vs/Astar/v16/Browse.VC.db differ diff --git a/C++/Astar/.vs/Astar/v16/ipch/AutoPCH/1e53c8206eecd77a/SOURCE.ipch b/C++/Astar/.vs/Astar/v16/ipch/AutoPCH/1e53c8206eecd77a/SOURCE.ipch new file mode 100644 index 00000000..22b0c6fb Binary files /dev/null and b/C++/Astar/.vs/Astar/v16/ipch/AutoPCH/1e53c8206eecd77a/SOURCE.ipch differ diff --git a/C++/Astar/.vs/Astar/v16/ipch/AutoPCH/2e4c48e3809dcb4c/MYGRAPHICS.ipch b/C++/Astar/.vs/Astar/v16/ipch/AutoPCH/2e4c48e3809dcb4c/MYGRAPHICS.ipch new file mode 100644 index 00000000..23d9080d Binary files /dev/null and b/C++/Astar/.vs/Astar/v16/ipch/AutoPCH/2e4c48e3809dcb4c/MYGRAPHICS.ipch differ diff --git a/C++/Astar/Astar.sln b/C++/Astar/Astar.sln new file mode 100644 index 00000000..e9a2e950 --- /dev/null +++ b/C++/Astar/Astar.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Astar", "Astar\Astar.vcxproj", "{1BD1DB87-A110-4B41-8B0A-5B15A7C2EF96}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1BD1DB87-A110-4B41-8B0A-5B15A7C2EF96}.Debug|x64.ActiveCfg = Debug|x64 + {1BD1DB87-A110-4B41-8B0A-5B15A7C2EF96}.Debug|x64.Build.0 = Debug|x64 + {1BD1DB87-A110-4B41-8B0A-5B15A7C2EF96}.Debug|x86.ActiveCfg = Debug|Win32 + {1BD1DB87-A110-4B41-8B0A-5B15A7C2EF96}.Debug|x86.Build.0 = Debug|Win32 + {1BD1DB87-A110-4B41-8B0A-5B15A7C2EF96}.Release|x64.ActiveCfg = Release|x64 + {1BD1DB87-A110-4B41-8B0A-5B15A7C2EF96}.Release|x64.Build.0 = Release|x64 + {1BD1DB87-A110-4B41-8B0A-5B15A7C2EF96}.Release|x86.ActiveCfg = Release|Win32 + {1BD1DB87-A110-4B41-8B0A-5B15A7C2EF96}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A92B4407-892B-4F3A-827E-91F19C98A7FE} + EndGlobalSection +EndGlobal diff --git a/C++/Astar/Astar/Astar.vcxproj b/C++/Astar/Astar/Astar.vcxproj new file mode 100644 index 00000000..ed623995 --- /dev/null +++ b/C++/Astar/Astar/Astar.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1bd1db87-a110-4b41-8b0a-5b15a7c2ef96} + Astar + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/C++/Astar/Astar/Astar.vcxproj.filters b/C++/Astar/Astar/Astar.vcxproj.filters new file mode 100644 index 00000000..3e7e62e8 --- /dev/null +++ b/C++/Astar/Astar/Astar.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/C++/Astar/Astar/Astar.vcxproj.user b/C++/Astar/Astar/Astar.vcxproj.user new file mode 100644 index 00000000..88a55094 --- /dev/null +++ b/C++/Astar/Astar/Astar.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/C++/Astar/Astar/Debug/Astar.exe.recipe b/C++/Astar/Astar/Debug/Astar.exe.recipe new file mode 100644 index 00000000..07be1f3f --- /dev/null +++ b/C++/Astar/Astar/Debug/Astar.exe.recipe @@ -0,0 +1,11 @@ + + + + + D:\University\Semester 6\AI\Astar\Debug\Astar.exe + + + + + + \ No newline at end of file diff --git a/C++/Astar/Astar/Debug/Astar.log b/C++/Astar/Astar/Debug/Astar.log new file mode 100644 index 00000000..1595fe13 --- /dev/null +++ b/C++/Astar/Astar/Debug/Astar.log @@ -0,0 +1,8 @@ + Source.cpp +D:\University\Semester 6\AI\Astar\Astar\Source.cpp(10,1): warning C4005: 'INFINITY': macro redefinition +C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_math.h(88): message : see previous definition of 'INFINITY' +D:\University\Semester 6\AI\Astar\Astar\Source.cpp(255,21): warning C4129: 'E': unrecognized character escape sequence +D:\University\Semester 6\AI\Astar\Astar\Source.cpp(232,17): warning C4244: 'initializing': conversion from 'int' to 'float', possible loss of data +D:\University\Semester 6\AI\Astar\Astar\Source.cpp(232,56): warning C4244: 'initializing': conversion from 'int' to 'float', possible loss of data +D:\University\Semester 6\AI\Astar\Astar\Source.cpp(243,76): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data + Astar.vcxproj -> D:\University\Semester 6\AI\Astar\Debug\Astar.exe diff --git a/C++/Astar/Astar/Debug/Astar.tlog/Astar.lastbuildstate b/C++/Astar/Astar/Debug/Astar.tlog/Astar.lastbuildstate new file mode 100644 index 00000000..9a8f3b95 --- /dev/null +++ b/C++/Astar/Astar/Debug/Astar.tlog/Astar.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.28.29910:TargetPlatformVersion=10.0.19041.0: +Debug|Win32|D:\University\Semester 6\AI\Astar\| diff --git a/C++/Astar/Astar/Debug/Astar.tlog/CL.command.1.tlog b/C++/Astar/Astar/Debug/Astar.tlog/CL.command.1.tlog new file mode 100644 index 00000000..263b808d Binary files /dev/null and b/C++/Astar/Astar/Debug/Astar.tlog/CL.command.1.tlog differ diff --git a/C++/Astar/Astar/Debug/Astar.tlog/CL.read.1.tlog b/C++/Astar/Astar/Debug/Astar.tlog/CL.read.1.tlog new file mode 100644 index 00000000..e47b7982 Binary files /dev/null and b/C++/Astar/Astar/Debug/Astar.tlog/CL.read.1.tlog differ diff --git a/C++/Astar/Astar/Debug/Astar.tlog/CL.write.1.tlog b/C++/Astar/Astar/Debug/Astar.tlog/CL.write.1.tlog new file mode 100644 index 00000000..0b64d882 Binary files /dev/null and b/C++/Astar/Astar/Debug/Astar.tlog/CL.write.1.tlog differ diff --git a/C++/Astar/Astar/Debug/Astar.tlog/link.command.1.tlog b/C++/Astar/Astar/Debug/Astar.tlog/link.command.1.tlog new file mode 100644 index 00000000..20bf2fd0 Binary files /dev/null and b/C++/Astar/Astar/Debug/Astar.tlog/link.command.1.tlog differ diff --git a/C++/Astar/Astar/Debug/Astar.tlog/link.read.1.tlog b/C++/Astar/Astar/Debug/Astar.tlog/link.read.1.tlog new file mode 100644 index 00000000..94dcab72 Binary files /dev/null and b/C++/Astar/Astar/Debug/Astar.tlog/link.read.1.tlog differ diff --git a/C++/Astar/Astar/Debug/Astar.tlog/link.write.1.tlog b/C++/Astar/Astar/Debug/Astar.tlog/link.write.1.tlog new file mode 100644 index 00000000..8f00a0f1 Binary files /dev/null and b/C++/Astar/Astar/Debug/Astar.tlog/link.write.1.tlog differ diff --git a/C++/Astar/Astar/Debug/Source.obj b/C++/Astar/Astar/Debug/Source.obj new file mode 100644 index 00000000..7a8b3040 Binary files /dev/null and b/C++/Astar/Astar/Debug/Source.obj differ diff --git a/C++/Astar/Astar/Debug/vc142.idb b/C++/Astar/Astar/Debug/vc142.idb new file mode 100644 index 00000000..9952cb1f Binary files /dev/null and b/C++/Astar/Astar/Debug/vc142.idb differ diff --git a/C++/Astar/Astar/Debug/vc142.pdb b/C++/Astar/Astar/Debug/vc142.pdb new file mode 100644 index 00000000..134e368b Binary files /dev/null and b/C++/Astar/Astar/Debug/vc142.pdb differ diff --git a/C++/Astar/Astar/Source.cpp b/C++/Astar/Astar/Source.cpp new file mode 100644 index 00000000..7937805f --- /dev/null +++ b/C++/Astar/Astar/Source.cpp @@ -0,0 +1,346 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INFINITY 9999999 +#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) + +using namespace std; + + +class TextAttr { + friend std::ostream& operator<<(std::ostream& out, TextAttr attr) + { + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), attr.value); + return out; + } +public: + explicit TextAttr(WORD attributes) : value(attributes) {} +private: + WORD value; +}; + +class Point { +public: + int x, y; + Point() + {} + Point(int i, int j) + { + x = i; y = j; + } + void setp(int i, int j) + { + x = i, y = j; + } +}; + +class Node { +public: + Point point; + bool visited = false; + bool blocked = false; + bool inPath = false; + vector neighbours; + Node* parent; + float gValue, hValue; + + bool operator == (const Node& o) { return point.x == o.point.x && point.y == o.point.y; } + bool operator == (const Point& o) { return point.x == o.x && point.y == o.y; + } + //bool operator < (const Node& o) { return hValue < o.hValue; } + +}; + + +class map { +public: + + Node* start; Node* end; + Node** mat; + int w, h; + map(int height , int width) { + h = height; w = width; + mat = new Node * [w]; + for (int r = 0; r < w; r++) { + mat[r] = new Node[h]; + for (int s = 0; s < h; s++) + { + mat[r][s].point.setp(r, s); + mat[r][s].blocked = false; + mat[r][s].parent = nullptr; + mat[r][s].visited = false; + mat[r][s].gValue = INFINITY; + mat[r][s].hValue = INFINITY; + } + } + //add neighbours + for (int i = 0; i < w; i++) { + + for (int j = 0; j < h; j++) + { + if (j > 0) + mat[i][j].neighbours.push_back(&mat[i][j - 1]); + if (j < h-1) + mat[i][j].neighbours.push_back(&mat[i][j + 1]); + if (i > 0) + mat[i][j].neighbours.push_back(&mat[i-1][j ]); + if (i < w - 1) + mat[i][j].neighbours.push_back(&mat[i+1][j ]); + if (i > 0 && j > 0) + mat[i][j].neighbours.push_back(&mat[i - 1 ][j - 1]); + if (i < w-1 && j < h-1) + mat[i][j].neighbours.push_back(&mat[i + 1][j + 1]); + if (i > 0 && j < h-1) + mat[i][j].neighbours.push_back(&mat[i - 1][j + 1]); + if (i < w-1 && j > 0) + mat[i][j].neighbours.push_back(&mat[i + 1][j - 1]); + } + } + } + + void addBlocks(int val) + { + srand((unsigned)time(0)); + float temp = float(val) / 100; + float num = (h * w) * temp; + while (num > 0) + { + int x = rand() % w; + int y = rand() % h; + while (1) { + if (!mat[x][y].blocked) { + mat[x][y].blocked = true; + break; + } + x = rand() % w; + y = rand() % h; + } + num--; + } + } + + bool setStart(int x, int y) + { + Point p(x, y); + if (isValid(p)) { + start = &mat[x][y]; + start->gValue = 0; + return true; + } + return false; + } + bool setend(int x, int y) + { + Point p(x, y); + if (isValid(p)) { + end = &mat[x][y]; + return true; + } + return false; + } + bool isValid(Point& p) { + return (p.x > -1 && p.y > -1 && p.x < w && p.y < h); + } + + void print(){ + for (int i = 0; i < w; i++) + { + cout << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_BLUE); + cout << '|'; + cout << TextAttr(FOREGROUND_WHITE); + for (int j = 0; j < h; j++) + { + //cout << '|'; + if (mat[i][j].blocked) { + cout << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_RED); + cout << 'x'; + cout << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_BLUE); + cout << '|'; + cout << TextAttr(FOREGROUND_WHITE); + } + else if (mat[i][j].inPath) { + if (&mat[i][j] == start) + cout << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_GREEN); + else if (&mat[i][j] == end) + cout << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_RED); + else + cout << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_BLUE); + cout << char(219); + cout << char(219); + + cout << TextAttr(FOREGROUND_WHITE); + } + else { + if (&mat[i][j] == start) + { + cout << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_GREEN); + cout << char(219); + cout << char(219); + cout << TextAttr(FOREGROUND_WHITE); + } + else if (&mat[i][j] == end) + { + cout << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_RED); + cout << char(219); + cout << char(219); + cout << TextAttr(FOREGROUND_WHITE); + } + else + { + //cout << TextAttr(FOREGROUND_WHITE); + cout << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_BLUE); + cout << '_'; + + cout << '|'; + cout << TextAttr(FOREGROUND_WHITE); + + } + } + } + //cout << '|'; + cout << endl; + } + } + + ~map() + { + for (int i = 0; i < w; i++) + delete[] mat[i]; + delete[] mat; + } +}; + +class aStar { +public: + + map* m; + list listNotTested; + aStar(map* map) { + m = map; + m->start->hValue = calHeuristic(*(m->start)); + listNotTested.push_back(m->start); + } + + float calHeuristic(Node p) { + + float x = m->end->point.x - p.point.x; float y = m->end->point.y - p.point.y; + return sqrtf(x * x + y * y); + } + + bool isValid(Point& p) { + return (p.x > -1 && p.y > -1 && p.x < m->w&& p.y < m->h); + } + + + float distance(Node* a, Node* b) // For convenience + { + return sqrtf((a->point.x - b->point.x) * (a->point.x - b->point.x) + (a->point.y - b->point.y) * (a->point.y - b->point.y)); + }; + + bool search() + { + if (m->start->blocked) + { + cout << "\nStart location blocked\n"; + return 0; + } + if (m->end->blocked) + { + cout << "\End location blocked\n"; + return 0; + } + Node* current = m->start; + m->start->hValue = calHeuristic(*m->start); + while (!listNotTested.empty() && current != m->end) + { + listNotTested.sort([](const Node* l, const Node* r) {return l->hValue < r->hValue; }); + + while(!listNotTested.empty() && listNotTested.front()->visited) + listNotTested.pop_front(); + + if (listNotTested.empty()) + break; + + current = listNotTested.front(); + current->visited = true; + for (auto n : current->neighbours) + { + if (!n->blocked && !n->visited) + listNotTested.push_back(n); + float newG = current->gValue + distance(current, n); + //float newG = current->gValue + 1; + + if (newG < n->gValue) + { + n->parent = current; + n->gValue = newG; + n->hValue = n->gValue + calHeuristic(*n); + } + } + } + current = m->end->parent; int count = 0; + if (current == nullptr) + return false; + cout << "Path:\n"; + while (current != nullptr) + { + current->inPath = true; + cout << " ( " << current->point.x << "," << current->point.y << " ) \n"; + current = current->parent; + count++; + } + cout << "\nCost: " << count << endl; + return true; + } + + + +}; + +int main() { + while (1) { + int rows, cols, blocks; + cout << "Enter rows: "; + cin >> rows; + cout << "Enter columns: "; + cin >> cols; + map* m = new map(rows, cols); + + cout << "Enter Start row: "; + cin >> rows; + cout << "Enter Start column: "; + cin >> cols; + m->setStart(rows, cols); + cout << "Enter End row: "; + cin >> rows; + cout << "Enter End column: "; + cin >> cols; + m->setend(rows, cols); + cout << "What percentage of obstacles are there: "; + cin >> blocks; + m->addBlocks(blocks); + cout << "\nMAP\n\n"; + m->print(); + cout << "\n ---A* Algo--- \n" << endl; + aStar a(m); + cout << "\n\n"; + if (a.search()) + m->print(); + + char temp; + cout << "\nPress n to end||Any letter to continue\n"; + cin >> temp; + if (toupper(temp) == 'N') + break; + system("CLS"); + cout << "CONTINUED!\n"; + + } + return 0; +} \ No newline at end of file diff --git a/C++/Astar/Astar/mygraphics.cpp b/C++/Astar/Astar/mygraphics.cpp new file mode 100644 index 00000000..457321b1 --- /dev/null +++ b/C++/Astar/Astar/mygraphics.cpp @@ -0,0 +1,126 @@ +#define _WIN32_WINNT 0x0500 + +#include +#include +#include +#include +#include +#include +#include "string" +#include "mygraohics.h" +void myLine(int x1, int y1, int x2, int y2,COLORREF lineColor) +{ + + HWND console_handle = GetConsoleWindow(); + HDC device_context = GetDC(console_handle); + + //change the color by changing the values in RGB (from 0-255) + HPEN pen =CreatePen(PS_SOLID,2,lineColor); //2 is the width of the pen + SelectObject(device_context,pen); + MoveToEx(device_context,x1,y1,NULL); + LineTo(device_context,x2, y2); + DeleteObject(pen); + + ReleaseDC(console_handle, device_context); +} +void myRect(int x1, int y1, int x2, int y2,COLORREF lineColor,COLORREF fillColor) +{ + HWND console_handle = GetConsoleWindow(); + HDC device_context = GetDC(console_handle); + + //change the color by changing the values in RGB (from 0-255) + HPEN pen =CreatePen(PS_SOLID,2,lineColor); + SelectObject(device_context,pen); + HBRUSH brush = ::CreateSolidBrush(fillColor); + SelectObject(device_context,brush); + + Rectangle(device_context,x1,y1,x2,y2); + DeleteObject(pen); + DeleteObject(brush); + ReleaseDC(console_handle, device_context); +} +void myEllipse(int x1, int y1, int x2, int y2,COLORREF lineColor,COLORREF fillColor) +{ + HWND console_handle = GetConsoleWindow(); + HDC device_context = GetDC(console_handle); + + //change the color by changing the values in RGB (from 0-255) + HPEN pen =CreatePen(PS_SOLID,2,lineColor); + SelectObject(device_context,pen); + HBRUSH brush = ::CreateSolidBrush(fillColor); + SelectObject(device_context,brush); + Ellipse(device_context,x1,y1,x2,y2); + DeleteObject(pen); + DeleteObject(brush); + ReleaseDC(console_handle, device_context); + +} + +void myDrawText(int x,int y,int ht,char str[],COLORREF lineColor,COLORREF fillColor) +{ + WCHAR wstr[200]={}; + for (int i=0;i<200&&str[i];++i) + wstr[i] = str[i]; + + RECT rects; + rects.left = x; + rects.top = y; + rects.right = x+ht; + rects.bottom = y+ht;//(x,y,x+ht,y+ht); + + HWND console_handle = GetConsoleWindow(); + HDC device_context = GetDC(console_handle); + + SetTextColor(device_context,lineColor); + SetBkColor(device_context,fillColor); + LPCSTR temp; + temp=str; + DrawText(device_context, temp, -1, &rects, DT_TOP | DT_NOCLIP); + + ReleaseDC(console_handle, device_context); + +} + +void myDrawTextWithFont(int x,int y,int ht,char str[],COLORREF lineColor,COLORREF fillColor) +{ + + WCHAR wstr[200]={}; + for (int i=0;i<200&&str[i];++i) + wstr[i] = str[i]; + + RECT rects; + HFONT hFont; + rects.left = x; + rects.top = y; + rects.right = x+ht; + rects.bottom = y+ht;//(x,y,x+ht,y+ht); + + HWND console_handle = GetConsoleWindow(); + HDC device_context = GetDC(console_handle); + hFont = CreateFont(ht,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS, + CLIP_DEFAULT_PRECIS,1, VARIABLE_PITCH,TEXT("Impact")); + SelectObject(device_context, hFont); + + SetTextColor(device_context,lineColor); + SetBkColor(device_context,fillColor); + + + LPCSTR temp; + temp=str; + DrawText(device_context,temp,-1,&rects,DT_TOP|DT_NOCLIP); + DeleteObject(hFont); + ReleaseDC(console_handle, device_context); + +} + +void mySetPixel(int x,int y,COLORREF colorVal) +{ + HWND console_handle = GetConsoleWindow(); + HDC device_context = GetDC(console_handle); + + SetPixel(device_context,x,y,colorVal); + ReleaseDC(console_handle,device_context); +} + + + diff --git a/C++/Astar/Astar/mygraphics.h b/C++/Astar/Astar/mygraphics.h new file mode 100644 index 00000000..a5857528 --- /dev/null +++ b/C++/Astar/Astar/mygraphics.h @@ -0,0 +1,56 @@ +#ifndef MYGRAPHICS_H +#define MYGRAPHICS_H +#include + + +//To compile your program with graphics.cpp you need to include the gdi32 library +//compile it using: g++ -o myprog.exe myprog.cpp graphics.cpp -lgdi32 +// for visual studio if you get linker errors then goto properties->linker->input and add the library +//gdi32.lib or gdi64.lib depending on your system. Normally this libaray is added by default so you may be able +//to compile the code. + + +//set the color of a pixel at (x,y) to colorVal +//create a color using different values of red (R), green (G) and blue (B) +//for example c is a color value, whose type is COLORREF: COLORREF c = RGB(30,300,20); +//usage exammple: mySetPixel(200,200,RGB(230,0,0)); +void mySetPixel(int x,int y, COLORREF colorVal); + + +//draw a line from (x1,y1) to (x2,y2) using lineColor +//create a color using different values of red (R), green (G) and blue (B) +//for example c is a color value, whose type is COLORREF: COLORREF c = RGB(30,300,20); +//usage example: myLine(0,0,300,400,RGB(200,0,0)); +void myLine(int x1, int y1, int x2, int y2, COLORREF lineColor); + +//draw a rectangle with top corner (x1,y1) and bottom corner(x2,y2) with outline lineColor +//and fillColor +//create a color using different values of red (R), green (G) and blue (B) +//for example c is a color value, whose type is COLORREF: COLORREF c = RGB(30,300,20); +//usage example: myRect(300,300,350,350,RGB(100,0,0),RGB(0,0,240)); +void myRect(int x1, int y1, int x2, int y2,COLORREF lineColor,COLORREF fillColor); + +//draw an ellipse within a rectangle with top corner (x1,y1) and bottom corner(x2,y2) +//create a color using different values of red (R), green (G) and blue (B) +//for example c is a color value, whose type is COLORREF: COLORREF c = RGB(30,300,20); +//usage example: myEllipse(100,50,180,200,RGB(100,0,0),RGB(0,0,240)); +void myEllipse(int x1, int y1, int x2, int y2,COLORREF colorForeground,COLORREF colorBackground) +; + +//write a string at position (x,y) in lineColor and background color as fillColor +//create a color using different values of red (R), green (G) and blue (B) +//for example c is a color value, whose type is COLORREF: COLORREF c = RGB(30,300,20); +//usage example: myDrawText(100,200,40,"Good day",RGB(200,0,200),RGB(3,200,3)); +void myDrawText(int x,int y,int ht,char str [],COLORREF lineColor,COLORREF fillColor); + + +//write a string at position (x,y) in lineColor and background color as fillColor +//the font size will be determined by the ht parameter +//create a color using different values of red (R), green (G) and blue (B) +//for example c is a color value, whose type is COLORREF: COLORREF c = RGB(30,300,20); +//usage example: myDrawText(100,200,40,"Good day",RGB(200,0,200),RGB(3,200,3)); +void myDrawTextWithFont(int x,int y,int ht,char str[],COLORREF lineColor,COLORREF fillColor); + +#endif + + diff --git a/C++/Astar/Debug/Astar.exe b/C++/Astar/Debug/Astar.exe new file mode 100644 index 00000000..e8471e03 Binary files /dev/null and b/C++/Astar/Debug/Astar.exe differ diff --git a/C++/Astar/Debug/Astar.ilk b/C++/Astar/Debug/Astar.ilk new file mode 100644 index 00000000..7395285c Binary files /dev/null and b/C++/Astar/Debug/Astar.ilk differ diff --git a/C++/Astar/Debug/Astar.pdb b/C++/Astar/Debug/Astar.pdb new file mode 100644 index 00000000..ca94295c Binary files /dev/null and b/C++/Astar/Debug/Astar.pdb differ