/*
Programmer: Jennifer Leopold
Date: November 10, 2016
File: point.cpp
Purpose: This file contains the definitions of the functions
for the Point class.
*/
#include "point.h"
using namespace std;
Point& Point::operator =(const Point &p)
{
m_x = p.m_x;
m_y = p.m_y;
return(*this);
}
ostream& operator <<(ostream& outs, const Point& p)
{
outs << "(" << p.m_x << ", " << p.m_y << ")";
return outs;
}
Point Point::getRandomNeighbor() const
{
// Create a new point with same coordinates as
// this point
Point p(m_x, m_y);
// Offset new point by 1 in randomly chosen direction
switch(rand() % NUM_DIRECTIONS)
{
case UP : p.m_y--;
break;
case LEFT : p.m_x--;
break;
case RIGHT : p.m_x++;
break;
case DOWN : p.m_y++;
break;
}
return p;
}