MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions
MFM::WindowScanner< CC > Class Template Reference

#include <WindowScanner.h>

Public Member Functions

 WindowScanner (EventWindow< CC > &window)
 
 ~WindowScanner ()
 
bool FillIfType (const SPoint &relative, const u32 type, const T &atom)
 
bool FillIfNotType (const SPoint &relative, const u32 type, const T &atom)
 
bool FillIfEmpty (const SPoint &relative, const T &atom)
 
bool CanSeeAtomOfType (const u32 type, const u32 radius) const
 
u32 CountAtomsOfType (const u32 type, const u32 radius) const
 
u32 CountEmptyAtoms (const u32 radius) const
 
bool IsBorderingNeighborhood (const u32 type, const Dir *neighborhood, const u32 dirCount) const
 
bool IsBorderingMoore (const u32 type) const
 
bool IsBorderingVonNeumann (const u32 type) const
 
u32 CountInNeighborhood (const u32 type, const Dir *neighborhood, const u32 dirCount) const
 
u32 CountMooreNeighbors (const u32 type) const
 
u32 CountVonNeumannNeighbors (const u32 type) const
 
u32 FindRandomLocationOfType (const u32 type, SPoint &outPoint) const
 
u32 FindRandomLocationOfType (const u32 type, const u32 radius, SPoint &outPoint) const
 
u32 FindRandomInSubWindow (const u32 type, const SPoint *subWindow, const u32 subCount, SPoint &outPoint) const
 
u32 FindEmptyInSubWindow (const SPoint *subWindow, const u32 subCount, SPoint &outPoint) const
 
u32 FindRandomInNeighborhood (const u32 type, const Dir *dirs, const u32 dirCount, SPoint &outPoint) const
 
u32 FindEmptyInNeighborhood (const Dir *dirs, const u32 dirCount, SPoint &outPoint) const
 
u32 FindRandomInMoore (const u32 type, SPoint &outPoint) const
 
u32 FindRandomInVonNeumann (const u32 type, SPoint &outPoint) const
 
u32 FindEmptyInMoore (SPoint &outPoint) const
 
u32 FindEmptyInVonNeumann (SPoint &outPoint) const
 
void FindRandomAtoms (const u32 radius, const u32 count,...) const
 
void FindRandomAtoms (const u32 count,...) const
 
bool FindRandomAtomsInSubWindows (const u32 count,...) const
 

Detailed Description

template<class CC>
class MFM::WindowScanner< CC >

A wrapper for the EventWindow class which allows for EventWindow searching and other powerful EventWindow modifications.

Constructor & Destructor Documentation

template<class CC >
MFM::WindowScanner< CC >::WindowScanner ( EventWindow< CC > &  window)

Constructs a new WindowScanner that is ready to be used on a given EventWindow.

Parameters
windowA reference to the EventWindow which the new instance of this class may read or write to.
template<class CC>
MFM::WindowScanner< CC >::~WindowScanner ( )
inline

Deconstructs this WindowScanner .

Member Function Documentation

template<class CC >
bool MFM::WindowScanner< CC >::CanSeeAtomOfType ( const u32  type,
const u32  radius 
) const

Scans the held EventWindow up to a specified radius (not including the center Atom) and sees whether or not an Atom of a specified type exists.

Parameters
typeThe type of the Atom being scanned for.
radiusThe maximum radius to expand this search to. This FAILs with ILLEGAL_ARGUMENT if this argument is either 0 or greater than the EventWindow radius.
Returns
true if an Atom of type type is found within radius of the center atom (discluding the center atom), else false .
template<class CC >
u32 MFM::WindowScanner< CC >::CountAtomsOfType ( const u32  type,
const u32  radius 
) const

Scans the held EventWindow up to a specified radius (not including the center Atom) and counts the Atoms which are of a specified type.

Parameters
typeThe type of the Atom being scanned for.
radiusThe maximum radius to expand this search to. This FAILs with ILLEGAL_ARGUMENT if this argument is either 0 or greater than the EventWindow radius.
Returns
The number of Atoms of type type within of the center atom (not including the center atom) in the held EventWindow.
template<class CC >
u32 MFM::WindowScanner< CC >::CountEmptyAtoms ( const u32  radius) const

