7並べ 〜その3〜 トランプのデータ
#include <iostream> #include <string> #include <pstade/oven/io.hpp> #include <pstade/oven/transformed.hpp> #include <pstade/oven/identities.hpp> #include <pstade/oven/copied.hpp> #include <pstade/oven/zipped.hpp> #include <pstade/oven/distance.hpp> #include <pstade/oven/counting.hpp> #include <pstade/oven/cycled.hpp> #include <pstade/oven/initial_values.hpp> #include <boost/array.hpp> #include <boost/tuple/tuple_io.hpp> #include <boost/range/algorithm/for_each.hpp> namespace trumps{ //-------------------------------------- // 絵柄 enum suit{ spade = 0, heart, diamond, club, max_suit }; typedef suit suit_t; std::string suit_to_string(const suit_t& suit){ static const boost::array<char*, 4> str = {{"spade", "heart", "diamond", "club"}}; return str[suit]; } //========================================================== //-------------------------------------- // 数字 typedef int number_t; static const number_t min_number = 1; static const number_t max_number = 13; //========================================================== } // namespace trumps int main(){ namespace oven = pstade::oven; // 絵柄データ boost::array<trumps::suit_t, trumps::max_suit> suits = { trumps::spade, trumps::heart, trumps::diamond, trumps::club }; std::cout << (suits|oven::transformed(trumps::suit_to_string)) << std::endl; // 数値データ boost::array<trumps::number_t, trumps::max_number> numbers = oven::counting(trumps::min_number, trumps::max_number+1)|oven::copied; std::cout << (numbers|oven::identities) << std::endl; // 2つのデータを組み合わせて出力してみる boost::for_each( boost::make_tuple( suits, (oven::initial_values(numbers)|oven::cycled(suits|oven::distance)) )|oven::zipped, [](boost::tuple< trumps::suit, boost::array<trumps::number_t, trumps::max_number> > t){ std::cout << trumps::suit_to_string(t.get<0>()) << (t.get<1>()|pstade::oven::identities) <<std::endl; } ); return 0; }
[出力]
{spade,heart,diamond,club} {1,2,3,4,5,6,7,8,9,10,11,12,13} spade{1,2,3,4,5,6,7,8,9,10,11,12,13} heart{1,2,3,4,5,6,7,8,9,10,11,12,13} diamond{1,2,3,4,5,6,7,8,9,10,11,12,13} club{1,2,3,4,5,6,7,8,9,10,11,12,13}
トランプは、1〜13×4つの絵柄の52枚が必要です。
今回は、無駄なデータを省いて、1〜13の数値と4つの絵柄のデータを組み合わせて使っていきたいと思います。
こんな感じのデータ。
{spade,heart,diamond,club} // 文字列ではなく、列挙型で保持 {1,2,3,4,5,6,7,8,9,10,11,12,13}
プレイヤーの手札や場に出したカードも全てこれを元にした range で保持していきたいと思います。
//-------------------------------------- // カード typedef boost::fusion::vector<suit_t, number_t> card_t; typedef pstade::oven::any_range< card_t, boost::forward_traversal_tag > any_card_range; any_card_range hand_card; // 手札
全体的に実験的な試みなので、これが正しいのかどうかは謎です。
いまさらながらちゃんと設計した方がいいような気がしてきた・・・。
[boost/pstade]
ver 1.44.0 / ver 1.04.3