Skip to content

Commit

Permalink
Merging Client changes with Coordinate.h
Browse files Browse the repository at this point in the history
  • Loading branch information
dmj12004 committed Apr 27, 2017
1 parent 5b1fe28 commit 9ec6851
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
20 changes: 20 additions & 0 deletions include/Coordinate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef COORDINATE_H
#define COORDINATE_H

#include <string>

class Coordinate
{
private:
int m_x;
int m_y;

public:
Coordinate(int x, int y) : m_x(x), m_y(y) {};
int getX() const { return m_x; }
int getY() const { return m_y; }

std::string toString() const;
};

#endif
12 changes: 7 additions & 5 deletions include/Move.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
#include <vector>
#include <cstdint>
#include <iostream>
#include <map>
#include "Coordinate.h"

class Move
{
private:
std::vector<int> moves;

static const std::vector<Coordinate> coordinateMap;

public:

Move();
Expand All @@ -21,11 +25,9 @@ class Move
int length();
std::vector<int> getMoves() { return moves; }

void printMoves() {
for (int m : moves) {
std::cout << m << "->" << std::endl;
}
}
void printMoves() const;

std::string toString() const;
};

#endif
7 changes: 7 additions & 0 deletions src/Coordinate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <string>
#include "Coordinate.h"

std::string Coordinate::toString() const
{
return "(" + std::to_string(getX()) + ":" + std::to_string(getY()) + ")";
}
36 changes: 36 additions & 0 deletions src/Move.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
#include <iostream>
#include "Move.h"

const std::vector<Coordinate> Move::coordinateMap = {
Coordinate(0, 6), Coordinate(1, 7), Coordinate(4, 0),
Coordinate(5, 1), Coordinate(6, 2), Coordinate(7, 3),
Coordinate(0, 4), Coordinate(1, 5), Coordinate(2, 6),
Coordinate(3, 7), Coordinate(6, 0), Coordinate(7, 1),
Coordinate(0, 2), Coordinate(1, 3), Coordinate(2, 4),
Coordinate(3, 5), Coordinate(4, 6), Coordinate(5, 7),
Coordinate(0, 0), Coordinate(1, 1), Coordinate(2, 2),
Coordinate(3, 3), Coordinate(4, 4), Coordinate(5, 5),
Coordinate(6, 6), Coordinate(7, 7), Coordinate(2, 0),
Coordinate(3, 1), Coordinate(4, 2), Coordinate(5, 3),
Coordinate(6, 4), Coordinate(7, 5)
};

Move::Move() : moves() {};

Move::Move(int start)
Expand Down Expand Up @@ -32,3 +46,25 @@ int Move::length()
{
return moves.size();
}

void Move::printMoves() const
{
int movesLength = moves.size();
for (int i = 0; i < movesLength; ++i) {
std::cout << coordinateMap[moves[i]].toString();
if (i != movesLength - 1) std::cout << ":";
}
std::cout << std::endl;
}

std::string Move::toString() const
{
std::string result;
int movesLength = moves.size();
for (int i = 0; i < movesLength; ++i) {
result += coordinateMap[moves[i]].toString();
if (i != movesLength - 1) result+= ":";
}

return result;
}

0 comments on commit 9ec6851

Please sign in to comment.