Files Classes Functions Hierarchy
#include <mazegameD2state01.h>
Public Member Functions | |
| mazegameD2state01 () | |
| Uninitialized state. | |
| void | game01 () |
| Build the maze from the current settings. | |
| void | game01default () |
| Default settings for game01, does not leave in a valid state. | |
| boolc | valid () const |
| Validate game and maze. | |
| stringc | settings () const |
| This class's command line settings. | |
| uintc | currentpos () const |
| Return current position id in maze. | |
| boolc | currentmove (uintc dir) |
| If possible move in dir direction. | |
| operator stringc () const | |
| Serialize. | |
| void | serializeInverse (stringc &str) |
Public Attributes | |
| uint & | m |
| Number of rows in maze. | |
| uint & | n |
| Number of columns in maze. | |
| vector< uint > | path |
| The current position is the last element. | |
| uint | gamestart |
| Starting index into maze. | |
| uint | gamefinish |
| Finishing index into maze. | |
| bool | randomize |
| For repeated testing with same outcome set to false. | |
| bool | proper |
| If true only a proper maze is generated. | |
| double | deletewall |
| Ratio of chance of deleting wall when proper set to false. | |
| mazematrixD2< uint > | mz |
| Maze. | |
Set the variables and call game01.
Definition at line 16 of file mazegameD2state01.h.
| mazegameD2state01::mazegameD2state01 | ( | ) |
Uninitialized state.
Definition at line 23 of file mazegameD2state01.cpp.
References game01default().
If possible move in dir direction.
Definition at line 101 of file mazegameD2state01.cpp.
References currentpos(), mz, path, and mazematrixD2< T >::vi.
Referenced by maze005::special01(), and maze004::special01().
00102 { 00103 assert(dir<4); 00104 00105 bool res=false; 00106 uint k2; 00107 00108 k2 = mz.vi[currentpos()].ni[dir]; 00109 if (k2!=0) 00110 res=true; 00111 00112 // mz.move(res,k2,dir,currentpos()); 00113 00114 if (res==false) 00115 return false; 00116 00117 if (path.size()>1) 00118 { 00119 if (path[path.size()-2]==k2) 00120 { 00121 path.pop_back(); 00122 return true; 00123 } 00124 } 00125 00126 path.push_back(k2); 00127 return true; 00128 }
| uintc mazegameD2state01::currentpos | ( | ) | const |
Return current position id in maze.
Definition at line 95 of file mazegameD2state01.cpp.
References path.
Referenced by currentmove(), and mazegameD2solver01::operator++().
| void mazegameD2state01::game01 | ( | ) |
Build the maze from the current settings.
Definition at line 30 of file mazegameD2state01.cpp.
References mazematrixD2createmaze< T >::buildpropermaze(), deletewall, mazematrixD2< T >::dimset(), gamefinish, gamestart, mazematrixD2createmaze< T >::impropermaze01(), m, mz, n, path, proper, randomize, and valid().
Referenced by maze004::maze004(), maze005::maze005(), and mazegameD2state01test::test01().
00031 { 00032 assert(m!=0); 00033 assert(n!=0); 00034 00035 uint mn=m*n; 00036 assert(mn!=0); 00037 if (mn==0) 00038 return; 00039 00040 if (randomize) 00041 srand( (unsigned)time( NULL ) ); 00042 00043 gamestart = gamefinish = 0; 00044 for ( ; gamestart==gamefinish; ) 00045 { 00046 gamestart = 1+(rand()%mn); 00047 gamefinish = 1+(rand()%mn); 00048 } 00049 00050 path.clear(); 00051 path.push_back(gamestart); 00052 00053 mz.dimset(m,n); 00054 mazematrixD2createmaze<uint> mc(mz); 00055 mc.buildpropermaze(); 00056 00057 if (proper==false) 00058 mc.impropermaze01(deletewall); 00059 00060 assert(valid()); 00061 }
| void mazegameD2state01::game01default | ( | ) |
Default settings for game01, does not leave in a valid state.
Definition at line 6 of file mazegameD2state01.cpp.
References deletewall, gamefinish, gamestart, m, n, path, proper, and randomize.
Referenced by mazegameD2state01().
00007 { 00008 m=8; 00009 n=12; 00010 00011 path.clear(); 00012 00013 gamestart=0; 00014 gamefinish=0; 00015 00016 randomize=true; 00017 00018 proper=true; 00019 deletewall=0.025; // 2.5% 00020 }
| mazegameD2state01::operator stringc | ( | ) | const |
Serialize.
Definition at line 130 of file mazegameD2state01.cpp.
References deletewall, gamefinish, gamestart, mz, path, proper, randomize, stringtag(), and stringto().
00131 { 00132 string s1; 00133 s1 += "<mazegameD2state01>\n"; 00134 00135 s1 += stringtag(gamestart,"gamestart"); 00136 s1 += stringtag(gamefinish,"gamefinish"); 00137 s1 += stringtag(path.size(),"pathsize"); 00138 s1 += "<path>\n"; 00139 for (uint i=0; i<path.size(); ++i) 00140 { 00141 s1 += stringto(path[i]); 00142 s1 += " "; 00143 } 00144 s1 += "\n</path>\n"; 00145 s1 += stringtag(randomize,"randomize"); 00146 s1 += stringtag(proper,"proper"); 00147 s1 += stringtag(deletewall,"deletewall"); 00148 00149 s1 += (stringc)mz; 00150 s1 += "</mazegameD2state01>\n"; 00151 00152 return s1; 00153 }
| void mazegameD2state01::serializeInverse | ( | stringc & | str | ) |
Definition at line 156 of file mazegameD2state01.cpp.
References deletewall, gamefinish, gamestart, mz, n, path, proper, randomize, mazematrixD2< T >::serializeInverse(), and stringfrom().
Referenced by mazegameD2state01test::test01().
00157 { 00158 string s2(stringtagparser(str).data("mazegameD2state01")); 00159 stringfrom(gamestart,stringtagparser(s2).data("gamestart")); 00160 stringfrom(gamefinish,stringtagparser(s2).data("gamefinish")); 00161 stringfrom(randomize,stringtagparser(s2).data("randomize")); 00162 stringfrom(proper,stringtagparser(s2).data("proper")); 00163 stringfrom(deletewall,stringtagparser(s2).data("deletewall")); 00164 00165 path.clear(); 00166 uint n; 00167 stringfrom(n,stringtagparser(s2).data("pathsize")); 00168 { 00169 uint k; 00170 stringstream ss(stringtagparser(s2).data("path")); 00171 for (uint i=0; i<n; ++i) 00172 { 00173 ss >> k; 00174 path.push_back(k); 00175 } 00176 } 00177 00178 mz.serializeInverse(s2); 00179 }
| stringc mazegameD2state01::settings | ( | ) | const |
This class's command line settings.
Definition at line 79 of file mazegameD2state01.cpp.
References deletewall, gamefinish, gamestart, m, n, proper, randomize, and stringconvert::tostring().
Referenced by maze004::maze004(), and maze005::maze005().
00080 { 00081 string options=""; 00082 string s; 00083 00084 options += ( "m=" + stringconvert::tostring(m) + " " ); 00085 options += ( "n=" + stringconvert::tostring(n) + " " ); 00086 options += ( "gamestart=" + stringconvert::tostring(gamestart) + " " ); 00087 options += ( "gamefinish=" + stringconvert::tostring(gamefinish) + " " ); 00088 options += ( "randomize=" + stringconvert::tostring(randomize) + " " ); 00089 options += ( "proper=" + stringconvert::tostring(proper) + " " ); 00090 options += ( "deletewall=" + stringconvert::tostring(deletewall) + " " ); 00091 00092 return options; 00093 }
| boolc mazegameD2state01::valid | ( | ) | const |
Validate game and maze.
Definition at line 63 of file mazegameD2state01.cpp.
References assertreturnfalse, mazematrixD2< T >::dim, gamefinish, gamestart, mz, and mazematrixD2< T >::valid().
Referenced by game01(), maze004::maze004(), and maze005::maze005().
00064 { 00065 //cout << SHOW(m) << endl; 00066 //cout << SHOW(mz.dim[0]) << endl; 00067 00068 //cout << SHOW(gamestart) << " " << SHOW(gamefinish) << " " << SHOW(mz.dim[2]) << endl; 00069 00070 assertreturnfalse(mz.valid()); 00071 //assertreturnfalse(m==mz.dim[0]); 00072 //assertreturnfalse(n==mz.dim[1]); 00073 assertreturnfalse(!((gamestart==0)||(gamestart>mz.dim[2]))); 00074 assertreturnfalse(!((gamefinish==0)||(gamefinish>mz.dim[2]))); 00075 00076 return true; 00077 }
Ratio of chance of deleting wall when proper set to false.
Definition at line 44 of file mazegameD2state01.h.
Referenced by game01(), game01default(), maze004::maze004(), maze005::maze005(), operator stringc(), serializeInverse(), and settings().
Finishing index into maze.
Definition at line 34 of file mazegameD2state01.h.
Referenced by game01(), game01default(), operator stringc(), mazegameD2solver01::operator!(), serializeInverse(), settings(), mazedisp03::staticgraphics(), and valid().
Starting index into maze.
Definition at line 32 of file mazegameD2state01.h.
Referenced by game01(), game01default(), operator stringc(), mazegameD2solver01::reset(), serializeInverse(), settings(), mazedisp03::staticgraphics(), and valid().
Number of rows in maze.
Definition at line 21 of file mazegameD2state01.h.
Referenced by game01(), game01default(), maze004::maze004(), maze005::maze005(), settings(), and mazegameD2state01test::test01().
Maze.
Definition at line 53 of file mazegameD2state01.h.
Referenced by mazedisp03::cellmidpoint(), currentmove(), game01(), operator stringc(), serializeInverse(), mazedisp03::staticgraphics(), and valid().
Number of columns in maze.
Definition at line 23 of file mazegameD2state01.h.
Referenced by game01(), game01default(), maze004::maze004(), maze005::maze005(), serializeInverse(), settings(), and mazegameD2state01test::test01().
| vector<uint> mazegameD2state01::path |
The current position is the last element.
Definition at line 29 of file mazegameD2state01.h.
Referenced by currentmove(), currentpos(), mazedisp03::currentposdraw(), game01(), game01default(), operator stringc(), mazegameD2solver01::operator++(), mazegameD2solver01::pathcontains(), mazegameD2solver01::reset(), and serializeInverse().
If true only a proper maze is generated.
Definition at line 41 of file mazegameD2state01.h.
Referenced by game01(), game01default(), maze004::maze004(), maze005::maze005(), operator stringc(), serializeInverse(), and settings().
For repeated testing with same outcome set to false.
Definition at line 38 of file mazegameD2state01.h.
Referenced by game01(), game01default(), maze004::maze004(), maze005::maze005(), operator stringc(), serializeInverse(), and settings().
1.5.8