Esempio n. 1
0
void Maze::ShowCellState(const Position &p, const CellState dist) const
{
   const char CurPosChar = '+';     // Current position display character
   const unsigned curPosX = 35;              // X location to display current position
   const unsigned curPosY = 2;               // Y location to display current position
   const char PathMarkChar = 'P';   // Mark the path if found.

   // Display the numeric current position (x, y).
   gotoxy( curPosX, curPosY);
   cout << "Position: (" << p.Col() << ", " << p.Row() << ")";

   // Display the new distance.
   gotoxy(CellWidth*p.Col() + ColOffset, CellHeight*p.Row() + RowOffset);

   // Wait and then change and display the new cell mark character.
   Delay(MsPerSec/speed);

   cout.width(CellWidth-1);
   if (dist == PathCell)
      // If cell is on the shortest path, display the PathMarkChar.
      cout << PathMarkChar;
   else
      // Otherwise, display the cell's distance from the start.
      cout << dist;
}
Esempio n. 2
0
CellState Maze::State(const Position &cellPos) const
{
   // If the position is off the grid, it is illegal.
   if (cellPos.Row() < 0 || cellPos.Row() >= GridSize)
      return Obstacle;
   if (cellPos.Col() < 0 || cellPos.Col() >= GridSize)
      return Obstacle;

   // Start and goal are considered open.
   if (  cell[cellPos.Row()][cellPos.Col()] == StartCell ||
         cell[cellPos.Row()][cellPos.Col()] == GoalCell)
      return Open;

   // Use the stored cell distance.
   return cell[cellPos.Row()][cellPos.Col()];
}
Esempio n. 3
0
void Maze::Mark(const Position &p, const CellState newState)
{
   logFile << "Mark (" << p.Row() << ", " << p.Col() << ") = " << newState << endl;

   // Mark the cell with its new distance.
   cell[p.Row()][p.Col()] = newState;
#if NoGraphics
   // Wait and then change and display the new cell mark character.
   Delay(MsPerSec/speed);

   cout << endl;
   
   Show();
#else
   ShowCellState(p, newState);
#endif   
}
Esempio n. 4
0
bool Maze::IsOpen(const Position &cellPos) const
{
   // If the position is off the grid, it is illegal.
   if (cellPos.Row() < 0 || cellPos.Row() >= GridSize)
      return false;
   if (cellPos.Col() < 0 || cellPos.Col() >= GridSize)
      return false;

   // The start and goal cells are open until visited.
   if (cell[cellPos.Row()][cellPos.Col()] == StartCell)	// 10-16-2003 - gpc
      return true;
   if (cell[cellPos.Row()][cellPos.Col()] == GoalCell)	// 10-16-2003 - gpc
      return true;

   // Use the stored cell state.
   return cell[cellPos.Row()][cellPos.Col()] == Open;
}
Esempio n. 5
0
void Maze::ShowCell(const Position &p, const CellState state) const
{
   const unsigned MsPerSec = 1000;        // Number of ms. in one second
   const char CurPosChar = '+';  // Current position display character
   const unsigned curPosX = 15;           // X location to display current position
   const unsigned curPosY = 2;            // Y location to display current position

   // Display the numeric current position (x, y).
   gotoxy( curPosX, curPosY);
   cout << "Position: (" << p.Col() << ", " << p.Row() << ")";

   // Display the new state.
   gotoxy(p.Col()+1, p.Row()+1);

   // Wait and then change and display the new state character.
//   Delay(MsPerSec/speed);

   cout << state;
}
Esempio n. 6
0
void Maze::MarkPathCell(const Position &p)
{
   cell[p.Row()][p.Col()] = PathCell;

#if NoGraphics
   Show();
#else
   ShowCell(p, PathCell);
#endif
   // Wait and then change and display the new state character.
   Delay(MsPerSec/speed);
}