-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathShogi.hpp
More file actions
166 lines (147 loc) · 8.55 KB
/
Shogi.hpp
File metadata and controls
166 lines (147 loc) · 8.55 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*#######################################################################################
Copyright (c) 2017-2019 Kasugaccho
Copyright (c) 2018-2019 As Project
https://github.com/Kasugaccho/DungeonTemplateLibrary
wanotaitei@gmail.com
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#######################################################################################*/
#ifndef INCLUDED_DUNGEON_TEMPLATE_LIBRARY_DTL_SHAPE_SHOGI_HPP
#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_DTL_SHAPE_SHOGI_HPP
/*#######################################################################################
日本語リファレンス (Reference-JP)
https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::Shogi-(形状クラス)/
#######################################################################################*/
#include <DTL/Base/Struct.hpp>
#include <DTL/Macros/constexpr.hpp>
#include <DTL/Macros/nodiscard.hpp>
#include <DTL/Type/Forward.hpp>
#include <DTL/Type/SizeT.hpp>
#include <DTL/Range/RectBaseShogi.hpp>
#include <DTL/Utility/DrawJagged.hpp>
/*#######################################################################################
[概要] "dtl名前空間"とは"DungeonTemplateLibrary"の全ての機能が含まれる名前空間である。
[Summary] The "dtl" is a namespace that contains all the functions of "DungeonTemplateLibrary".
#######################################################################################*/
namespace dtl {
inline namespace shape { //"dtl::shape"名前空間に属する
/*#######################################################################################
[概要] Shogiとは "Matrixの描画範囲に将棋の駒を初期位置に設置する" 機能を持つクラスである。
[Summary] Shogi is a class that generates Shogi, a Japanese game, in the drawing range of Matrix.
#######################################################################################*/
template<typename Matrix_Var_>
class Shogi : public ::dtl::range::RectBaseShogi<Shogi<Matrix_Var_>, Matrix_Var_>,
public ::dtl::utility::DrawJagged<Shogi<Matrix_Var_>, Matrix_Var_> {
private:
///// エイリアス (Alias) /////
using Index_Size = ::dtl::type::size;
using ShapeBase_t = ::dtl::range::RectBaseShogi<Shogi, Matrix_Var_>;
using DrawBase_t = ::dtl::utility::DrawJagged<Shogi, Matrix_Var_>;
friend DrawBase_t;
///// 基本処理 /////
//STL
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
typename DTL_TYPE_ENABLE_IF<Matrix_::is_jagged::value, bool>::DTL_TYPE_EITYPE
drawNormal(Matrix_&& matrix_, Args_&& ... args_) const noexcept {
const Index_Size end_y_ { this->calcEndY(matrix_.getY())};
if (end_y_ <= this->start_y + 2) return true;
const Index_Size end_x_ { this->calcEndX(matrix_.getX(this->start_y))};
if (end_x_ <= this->start_x + 3) return true;
const Index_Size end_x2_ { this->calcEndX(matrix_.getX(end_y_ - 1))};
if (end_x2_ <= this->start_x + 3) return true;
//桂馬
matrix_.set(this->start_x + 1, this->start_y, this->shogiList.keima_1, args_...);
matrix_.set(end_x_ - 2, this->start_y, this->shogiList.keima_1, args_...);
matrix_.set(this->start_x + 1, end_y_ - 1, this->shogiList.keima_2, args_...);
matrix_.set(end_x2_ - 2, end_y_ - 1, this->shogiList.keima_2, args_...);
//香車
matrix_.set(this->start_x, this->start_y, this->shogiList.kyosha_1, args_...);
matrix_.set(end_x_ - 1, this->start_y, this->shogiList.kyosha_1, args_...);
matrix_.set(this->start_x, end_y_ - 1, this->shogiList.kyosha_2, args_...);
matrix_.set(end_x2_ - 1, end_y_ - 1, this->shogiList.kyosha_2, args_...);
//銀将
matrix_.set(this->start_x + 2, this->start_y, this->shogiList.ginsho_1, args_...);
matrix_.set(end_x_ - 3, this->start_y, this->shogiList.ginsho_1, args_...);
matrix_.set(this->start_x + 2, end_y_ - 1, this->shogiList.ginsho_2, args_...);
matrix_.set(end_x2_ - 3, end_y_ - 1, this->shogiList.ginsho_2, args_...);
//金将
matrix_.set(this->start_x + 3, this->start_y, this->shogiList.kinsho_1, args_...);
matrix_.set(end_x_ - 4, this->start_y, this->shogiList.kinsho_1, args_...);
matrix_.set(this->start_x + 3, end_y_ - 1, this->shogiList.kinsho_2, args_...);
matrix_.set(end_x2_ - 4, end_y_ - 1, this->shogiList.kinsho_2, args_...);
//王将・玉将
matrix_.set(this->start_x + (end_x_ - this->start_x) / 2, this->start_y, this->shogiList.osho, args_...);
matrix_.set(this->start_x + (end_x_ - this->start_x) / 2, end_y_ - 1, this->shogiList.gyokusho, args_...);
//飛車・角行
const Index_Size end_2x_ = this->calcEndX(matrix_.getX(this->start_y + 1));
if (end_2x_ <= this->start_x + 3) return true;
const Index_Size end_2x2_ = this->calcEndX(matrix_.getX(end_y_ - 2));
if (end_2x2_ <= this->start_x + 3) return true;
matrix_.set(this->start_x + 1, this->start_y + 1, this->shogiList.hisha_1, args_...);
matrix_.set(end_2x_ - 2, this->start_y + 1, this->shogiList.kakugyo_1, args_...);
matrix_.set(this->start_x + 1, end_y_ - 2, this->shogiList.kakugyo_2, args_...);
matrix_.set(end_2x2_ - 2, end_y_ - 2, this->shogiList.hisha_2, args_...);
//歩兵
const Index_Size end_3x_ = this->calcEndX(matrix_.getX(this->start_y + 2));
if (end_3x_ <= this->start_x + 3) return true;
for (Index_Size col{ this->start_x }; col < end_3x_; ++col) {
matrix_.set(col, this->start_y + 2, this->shogiList.fuhyo_1, args_...);
}
const Index_Size end_3x2_ = this->calcEndX(matrix_.getX(end_y_ - 3));
if (end_3x2_ <= this->start_x + 3) return true;
for (Index_Size col{ this->start_x }; col < end_3x2_; ++col) {
matrix_.set(col, end_y_ - 3, this->shogiList.fuhyo_2, args_...);
}
return true;
}
//Normal
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
typename DTL_TYPE_ENABLE_IF<!Matrix_::is_jagged::value, bool>::DTL_TYPE_EITYPE
drawNormal(Matrix_ && matrix_, Args_ && ... args_) const noexcept {
const Index_Size end_x_ { this->calcEndX(matrix_.getX())};
const Index_Size end_y_ { this->calcEndY(matrix_.getY())};
if (end_x_ <= this->start_x + 3 || end_y_ <= this->start_y + 2) return true;
//桂馬
matrix_.set(this->start_x + 1, this->start_y, this->shogiList.keima_1, args_...);
matrix_.set(end_x_ - 2, this->start_y, this->shogiList.keima_1, args_...);
matrix_.set(this->start_x + 1, end_y_ - 1, this->shogiList.keima_2, args_...);
matrix_.set(end_x_ - 2, end_y_ - 1, this->shogiList.keima_2, args_...);
//香車
matrix_.set(this->start_x, this->start_y, this->shogiList.kyosha_1, args_...);
matrix_.set(end_x_ - 1, this->start_y, this->shogiList.kyosha_1, args_...);
matrix_.set(this->start_x, end_y_ - 1, this->shogiList.kyosha_2, args_...);
matrix_.set(end_x_ - 1, end_y_ - 1, this->shogiList.kyosha_2, args_...);
//銀将
matrix_.set(this->start_x + 2, this->start_y, this->shogiList.ginsho_1, args_...);
matrix_.set(end_x_ - 3, this->start_y, this->shogiList.ginsho_1, args_...);
matrix_.set(this->start_x + 2, end_y_ - 1, this->shogiList.ginsho_2, args_...);
matrix_.set(end_x_ - 3, end_y_ - 1, this->shogiList.ginsho_2, args_...);
//金将
matrix_.set(this->start_x + 3, this->start_y, this->shogiList.kinsho_1, args_...);
matrix_.set(end_x_ - 4, this->start_y, this->shogiList.kinsho_1, args_...);
matrix_.set(this->start_x + 3, end_y_ - 1, this->shogiList.kinsho_2, args_...);
matrix_.set(end_x_ - 4, end_y_ - 1, this->shogiList.kinsho_2, args_...);
//王将・玉将
matrix_.set(this->start_x + (end_x_ - this->start_x) / 2, this->start_y, this->shogiList.osho, args_...);
matrix_.set(this->start_x + (end_x_ - this->start_x) / 2, end_y_ - 1, this->shogiList.gyokusho, args_...);
//飛車・角行
matrix_.set(this->start_x + 1, this->start_y + 1, this->shogiList.hisha_1, args_...);
matrix_.set(end_x_ - 2, this->start_y + 1, this->shogiList.kakugyo_1, args_...);
matrix_.set(this->start_x + 1, end_y_ - 2, this->shogiList.kakugyo_2, args_...);
matrix_.set(end_x_ - 2, end_y_ - 2, this->shogiList.hisha_2, args_...);
//歩兵
for (Index_Size col{ this->start_x }; col < end_x_; ++col) {
matrix_.set(col, this->start_y + 2, this->shogiList.fuhyo_1, args_...);
matrix_.set(col, end_y_ - 3, this->shogiList.fuhyo_2, args_...);
}
return true;
}
public:
///// コンストラクタ (Constructor) /////
using ShapeBase_t::ShapeBase_t;
};
}
}
#endif //Included Dungeon Template Library