myshogi.cc
Go to the documentation of this file.
00001 /* myshogi.cc
00002  */
00003 #include "osl/record/myshogi.h"
00004 #include "osl/record/ki2.h"
00005 #include "osl/record/csa.h"
00006 #include "osl/pieceStand.h"
00007 #include <boost/foreach.hpp>
00008 #include <sstream>
00009 
00010 std::string osl::record::
00011 myshogi::show(const NumEffectState& state,
00012               Move last_move, const NumEffectState& prev, bool add_csa_move)
00013 {
00014   std::ostringstream os;
00015   os << "\\begin{myshogi}[.7] \\banmen \n";
00016   os << "\\mochigoma{\\sente}";
00017   BOOST_FOREACH(Ptype ptype, PieceStand::order)
00018     os << "{" << state.countPiecesOnStand(BLACK, ptype) << "}";
00019   os << "\n\\mochigoma{\\gote}";
00020   BOOST_FOREACH(Ptype ptype, PieceStand::order)
00021     os << "{" << state.countPiecesOnStand(WHITE, ptype) << "}";
00022   os << "\n";
00023   if (last_move.isNormal()) {
00024     os << "\\lastmove[" << last_move.to().x() << last_move.to().y()
00025        << "]{" << ki2::show(last_move, prev);
00026     if (add_csa_move)
00027       os << '(' << csa::show(last_move) << ')';
00028     os << "}\n";
00029   }
00030   for (int i=0; i<Piece::SIZE; ++i)
00031   {
00032     const Piece p = state.pieceOf(i);
00033     if (p.isOnBoard())
00034       os << show(p);
00035     if (i % 2)
00036       os << "\n";
00037   }
00038   os << "\\end{myshogi}\n";
00039   return os.str();
00040 }
00041 
00042 std::string osl::record::
00043 myshogi::show(const NumEffectState& state) 
00044 {
00045   static NumEffectState dummy;
00046   return show(state, Move(), dummy);
00047 }
00048 
00049 std::string osl::record::
00050 myshogi::show(Ptype p)
00051 {
00052   static CArray<std::string, PTYPE_SIZE> names = {{
00053       "", "", 
00054       "\\tokin", "\\narikyou", "\\narikei", "\\narigin", "\\uma", "\\ryu", 
00055       "\\ou", // todo: \\gyoku   
00056       "\\kin", "\\fu", "\\kyou", "\\kei", "\\gin", "\\kaku", "\\hi"
00057     }};
00058   return names[p];
00059 }
00060 
00061 std::string osl::record::
00062 myshogi::show(Square p)
00063 {
00064   std::string ret = "xx";
00065   ret[0] = '0'+p.x();
00066   ret[1] = '0'+p.y();
00067   return ret;
00068 }
00069 
00070 std::string osl::record::
00071 myshogi::show(Piece p)
00072 {
00073   if (! p.isOnBoard())
00074     return "";
00075   return std::string("\\koma{") + show(p.square()) + "}"
00076     + "{" + show(p.owner()) + "}{" + show(p.ptype()) + "}";
00077 }
00078 
00079 std::string osl::record::
00080 myshogi::show(Player p)
00081 {
00082   return p == BLACK ? "\\sente" : "\\gote";
00083 }
00084 // ;;; Local Variables:
00085 // ;;; mode:c++
00086 // ;;; c-basic-offset:2
00087 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines