1  interface Action {
   2      void performN(int x, int y);
   3      void performS(int x, int y);
   4      void performE(int x, int y);
   5      void performW(int x, int y);
   6  }
   7  
   8  class BoundsAction : Action {
   9      public BoundsAction() {
  10          minPosition_ = new Position(0, 0, null);
  11          maxPosition_ = new Position(0, 0, null);
  12          }
  13  
  14      public void performN(int x, int y) {if (y > maxPosition_.y_) maxPosition_.y_ = y;}
  15      public void performE(int x, int y) {if (x > maxPosition_.x_) maxPosition_.x_ = x;}
  16      public void performS(int x, int y) {if (y < minPosition_.y_) minPosition_.y_ = y;}
  17      public void performW(int x, int y) {if (x < minPosition_.x_) minPosition_.x_ = x;}
  18  
  19      public int numRows() {return maxPosition_.y_ - minPosition_.y_ + 1;}
  20      public int numCols() {return maxPosition_.x_ - minPosition_.x_ + 1;}
  21      public int minX()    {return minPosition_.x_;}
  22  
  23      // ======= Data Members ========
  24      // Final extents include beginning and end of path, 
  25      // both of which are outside the maze.
  26      // These must be subtracted out by the client.
  27      private Position minPosition_;
  28      private Position maxPosition_;
  29  }
  30  
  31  class OpenAction : Action {
  32      public OpenAction(Maze maze) {maze_ = maze;}
  33  
  34      public void performN(int x, int y) {maze_.horizontal_[x,   y]   = true;}
  35      public void performE(int x, int y) {maze_.vertical_  [x,   y]   = true;}
  36      public void performS(int x, int y) {maze_.horizontal_[x,   y+1] = true;}
  37      public void performW(int x, int y) {maze_.vertical_  [x+1, y]   = true;}
  38  
  39      // ======= Data Members ========
  40      private Maze maze_;
  41  }