00001 #ifndef _KISEN_H
00002 #define _KISEN_H
00003
00004 #include "osl/record/record.h"
00005 #include "osl/position.h"
00006 #include "osl/misc/carray.h"
00007 #include <string>
00008 #include <iosfwd>
00009 #include <fstream>
00010 namespace osl
00011 {
00012 namespace record
00013 {
00014 class KisenUtils{
00015 public:
00016 static Position convertPosition( int pos );
00017 static Move convertMove( SimpleState const& state,int c0,int c1 );
00018 };
00019
00020 class IKisenStream : public IRecordStream{
00021 private:
00022 CArray<unsigned char, 512> cbuf;
00023 SimpleState state;
00024 RecordVisitor rv;
00025 public:
00026 IKisenStream(char const readbuf[]) : state(HIRATE) {
00027 std::copy(&readbuf[0],&readbuf[512],&cbuf[0]);
00028 }
00029 SimpleState getState() const { return state;}
00030 virtual void load(Record*);
00031 virtual ~IKisenStream(){};
00032 };
00037 class KisenFile{
00038 private:
00039 std::ifstream ifs;
00040 size_t numberOfGames;
00041 SimpleState const initialState;
00042 const std::string fileName;
00043 public:
00044 static const size_t maxMoves=256;
00045 explicit KisenFile(const std::string& fileName);
00046 ~KisenFile();
00047
00048 size_t size() const{ return numberOfGames; }
00049 SimpleState const& getInitialState() const{ return initialState; }
00050 const vector<Move> getMoves(size_t index);
00051 const std::string& getFileName() const { return fileName; }
00052 std::string getIpxFileName() const;
00053 };
00059 class KisenIpxFile{
00060 std::ifstream ifs;
00061 size_t numberOfGames;
00062 const std::string file_name;
00063 public:
00064 enum{
00065 BY_PARITY=0,
00066 BLACK_WIN=1,
00067 WHITE_WIN=2,
00068 SENNNICHITE=3,
00069 JISHOGI=4,
00070 BLACK_WIN_256=5,
00071 WHITE_WIN_256=6,
00072 SENNNICHITE_256=7,
00073 JISHOGI_256=8,
00074 };
00075 explicit KisenIpxFile(std::string const& fileName);
00076 ~KisenIpxFile();
00077
00078 size_t size() const{ return numberOfGames; }
00079 const std::string getPlayer(size_t index,Player pl);
00080 const std::string getTitle(size_t index,Player pl);
00081 unsigned int getRating(size_t index,Player pl);
00082 unsigned int getResult(size_t index);
00083 const std::string& getFileName() const { return file_name; }
00084 };
00089 class KisenPlusFile{
00090 private:
00091 std::ifstream ifs;
00092 size_t numberOfGames;
00093 SimpleState const initialState;
00094 public:
00095 static const size_t maxMoves=256;
00096 explicit KisenPlusFile(const std::string& fileName);
00097 size_t size() const{ return numberOfGames; }
00098 SimpleState const& getInitialState() const{ return initialState; }
00099 const vector<Move> getMoves(size_t index);
00100 void getMoves(size_t index, vector<Move>&, vector<int>&);
00101 };
00102 }
00103 using record::KisenFile;
00104 using record::KisenIpxFile;
00105 }
00106 #endif // _KISEN_H
00107
00108
00109
00110