Scans the held EventWindow up to a specified radius (not including the center Atom) and counts the Atoms which represent Element_Empty

Parameters
radiusThe maximum radius to expand this search to. This FAILs with ILLEGAL_ARGUMENT if this argument is either 0 or greater than the EventWindow radius.
Returns
The number of Element_Empty Atoms within of the center atom (not including the center atom) in the held EventWindow.
template<class CC >
u32 MFM::WindowScanner< CC >::CountInNeighborhood ( const u32  type,
const Dir *  neighborhood,
const u32  dirCount 
) const

Scans a specified neighborhood consisting of Dirs directly surrounding the center Atom and counts the Atoms of a specified type.

Parameters
typeThe type of the Atoms to search for.
neighborhoodAn array of Dirs representing the neighborhood around the central Atom.
dirCountThe number of elements inside the neighborhood array.
Returns
The number of Atoms in the specified neighborhood which are of type type.
template<class CC >
u32 MFM::WindowScanner< CC >::CountMooreNeighbors ( const u32  type) const

Scans the moore neighborhood (N, NE, E, SE, S, SW, W, NW) directly surrounding the center Atom and counts the Atoms of a specified type.

Parameters
typeThe type of the Atom to search for.
Returns
The number of Atoms which are of type type in the moore neighborhood of the central atom.
template<class CC >
u32 MFM::WindowScanner< CC >::CountVonNeumannNeighbors ( const u32  type) const

Scans the Von Neumann neighborhood (N, E, S, W) directly surrounding the center Atom and counts the Atoms of a specified type.

Parameters
typeThe type of the Atom to search for.
Returns
The number of Atoms which are of type type in the Von Neumann neighborhood of the central atom.
template<class CC >
bool MFM::WindowScanner< CC >::FillIfEmpty ( const SPoint relative,
const T &  atom 
)

Examines the held EventWindow at a given point and fills the atom there with a specified Atom if it is occupied by an Atom representing Element_Empty.

Parameters
relativeThe loaction of the held EventWindow to examine.
atomThe Atom to place in relative if it is occupied by an Element_Empty Atom.
Returns
true if the Atom at the relative location represents Element_Empty and therefore will be replaced by atom , else false .
template<class CC >
bool MFM::WindowScanner< CC >::FillIfNotType ( const SPoint relative,
const u32  type,
const T &  atom 
)

Replaces the Atom at a specified relative location from the center Atom of the held EventWindow with another specified atom if the existing atom is not of a particular type.

Parameters
relativeThe location, relative to the center of the held EventWindow, of the Atom to inspect and perhaps replace.
typeThe type of the Atom supposed to be in the relative location. If the Atom in relative is not this type, it will be replaced with the specified Atom.
atomThe Atom to write to relative if the existing Atom is not type type .
Returns
true if the atom at relative was replaced by atom , else false.
template<class CC >
bool MFM::WindowScanner< CC >::FillIfType ( const SPoint relative,
const u32  type,
const T &  atom 
)

Replaces the Atom at a specified relative location from the center Atom of the held EventWindow with another specified atom if the existing atom is of a particular type.

Parameters
relativeThe location, relative to the center of the held EventWindow, of the Atom to inspect and perhaps replace.
typeThe type of the Atom supposed to be in the relative location. If the Atom in relative is this type, it will be replaced with the specified Atom.
atomThe Atom to write to relative if the existing Atom is type type .
Returns
true if the atom at relative was replaced by atom , else false.
template<class CC >
u32 MFM::WindowScanner< CC >::FindEmptyInMoore ( SPoint outPoint) const

Searches the Moore neighborhood around the center atom of the held EventWindow for an Atom representing Element_Empty , giving its location if found.

Parameters
outPointan output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one representing Element_Empty is located. If this method returns 0 , the contents of this SPoint are undefined.
Returns
The number of Atoms in the center Atom's Moore neighborhood representing Element_Empty.
template<class CC >
u32 MFM::WindowScanner< CC >::FindEmptyInNeighborhood ( const Dir *  dirs,
const u32  dirCount,
SPoint outPoint 
) const

