Skip to content

Commit

Permalink
add include cpp14
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPJT committed Jan 17, 2019
1 parent 021f237 commit 5a265e3
Show file tree
Hide file tree
Showing 4 changed files with 641 additions and 20 deletions.
97 changes: 97 additions & 0 deletions include/cpp14/BoardGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,103 @@ namespace dtl {
return false;
}

enum :std::size_t {
chess_empty,
chess_king1,
chess_king2,
chess_queen1,
chess_queen2,
chess_rook1,
chess_rook2,
chess_bishop1,
chess_bishop2,
chess_knight1,
chess_knight2,
chess_pawn1,
chess_pawn2,
chess_next_place1,
chess_next_place2
};

template<typename STL_>
constexpr void createChess(STL_& stl_) noexcept {
if (stl_.size() < 2) return;

for (std::size_t i{}; i < stl_[1].size(); ++i)
stl_[1][i] = chess_pawn2;
for (std::size_t i{}; i < stl_[stl_.size() - 2].size(); ++i)
stl_[stl_.size() - 2][i] = chess_pawn1;

if (stl_[0].size() < 4) return;
stl_[0][0] = chess_rook2;
stl_[0][stl_[0].size() - 1] = chess_rook2;
stl_[0][1] = chess_knight2;
stl_[0][stl_[0].size() - 2] = chess_knight2;
stl_[0][2] = chess_bishop2;
stl_[0][stl_[0].size() - 3] = chess_bishop2;
stl_[0][3] = chess_queen2;
stl_[0][stl_[0].size() - 4] = chess_king2;
if (stl_[stl_.size() - 1].size() < 4) return;
stl_[stl_.size() - 1][0] = chess_rook1;
stl_[stl_.size() - 1][stl_[stl_.size() - 1].size() - 1] = chess_rook1;
stl_[stl_.size() - 1][1] = chess_knight1;
stl_[stl_.size() - 1][stl_[stl_.size() - 1].size() - 2] = chess_knight1;
stl_[stl_.size() - 1][2] = chess_bishop1;
stl_[stl_.size() - 1][stl_[stl_.size() - 1].size() - 3] = chess_bishop1;
stl_[stl_.size() - 1][3] = chess_queen1;
stl_[stl_.size() - 1][stl_[stl_.size() - 1].size() - 4] = chess_king1;
}
template<typename STL_>
constexpr void createChess(STL_& stl_, const std::size_t x_, const std::size_t y_) noexcept {
if (y_ < 2) return;

for (std::size_t i{}; i < x_; ++i)
stl_[1][i] = chess_pawn2;
for (std::size_t i{}; i < x_; ++i)
stl_[y_ - 2][i] = chess_pawn1;

if (x_ < 4) return;
stl_[0][0] = chess_rook2;
stl_[0][x_ - 1] = chess_rook2;
stl_[0][1] = chess_knight2;
stl_[0][x_ - 2] = chess_knight2;
stl_[0][2] = chess_bishop2;
stl_[0][x_ - 3] = chess_bishop2;
stl_[0][3] = chess_queen2;
stl_[0][x_ - 4] = chess_king2;
stl_[y_ - 1][0] = chess_rook1;
stl_[y_ - 1][x_ - 1] = chess_rook1;
stl_[y_ - 1][1] = chess_knight1;
stl_[y_ - 1][x_ - 2] = chess_knight1;
stl_[y_ - 1][2] = chess_bishop1;
stl_[y_ - 1][x_ - 3] = chess_bishop1;
stl_[y_ - 1][3] = chess_queen1;
stl_[y_ - 1][x_ - 4] = chess_king1;
}

template<typename Int_>
class Chess {
public:
//コンストラクタ
constexpr Chess() noexcept = default;
template<typename STL_>
constexpr explicit Chess(STL_& stl_) noexcept {
create(stl_);
}
template<typename STL_>
constexpr void create(STL_& stl_) noexcept {
createChess(stl_);
}
template<typename STL_>
constexpr explicit Chess(STL_& stl_, const std::size_t x_, const std::size_t y_) noexcept {
create(stl_, x_, y_);
}
template<typename STL_>
constexpr void create(STL_& stl_, const std::size_t x_, const std::size_t y_) noexcept {
createChess(stl_, x_, y_);
}
};

}

#endif //Included Dungeon Template Library
8 changes: 6 additions & 2 deletions include/cpp14/DungeonFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <fstream>
#include <string>
#include <sstream>
#include <typeinfo>

