-
Notifications
You must be signed in to change notification settings - Fork 0
/
hex.cc
52 lines (32 loc) · 1.29 KB
/
hex.cc
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
49
50
51
52
// Time-stamp: <2016-03-07 10:21:08 dmendyke>
//
// hex.cc:
//
// Required header files
//-----------------------------------------------------------------------------
#include <cmath> // std::abs
#include "hex.hh" // parsec::hex
// Namespace Short Hand
//-----------------------------------------------------------------------------
using namespace std; // standard library
using namespace parsec; // project NS
// Constructor
//-----------------------------------------------------------------------------
hex_t::hex_t( int q, int r ) : q_( q ), r_( r ) {
}; // end hex_t
// Destructor
//-----------------------------------------------------------------------------
hex_t::~hex_t( ) {
}; // end destructor
// Find the distance between this hex and another hex
//-----------------------------------------------------------------------------
int hex_t::distance( const hex_t& other ) const {
return hex_t::distance_between( *this, other );
}; // end distance
// Calculate the distance between hex A and hex B
//-----------------------------------------------------------------------------
int hex_t::distance_between( const hex_t& A, const hex_t& B ) {
return ( abs( A.q_ - B.q_ )
+ abs( A.q_ + A.r_ - B.q_ - B.r_ )
+ abs( A.r_ - B.r_ ) ) / 2;
}; // end distance