-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
#include "recursive_horsewalker.hpp" | ||
|
||
TEST_CASE_TEMPLATE("Никъде не можем да стигнем от невалидна стартова позиция", | ||
AnyHorseWalker, RecursiveHorseWalker) { | ||
AnyHorseWalker horseWalker(4); | ||
CHECK_FALSE(horseWalker.existsWalk({-1, 0}, {3, 3})); | ||
} | ||
|
||
TEST_CASE_TEMPLATE("Не можем да стигнем до невалидна крайна позиция", | ||
AnyHorseWalker, RecursiveHorseWalker) { | ||
AnyHorseWalker horseWalker(4); | ||
CHECK_FALSE(horseWalker.existsWalk({0, 0}, {3, 5})); | ||
} | ||
|
||
TEST_CASE_TEMPLATE("Началната и крайната позиция съвпадат", | ||
AnyHorseWalker, RecursiveHorseWalker) { | ||
AnyHorseWalker horseWalker(4); | ||
CHECK(horseWalker.existsWalk({0, 0}, {0, 0})); | ||
} | ||
|
||
TEST_CASE_TEMPLATE("На дъска 4x4 можем да стигнем от (0,0) до (3,3)", | ||
AnyHorseWalker, RecursiveHorseWalker) { | ||
AnyHorseWalker horseWalker(4); | ||
CHECK(horseWalker.existsWalk({0, 0}, {3, 3})); | ||
} | ||
|
||
TEST_CASE_TEMPLATE("На дъска 4x4 можем да стигнем от (0,0) до (2,2)", | ||
AnyHorseWalker, RecursiveHorseWalker) { | ||
AnyHorseWalker horseWalker(4); | ||
CHECK(horseWalker.existsWalk({0, 0}, {2, 2})); | ||
} | ||
|
||
TEST_CASE_TEMPLATE("На дъска 4x4 можем да стигнем от (0,0) до (0,1)", | ||
AnyHorseWalker, RecursiveHorseWalker) { | ||
AnyHorseWalker horseWalker(4); | ||
CHECK(horseWalker.existsWalk({0, 0}, {0, 1})); | ||
} | ||
|
||
TEST_CASE_TEMPLATE("На дъска 3x3 не можем да стигнем от (0,0) до (1,1)", | ||
AnyHorseWalker, RecursiveHorseWalker) { | ||
AnyHorseWalker horseWalker(3); | ||
CHECK_FALSE(horseWalker.existsWalk({0, 0}, {1, 1})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "horsewalker.hpp" | ||
|
||
HorseWalker::HorseWalker(size_t size) { | ||
initBoard(size); | ||
} | ||
|
||
void HorseWalker::initBoard(size_t size) { | ||
for(size_t i = 0; i < size; i++) | ||
board.push_back(ChessRow(size)); | ||
} | ||
|
||
bool HorseWalker::insideBoard(Position const& pos) const { | ||
return pos.first >= 0 && pos.first < board.size() && | ||
pos.second >= 0 && pos.second < board.size(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
#include <cmath> | ||
#include "recursive_horsewalker.hpp" | ||
|
||
RecursiveHorseWalker::RecursiveHorseWalker(size_t size) {} | ||
RecursiveHorseWalker::RecursiveHorseWalker(size_t size) : HorseWalker(size) {} | ||
|
||
bool RecursiveHorseWalker::existsWalk(Position const& start, Position const& end) { | ||
if (!insideBoard(start) || !insideBoard(end) || board[start.first][start.second]) | ||
return false; | ||
|
||
if (start == end) | ||
return true; | ||
|
||
board[start.first][start.second] = true; | ||
|
||
for(int dx = -2; dx <= 2; dx++) | ||
if (dx != 0) | ||
for (int sign : {-1, 1}) { | ||
int dy = sign * (3 - std::abs(dx)); | ||
if (existsWalk({start.first + dx, start.second + dy}, end)) | ||
return true; | ||
} | ||
|
||
bool RecursiveHorseWalker::existsWalk(Position const& start, Position const& end) const { | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters