001: // ConsoleApp.cpp : Defines the entry point for the console application.

002: //

003: 
004: #include "stdafx.h"
005: #include <stdlib.h>
006: #include "ConsoleApp.h"
007: 
008: #ifdef _DEBUG
009: #define new DEBUG_NEW
010: #undef THIS_FILE
011: static char THIS_FILE[] = __FILE__;
012: #endif

013: 
014: #include "..\UKPuzzleCore.h"
015: 
016: /////////////////////////////////////////////////////////////////////////////

017: // The one and only application object

018: 
019: #define UKTESTENVIRONMENNT
020: 
021: CWinApp theApp;
022: 
023: using namespace std;
024: 
025: int __cdecl _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
026: {
027:         int nRetCode = 0;
028: 
029:         // initialize MFC and print and error on failure

030:         if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
031:         {
032:                 // TODO: change error code to suit your needs

033:                 cerr << _T("Fatal Error: MFC initialization failed") << endl;
034:                 nRetCode = 1;
035:         }
036:         else
037:         {
038:                 TCHAR szPATH[_MAX_PATH];
039:                 TCHAR szDRIVE[_MAX_DRIVE];
040:                 TCHAR szDIR[_MAX_DIR];
041:                 TCHAR szFNAME[_MAX_FNAME];
042:                 TCHAR szEXT[_MAX_EXT];
043: 
044: 
045:                 if (argc>=1)
046:                 {
047:                         //Windows has different behaviors, setting the current directory

048:                         //therefor I set the application path as current directory

049: 
050:                         //Application Name and Path

051:                         _splitpath(argv[0],szDRIVE,szDIR,szFNAME,szEXT);
052:                         _makepath(szPATH,szDRIVE,szDIR,NULL,NULL);
053:                         SetCurrentDirectory(szPATH);
054:                 }
055: 
056:                 CString strIniFileName="";
057:                 long nStoneCount=12;
058:                 if (argc>=2)
059:                 {
060:                         strIniFileName=argv[1];
061:                         CUKIniAccess theIniFile(strIniFileName);
062:                         theIniFile.ReadValue("StoneInfo","StoneCount",&nStoneCount);
063:                 }
064: 
065:                 // TODO: code your application's behavior here.

066:                 CUKPuzzleCore theCore;
067:                 long nStartTime=GetTickCount();
068:                 long nCounter1=0;
069:                 long nCounter2=0;
070:                 long nCounter3=0;
071:                 long nSum=0;
072: 
073: #ifdef UKTESTENVIRONMENNT
074:                 if (!theCore.Init(0,0,strIniFileName,".\\Output.txt"))
075:                         return -1;
076: #else

077:                 if (!theCore.Init(0,nStoneCount,strIniFileName,".\\Output.txt"))
078:                         return -1;
079: #endif

080: 
081:                 cout << "Initialisierung erfolgreich"<< endl;
082: 
083: #ifdef UKTESTENVIRONMENNT
084:                 while (TRUE)
085: #else

086:                 while (!theCore.HasFinished())
087: #endif

088:                 {
089:                         theCore.DoNextStep();
090: #ifdef UKTESTENVIRONMENNT
091:                         if (theCore.HasFinished())
092:                         {
093:                                 nCounter1=MAXLONG-1;//will be incremented later

094:                                 nCounter2=MAXLONG-1;//will be incremented later

095:                         }        
096: #endif

097: 
098:                         nCounter1++;
099: 
100: #ifdef _DEBUG
101:         #ifdef        UKPUZ_FTL
102:                         if (nCounter1>=10000)
103:         #else

104:                         if (nCounter1>=100000)
105:         #endif

106: #else          
107:         #ifdef        UKPUZ_FTL
108:                         if (nCounter1>=100000)
109:         #else

110:                         if (nCounter1>=1000000)
111:         #endif

112: #endif

113:                         {
114:                                 cout <<        ".";
115:                                 nCounter1=0;
116:                                 nCounter2++;
117:                                 if (nCounter2>=74)
118:                                 {
119:                                         //cout <<".";

120:                                         nCounter2=0;
121:                                         CString str0;
122:                                         CString str1;
123:                                         CString str2;
124:                                         str0.Format("%6d",nSum+theCore.GetSolutions());
125:                                         str1.Format("%7.1f",(GetTickCount()-nStartTime)/1000.0);
126:                                         str2.Format("%5.1f",(nSum+theCore.GetSolutions())/((GetTickCount()-nStartTime)/1000.0));
127:                                         cout << endl << (LPCTSTR)str0 << " Loesungen in " << (LPCTSTR)str1 <<" sekunden gefunden ";
128:                                         cout << "==> " << (LPCTSTR)str2 << " Ergebinsse/sekunde" << endl;
129:                                         cout << "Kilo Trys:" << (DWORD)(theCore.m_nTrys/1000) <<endl;
130: #ifdef UKTESTENVIRONMENNT
131:                                         nSum+=theCore.GetSolutions();
132:                                         nCounter3++;
133:                                         theCore.Init(nCounter3,nCounter3,strIniFileName,"");
134: #endif

135:                                 }
136:                         }
137: #ifdef UKTESTENVIRONMENNT
138:                 if (nCounter3>=nStoneCount)
139:                         break;
140: #endif

141:                 }
142: 
143: #ifdef UKTESTENVIRONMENNT
144:                 cout << endl << "Endergebins:" << nSum << " Loesungen in " << (GetTickCount()-nStartTime)/1000 <<" sekunden gefunden" << endl;
145: #else

146:                 cout << endl << "Endergebins:" << theCore.GetSolutions() << " Loesungen in " << (GetTickCount()-nStartTime)/1000 <<" sekunden gefunden" << endl;
147: #endif

148: 
149:                 cout << "Kilo Trys:" << (DWORD)(theCore.m_nTrys/1000) <<endl;
150: 
151:                 cout << endl << "Enter druecken zum beenden:" << endl;
152:                 getchar();
153:                 theCore.Deinit();
154:         }
155: 
156:         return nRetCode;
157: }
158: 
159: