proj home

Files   Classes   Functions   Hierarchy  

mazegameD2solver01 Class Reference

Solve D2 maze - rough solution. More...

#include <mazegameD2solver01.h>

Collaboration diagram for mazegameD2solver01:

List of all members.

Public Types

typedef set< uintuintset

Public Member Functions

 mazegameD2solver01 (mazegameD2state01 &mg_)
 Constructor.
boolc pathcontains (uintc k) const
 Is the cell already on the path?
void reset ()
 Set to beginning of game.
boolc operator! () const
 Invalid if already found solution or no more moves.
void operator++ ()
 Next step.

Public Attributes

mazegameD2state01mg
 State.
vector< cellD2< uint > > & vi
uintset visited
 List of visited cells.


Detailed Description

Solve D2 maze - rough solution.

Definition at line 14 of file mazegameD2solver01.h.


Member Typedef Documentation

Definition at line 26 of file mazegameD2solver01.h.


Constructor & Destructor Documentation

mazegameD2solver01::mazegameD2solver01 ( mazegameD2state01 mg_  ) 

Constructor.

Definition at line 6 of file mazegameD2solver01.cpp.

00007   : mg(mg_), vi(mg.mz.vi)
00008 {
00009 }


Member Function Documentation

boolc mazegameD2solver01::operator! (  )  const

Invalid if already found solution or no more moves.

Definition at line 34 of file mazegameD2solver01.cpp.

References mazegameD2state01::gamefinish, mg, and pathcontains().

00035 {
00036   if (pathcontains(mg.gamefinish))
00037     return false;
00038 
00039   return true;
00040 }

void mazegameD2solver01::operator++ (  ) 

Next step.

Definition at line 42 of file mazegameD2solver01.cpp.

References mazegameD2state01::currentpos(), mg, mazegameD2state01::path, vi, and visited.

00043 {
00044   // Try moving forward.
00045 
00046   uint cpi=mg.currentpos();
00047   assert(cpi!=0);
00048 
00049   uint k2;
00050   uint gi[4];
00051   uint gisize=0;
00052   for (uint i=0; i<4; ++i)
00053   {
00054     k2 = vi[cpi].ni[i];
00055     if (k2==0)
00056       continue;
00057 
00058     if (visited.find(k2)!=visited.end())
00059       continue;
00060 
00061     gi[gisize] = k2;
00062     ++gisize;
00063   }
00064 
00065   if (gisize!=0)
00066   {
00067     // pick one and move forward
00068     k2 = gi[ rand() % gisize ];
00069     mg.path.push_back(k2);
00070     visited.insert(k2);
00071     return;
00072   } 
00073     
00074   // Must backtrack.
00075   assert(mg.path.size()>1);
00076   mg.path.pop_back();
00077 }

boolc mazegameD2solver01::pathcontains ( uintc  k  )  const

Is the cell already on the path?

Definition at line 21 of file mazegameD2solver01.cpp.

References assertreturnfalse, mg, and mazegameD2state01::path.

Referenced by operator!().

00022 {
00023   assertreturnfalse(k!=0);
00024 
00025   for (uint i=0; i<mg.path.size(); ++i)
00026   {
00027     if (mg.path[i]==k)
00028       return true;
00029   }
00030  
00031   return false; 
00032 }

void mazegameD2solver01::reset (  ) 

Set to beginning of game.

Definition at line 11 of file mazegameD2solver01.cpp.

References mazegameD2state01::gamestart, mg, mazegameD2state01::path, and visited.

Referenced by maze005::eval().

00012 {
00013   mg.path.clear();
00014   mg.path.push_back(mg.gamestart);
00015 
00016   visited.clear();
00017   visited.insert(0);
00018   visited.insert(mg.gamestart);
00019 }


Member Data Documentation

State.

Definition at line 18 of file mazegameD2solver01.h.

Referenced by operator!(), operator++(), pathcontains(), and reset().

Definition at line 20 of file mazegameD2solver01.h.

Referenced by operator++().

List of visited cells.

Definition at line 28 of file mazegameD2solver01.h.

Referenced by operator++(), and reset().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:05 2011 for Chelton Evans Source by  doxygen 1.5.8