Searches a specified neighborhood around the center atom of the held EventWindow for an Atom representing Element_Empty , giving its location if found.

Parameters
dirsAn array of Dirs specifying the neighborhood to search around the center Atom.
dirCountThe number of Dir elements inside of dirs .
outPointan output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one representing Element_Empty is located. If this method returns false , the contents of this SPoint are undefined.
Returns
The number of Atoms in the center Atom's specified neighborhood representing Element_Empty
template<class CC >
u32 MFM::WindowScanner< CC >::FindEmptyInSubWindow ( const SPoint subWindow,
const u32  subCount,
SPoint outPoint 
) const

Scans a subset of the held EventWindow, specified by a given set of relative Points, for an Atom representing Element_Empty, placing the location of a randomly chosen Atom in an output Point.

Parameters
subWindowThe array of relative Points to search through.
subCountThe length of the subWindow array.
outPointAn output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one of the correct type is located. If this method returns 0 , the contents of this SPoint are undefined.
Returns
The number of Atoms found in the subWindow which represent Element_Empty .
template<class CC >
u32 MFM::WindowScanner< CC >::FindEmptyInVonNeumann ( SPoint outPoint) const

Searches the Von Neumann neighborhood around the center atom of the held EventWindow for an Atom representing Element_Empty , giving its location if found.

Parameters
outPointan output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one representing Element_Empty is located. If this method returns 0 , the contents of this SPoint are undefined.
Returns
The number of Atoms in the center Atom's Von Neumann neighborhood representing Element_Empty.
template<class CC >
void MFM::WindowScanner< CC >::FindRandomAtoms ( const u32  radius,
const u32  count,
  ... 
) const

Searches the held EventWindow under a specified radius for different types of Atoms, giving the number of Atoms found and the location of a randomly chosen one for each being searched for.

Parameters
radiusThe radius of the search over the held EventWindow in manhattan distance. The center Atom is never included in this search.
countThe number of Atom - Type pairs being searched for.
...A variadic number of triplets specifying this particular search. Each triplet consists of three parts:
  • SPoint* Output parameter, the location of a randomly chosen Atom of its paired type if one is found.
  • u32 The Type of the Atom to search for.
  • u32* Output parameter, the number of Atoms of the paired type encountered during the search.
template<class CC >
void MFM::WindowScanner< CC >::FindRandomAtoms ( const u32  count,
  ... 
) const

Searches the held EventWindow for different types of Atoms, giving the number of Atoms found and the location of a randomly chosen one for each being searched for.

Parameters
countThe number of Atom - Type pairs being searched for.
...A variadic number of triplets specifying this particular search. Each triplet consists of three parts:
  • SPoint* Output parameter, the location of a randomly chosen Atom of its paired type if one is found.
  • u32 The Type of the Atom to search for.
  • u32* Output parameter, the number of Atoms of the paired type encountered during the search.
template<class CC >
u32 MFM::WindowScanner< CC >::FindRandomInMoore ( const u32  type,
SPoint outPoint 
) const

Searches the Moore neighborhood around the center atom of the held EventWindow for an Atom of a specified type, giving its location if found.

Parameters
typeThe type of the Atom to search for.
outPointan output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one of type type is located. If this method returns 0 , the contents of this SPoint are undefined.
Returns
The number of Atoms in the center Atom's Moore neighborhood of type type.
template<class CC >
u32 MFM::WindowScanner< CC >::FindRandomInNeighborhood ( const u32  type,
const Dir *  dirs,
const u32  dirCount,
SPoint outPoint 
) const

Searches a specified neighborhood around the center atom of the held EventWindow for an Atom of a specified type, giving its location if found.

