#include #include "dir.h" bool isLegal( Dir d ) { return (d == NORTH) || (d == SOUTH) || (d == WEST) || (d == EAST); } Dir opposite( Dir d ) { assert( isLegal( d ) ); switch( d ) { case NORTH: return SOUTH; case SOUTH: return NORTH; case WEST: return EAST; case EAST: default: return WEST; } } Dir nextCW( Dir d ) { assert( isLegal( d ) ); switch( d ) { case NORTH: return EAST; case SOUTH: return WEST; case WEST: return NORTH; case EAST: default: return SOUTH; } } Dir nextCCW( Dir d ) { return nextCW( opposite( d ) ); } ostream& operator <<( ostream& os, const Dir& d ) { assert( isLegal( d ) ); switch( d ) { case NORTH: os << "NORTH"; break; case SOUTH: os << "SOUTH"; break; case WEST: os << "WEST"; break; case EAST: default: os << "EAST"; break; } return os; }