00001
00002
00003 #include "osl/eval/ppair/piecePairRawEval.h"
00004 #include "osl/eval/ppair/piecePairEval.tcc"
00005 #include "osl/stl/vector.h"
00006 #include "osl/oslConfig.h"
00007 #include <boost/static_assert.hpp>
00008 #include <algorithm>
00009 #include <fstream>
00010 #include <iostream>
00011
00012 namespace osl
00013 {
00014 namespace eval
00015 {
00016 namespace ppair
00017 {
00018 BOOST_STATIC_ASSERT(PiecePairIndex::maxPtypeOIndex == 32);
00019
00020 BOOST_STATIC_ASSERT((PiecePairEvalBase::ROUND_UP
00021 & (PiecePairEvalBase::ROUND_UP-1))
00022 == 0);
00023 BOOST_STATIC_ASSERT(PiecePairEvalBase::ROUND_UP >= 2);
00024
00025 template class PiecePairEvalTableBase<PiecePairRawTable>;
00026 template class PiecePairEval<PiecePairRawEval,PiecePairRawTable>;
00027 }
00028 }
00029 }
00030
00031 osl::eval::ppair::
00032 PiecePairRawTable::PiecePairRawTable()
00033 {
00034 }
00035
00036 osl::eval::ppair::
00037 PiecePairRawTable::~PiecePairRawTable()
00038 {
00039 }
00040
00041 void osl::eval::ppair::
00042 PiecePairRawTable::writeInBinaryFile(const char *filename) const
00043 {
00044 std::ofstream os(filename);
00045 osl::stl::vector<signed char> buffer(82*PTYPEO_SIZE*82*PTYPEO_SIZE);
00046 for(int i=0;i<82;i++){
00047 Position pos0=PositionCompressor::melt(i);
00048 for(int j=0;j<82;j++){
00049 Position pos1=PositionCompressor::melt(j);
00050 for(int k=0;k<PTYPEO_SIZE;k++)
00051 for(int l=0;l<PTYPEO_SIZE;l++){
00052 int index0=PiecePairIndex::indexOf(pos0,static_cast<PtypeO>(k+PTYPEO_MIN));
00053 int index1=PiecePairIndex::indexOf(pos1,static_cast<PtypeO>(l+PTYPEO_MIN));
00054 int index=PiecePairIndex::indexOf(index0,index1);
00055
00056 buffer[(i*32+k)*82*32+(j*32+l)]=values[index];
00057 }
00058 }
00059
00060 }
00061 os.write(reinterpret_cast<const char*>(&*buffer.begin()),buffer.size());
00062 }
00063
00064 bool osl::eval::ppair::
00065 PiecePairRawTable::
00066 loadFromBinaryFile(const char *filename) const
00067 {
00068 if (OslConfig::verbose())
00069 std::cerr << "PiecePairRawTable loading " << filename << "\n";
00070 std::ifstream is(filename);
00071 osl::stl::vector<signed char> buffer(82*PTYPEO_SIZE*82*PTYPEO_SIZE);
00072 is.read(reinterpret_cast<char*>(&*buffer.begin()), buffer.size());
00073 for(int i=0;i<82;i++){
00074 Position pos0=PositionCompressor::melt(i);
00075 for(int j=0;j<82;j++){
00076 Position pos1=PositionCompressor::melt(j);
00077 for(int k=0;k<PTYPEO_SIZE;k++)
00078 for(int l=0;l<PTYPEO_SIZE;l++){
00079 int index0=PiecePairIndex::indexOf(pos0,static_cast<PtypeO>(k+PTYPEO_MIN));
00080 int index1=PiecePairIndex::indexOf(pos1,static_cast<PtypeO>(l+PTYPEO_MIN));
00081 int index=PiecePairIndex::indexOf(index0,index1);
00082 if(!pos0.isPieceStand() && !pos1.isPieceStand())
00083 values[index]=buffer[(i*32+k)*82*32+(j*32+l)];
00084 else
00085 values[index]=0;
00086 }
00087 }
00088 }
00089 if (! is)
00090 return false;
00091
00092 return true;
00093 }
00094
00095 bool osl::eval::ppair::
00096 PiecePairRawTable::
00097 setUp(const char *filename) const
00098 {
00099 static std::string filename_memory;
00100 if (! filename_memory.empty())
00101 {
00102 if (filename_memory != filename)
00103 {
00104 std::cerr << "PiecePairRawTable: don't load " << filename
00105 << ", since " << filename_memory
00106 << " already loaded \n";
00107 return false;
00108 }
00109 return true;
00110 }
00111 filename_memory = filename;
00112 return loadFromBinaryFile(filename);
00113 }
00114
00115
00116
00117
00118
00119