-
Notifications
You must be signed in to change notification settings - Fork 0
/
Position.cpp
48 lines (41 loc) · 886 Bytes
/
Position.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Position.h"
#include <iostream>
Position::Position()
{
}
// initialises position based on arguments
// also checks that the position is valid
// terminates program if invalid position is set
Position::Position(int x, int y)
: row_(x),
col_(y)
{
if (IsValid() == false)
{
std::cout << "Invalid position set" << std::endl;
exit(0);
}
}
// returns true if position is in valid range [0,2]
// returns false otherwise
bool Position::IsValid() const
{
// check valid row
if (row_ > 2 || row_ < 0)
{
return false;
}
// check valid col
if (col_ > 2 || col_ < 0)
{
return false;
}
return true;
}
// returns true if rows and cols are equal
// returns false otherwise
bool Position::operator==(const Position& rhs) const
{
return (this -> row_ == rhs.row_ &&
this -> col_ == rhs.col_);
}