DigitalCurling3  1.0.0
A curling simulation system for curling AIs
game_state.hpp
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2022 UEC Takeshi Ito Laboratory
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
25 
26 #ifndef DIGITALCURLING3_GAME_STATE_HPP
27 #define DIGITALCURLING3_GAME_STATE_HPP
28 
29 #include <cstdint>
30 #include <array>
31 #include <optional>
32 #include <vector>
33 #include <chrono>
34 #include "json/common.hpp"
35 #include "vector2.hpp"
36 #include "transform.hpp"
37 #include "constants.hpp"
38 #include "game_result.hpp"
39 #include "game_setting.hpp"
40 #include "i_simulator.hpp"
41 
42 namespace digitalcurling3 {
43 
44 
45 
46 
53 struct GameState {
54 
56  static constexpr std::uint8_t kExtraEndMax = 255;
57 
59  static constexpr size_t kShotPerEnd = 16;
60 
63  using Stones = std::array<
64  std::array<std::optional<Transform>, kShotPerEnd / 2>,
65  2>;
66 
74  GameState();
75 
79  GameState(GameSetting const& setting);
80 
82  GameState(GameState const&) = default;
83 
87  GameState(GameState &&) = default;
88 
90  GameState& operator = (GameState const&) = default;
91 
95  GameState& operator = (GameState &&) = default;
96 
100  std::uint8_t end;
101 
103  std::uint8_t shot;
104 
109 
122 
134  std::array<
135  std::vector<std::optional<std::uint8_t>>,
136  2> scores;
137 
149  std::array<std::optional<std::uint8_t>, 2> extra_end_score;
150 
154  std::array<std::chrono::milliseconds, 2> thinking_time_remaining;
155 
159  std::optional<GameResult> game_result;
160 
166  std::uint32_t GetTotalScore(Team team) const;
167 
173  Team GetNextTeam() const;
174 
178  bool IsGameOver() const
179  {
180  return game_result.has_value();
181  }
182 
187  static std::pair<Team, size_t> StonesIndexFromAllStonesIndex(size_t all_stones_index);
188 
194  static size_t StonesIndexToAllStonesIndex(Team team, size_t team_stone_index);
195 
201  static Stones StonesFromAllStones(ISimulator::AllStones const& all_stones, std::uint8_t end);
202 
208  static ISimulator::AllStones StonesToAllStones(Stones const& stones, std::uint8_t end);
209 };
210 
211 
213 // json
214 void to_json(nlohmann::json &, GameState const&);
215 void from_json(nlohmann::json const&, GameState &);
217 
218 } // namespace digitalcurling3
219 
220 #endif // DIGITALCURLING3_GAME_STATE_HPP
digitalcurling3::GameState::shot
std::uint8_t shot
現在のショット番号.0以上,15以下.
Definition: game_state.hpp:103
digitalcurling3::GameState::Stones
std::array< std::array< std::optional< Transform >, kShotPerEnd/2 >, 2 > Stones
各チームのストーンの位置と角度を格納します
Definition: game_state.hpp:65
digitalcurling3::Team
Team
チームを識別するために用いる列挙体です.
Definition: team.hpp:39
digitalcurling3::GameSetting
試合設定
Definition: game_setting.hpp:37
digitalcurling3::GameState::IsGameOver
bool IsGameOver() const
ゲームが終了しているかを調べる
Definition: game_state.hpp:178
digitalcurling3::GameState
試合の状態を表す
Definition: game_state.hpp:53
common.hpp
必要なJSON変換関数を定義します
digitalcurling3::GameState::StonesIndexToAllStonesIndex
static size_t StonesIndexToAllStonesIndex(Team team, size_t team_stone_index)
GameState::Stones のインデックスから ISimulator::AllStones のインデックスに変換する.
digitalcurling3::GameState::kShotPerEnd
static constexpr size_t kShotPerEnd
エンド毎のショット数
Definition: game_state.hpp:59
digitalcurling3::GameState::StonesFromAllStones
static Stones StonesFromAllStones(ISimulator::AllStones const &all_stones, std::uint8_t end)
ISimulator::AllStones から GameState::Stones へ変換する.
digitalcurling3::ISimulator::AllStones
std::array< std::optional< Stone >, kStoneMax > AllStones
全ストーンの位置と速度
Definition: i_simulator.hpp:97
digitalcurling3::GameState::GetNextTeam
Team GetNextTeam() const
次に行動するチームを得る.
digitalcurling3::GameState::end
std::uint8_t end
現在のエンド.
Definition: game_state.hpp:100
digitalcurling3::GameState::extra_end_score
std::array< std::optional< std::uint8_t >, 2 > extra_end_score
エクストラエンド(延長戦)のスコア.
Definition: game_state.hpp:149
constants.hpp
定数を定義します
digitalcurling3::GameState::GetTotalScore
std::uint32_t GetTotalScore(Team team) const
チームの現在までの合計スコアを得る
digitalcurling3::GameState::StonesIndexFromAllStonesIndex
static std::pair< Team, size_t > StonesIndexFromAllStonesIndex(size_t all_stones_index)
ISimulator::AllStones のインデックスから GameState::Stones のインデックスに変換する.
digitalcurling3
Digital Curling ライブラリはこの名前空間の中に定義されます
Definition: polymorphic_json.hpp:37
transform.hpp
Transform を定義します
digitalcurling3::GameState::game_result
std::optional< GameResult > game_result
試合結果
Definition: game_state.hpp:159
vector2.hpp
Vector2 を定義します
digitalcurling3::GameState::hammer
Team hammer
現在のエンドのハンマー(後攻).
Definition: game_state.hpp:108
digitalcurling3::GameState::kExtraEndMax
static constexpr std::uint8_t kExtraEndMax
延長戦を含めたエンド数の最大値 ( GameState::end >= kExtraEndMax のときは無効なエンドを表します)
Definition: game_state.hpp:56
digitalcurling3::GameState::operator=
GameState & operator=(GameState const &)=default
コピーする
digitalcurling3::GameState::thinking_time_remaining
std::array< std::chrono::milliseconds, 2 > thinking_time_remaining
各チームの残り思考時間
Definition: game_state.hpp:154
digitalcurling3::GameState::GameState
GameState()
デフォルトコンストラクタ.
i_simulator.hpp
ISimulator を定義します
digitalcurling3::GameState::stones
Stones stones
各チームのストーンの位置と角度
Definition: game_state.hpp:121
game_setting.hpp
GameSetting を定義します
game_result.hpp
Result を定義します
digitalcurling3::GameState::scores
std::array< std::vector< std::optional< std::uint8_t > >, 2 > scores
各エンドのスコアを格納する
Definition: game_state.hpp:136
digitalcurling3::GameState::StonesToAllStones
static ISimulator::AllStones StonesToAllStones(Stones const &stones, std::uint8_t end)
GameState::Stones から ISimulator::AllStones へ変換する.