//Dungeon Template Library Namespace
namespace dtl {
Expand Down Expand Up @@ -79,12 +80,15 @@ namespace dtl {
bool fileWrite_CSV(const STL_& stl_, const std::string& str_) noexcept {
std::ofstream ofs(str_);
if (ofs.fail()) return false;
const bool is_char{ (typeid(Int_) == typeid(unsigned char) || typeid(Int_) == typeid(signed char)) };
for (std::size_t i{}; i < stl_.size(); ++i) {
if (stl_[i].size() == 0) continue;
ofs << stl_[i][0];
if(is_char) ofs << static_cast<int>(stl_[i][0]);
else ofs << stl_[i][0];;
for (std::size_t j{ 1 }; j < stl_[i].size(); ++j) {
ofs << ',';
ofs << stl_[i][j];
if (is_char) ofs << static_cast<int>(stl_[i][j]);
else ofs << stl_[i][j];
}
ofs << std::endl;
}
Expand Down
56 changes: 56 additions & 0 deletions include/cpp14/DungeonOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ namespace dtl {
}
}
template<typename STL_>
constexpr void dungeonNumberOutput(const STL_& stl_, const std::size_t x_, const std::size_t y_) noexcept {
for (std::size_t i{}; i < y_; ++i) {
for (std::size_t j{}; j < x_; ++j)
std::cout << stl_[i][j];
std::cout << std::endl;
}
}
template<typename STL_>
constexpr void dungeonNumberOutput_Array(const STL_& stl_, const std::size_t x_, const std::size_t y_) noexcept {
for (std::size_t i{}; i < y_; ++i) {
for (std::size_t j{}; j < x_; ++j)
std::cout << stl_[i * x_ + j];
std::cout << std::endl;
}
}
template<typename STL_>
constexpr void dungeonNumberOutput_RangeBasedFor(const STL_& stl_) noexcept {
for (const auto& i : stl_) {
for (const auto& j : i)
Expand All @@ -41,6 +57,24 @@ namespace dtl {
}
}
template<typename STL_>
constexpr void dungeonNumberOutput(const STL_& stl_, const std::size_t x_, const std::size_t y_, const char* const string_) noexcept {
if (string_ == nullptr) return;
for (std::size_t i{}; i < y_; ++i) {
for (std::size_t j{}; j < x_; ++j)
std::cout << stl_[i][j] << string_;
std::cout << std::endl;
}
}
template<typename STL_>
constexpr void dungeonNumberOutput_Array(const STL_& stl_, const std::size_t x_, const std::size_t y_, const char* const string_) noexcept {
if (string_ == nullptr) return;
for (std::size_t i{}; i < y_; ++i) {
for (std::size_t j{}; j < x_; ++j)
std::cout << stl_[i * x_ + j] << string_;
std::cout << std::endl;
}
}
template<typename STL_>
constexpr void dungeonNumberOutput_RangeBasedFor(const STL_& stl_, const char* const string_) noexcept {
if (string_ == nullptr) return;
for (const auto& i : stl_) {
Expand All @@ -62,6 +96,28 @@ namespace dtl {
}
}
template<typename STL_>
constexpr void dungeonStringOutputBool(const STL_& stl_, const std::size_t x_, const std::size_t y_, const char* const true_, const char* const false_) noexcept {
if (true_ == nullptr || false_ == nullptr) return;
for (std::size_t i{}; i < y_; ++i) {
for (std::size_t j{}; j < x_; ++j) {
if (stl_[i][j]) std::cout << true_;
else std::cout << false_;
}
std::cout << std::endl;
}
}
template<typename STL_>
constexpr void dungeonStringOutputBool_Array(const STL_& stl_, const std::size_t x_, const std::size_t y_, const char* const true_, const char* const false_) noexcept {
if (true_ == nullptr || false_ == nullptr) return;
for (std::size_t i{}; i < y_; ++i) {
for (std::size_t j{}; j < x_; ++j) {
if (stl_[i * x_ + j]) std::cout << true_;
else std::cout << false_;
}
std::cout << std::endl;
}
}
template<typename STL_>
constexpr void dungeonStringOutputBool_RangeBasedFor(const STL_& stl_, const char* const true_, const char* const false_) noexcept {
if (true_ == nullptr || false_ == nullptr) return;
for (const auto& i : stl_) {
Expand Down
Loading

0 comments on commit 5a265e3

Please sign in to comment.