Parameters
typeThe type of the Atom to search for.
dirsAn array of Dirs specifying the neighborhood to search around the center Atom.
dirCountThe number of Dir elements inside of dirs .
outPointan output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one of type type is located. If this method returns false , the contents of this SPoint are undefined.
Returns
The number of Atoms in the center Atom's specified neighborhood of type type.
template<class CC >
u32 MFM::WindowScanner< CC >::FindRandomInSubWindow ( const u32  type,
const SPoint subWindow,
const u32  subCount,
SPoint outPoint 
) const

Scans a subset of the held EventWindow, specified by a given set of relative Points, for an Atom of a particular type, placing the location of a randomly chosen Atom in an output Point.

Parameters
typeThe type of the Atom to search for in this subset.
subWindowThe array of relative Points to search through.
subCountThe length of the subWindow array.
outPointAn output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one of the correct type is located. If this method returns 0 , the contents of this SPoint are undefined.
Returns
The number of Atoms found in the subWindow of type type .
template<class CC >
u32 MFM::WindowScanner< CC >::FindRandomInVonNeumann ( const u32  type,
SPoint outPoint 
) const

Searches the Von Neumann neighborhood around the center atom of the held EventWindow for an Atom of a specified type, giving its location if found.

Parameters
typeThe type of the Atom to search for.
outPointan output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one of type type is located. If this method returns 0 , the contents of this SPoint are undefined.
Returns
The number of Atoms in the center Atom's Von Neumann neighborhood of type type.
template<class CC >
u32 MFM::WindowScanner< CC >::FindRandomLocationOfType ( const u32  type,
SPoint outPoint 
) const

Scans the held EventWindow (discluding the center atom) for all atoms of a specified type, filling a point with the location of a single randomly chosen one.

Parameters
typeThe type of the atoms to search for and potentially randomly pick.
outPointAn output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one of the correct type is located. If this method returns 0 , the contents of this SPoint are undefined.
Returns
The number of Atoms found in the held EventWindow of type type .
template<class CC >
u32 MFM::WindowScanner< CC >::FindRandomLocationOfType ( const u32  type,
const u32  radius,
SPoint outPoint 
) const

Scans a subset of the held EventWindow, up to a specified radius, discluding the center Atom, for all Atoms of a specified type, filling a given point with the location of a single randomly chosen Atom of the specified type.

Parameters
typeThe type of the atoms to search for and potentially randomly pick.
radiusThe maximum radius to search for atoms at. This must be greater than 0 and less than the radius of the held EventWindow, or this will FAIL with ILLEGAL_ARGUMENT .
outPointAn output parameter; The SPoint to fill with the coordinates of a randomly chosen atom if one of the correct type is located. If this method returns 0 , the contents of this SPoint are undefined.
Returns
The number of Atoms found in the search radius of type type .
template<class CC >
bool MFM::WindowScanner< CC >::IsBorderingMoore ( const u32  type) const

Scans the moore neighborhood (N, NE, E, SE, S, SW, W, NW) directly surrounding the center atom for an Atom of a specified type.

Parameters
typeThe type of the Atom to search for.
Returns
true if an Atom of type type is within the moore neighborhood of the center Atom of the held EventWindow, else false .
template<class CC >
bool MFM::WindowScanner< CC >::IsBorderingNeighborhood ( const u32  type,
const Dir *  neighborhood,
const u32  dirCount 
) const

Scans a specified neighborhood consisting of Dirs directly surrounding the center atom for an Atom of a specified type.

Parameters
typeThe type of the Atom to search for.
neighborhoodAn array of Dirs representing the neighborhood around the central Atom.
dirCountThe number of elements inside the neighborhood array.
Returns
true if an Atom of type type is within the specified neighborhood of the center Atom of this EventWindow, else false .
Remarks
This is similar to CountInNeighborhood() > 0 except that it returns more quickly if an Atom is found.
template<class CC >
bool MFM::WindowScanner< CC >::IsBorderingVonNeumann ( const u32  type) const

Scans the Von Neumann neighborhood (N, E, S, W) directly surrounding the center atom for an Atom of a specified type.

Parameters
typeThe type of the Atom to search for.
Returns
true if an Atom of type type is within the Von Neumann neighborhood of the center Atom of the held EventWindow, else false .

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