|
#ifndef _PAT_MATCH_H |
|
#define _PAT_MATCH_H |
|
|
#include <string> |
#include <string> |
#include "BitmapFont.h" |
#include "BitmapFont.h" |
#include "Assumption.h" |
#include "Assumption.h" |
/* . : 白 */ |
/* . : 白 */ |
/* else(?) : どちらでも */ |
/* else(?) : どちらでも */ |
class PatMatch{ |
class PatMatch{ |
private: |
friend ostream& operator<<(ostream &os,const PatMatch &pm); |
|
protected: |
int width, height; |
int width, height; |
string pat; |
string pat; |
Assumption assumption; |
Assumption assumption; |
public: |
public: |
PatMatch(int w,int h,string s,Assumption as) |
PatMatch(int w,int h,string s,const Assumption &as) |
:width(w), height(h), pat(s), assumption(as){ |
:width(w), height(h), pat(s), assumption(as){ |
assert(pat.length() == (unsigned int)width*height); |
assert(pat.length() == (unsigned int)width*height); |
} |
} |
|
PatMatch(int w,int h,string s, const SimpleAssumption &sa) |
|
:width(w), height(h), pat(s), assumption(){ |
|
assumption.add(sa); |
|
assert(pat.length() == (unsigned int)width*height); |
|
} |
|
int get(int x,int y) const{ |
|
return pat[y*width+x]; |
|
} |
bool isMatch(const BitmapFont& bf, int x, int y) const{ |
bool isMatch(const BitmapFont& bf, int x, int y) const{ |
for(int i=0;i<width;i++) |
for(int i=0;i<width;i++) |
for(int j=0;j<height;j++){ |
for(int j=0;j<height;j++){ |
if(bf.get(x+i,y+j)){ |
if(bf.get(x+i,y+j)){ |
if(pat[j*width+i]=='.') return false; |
if(get(i,j)=='.') return false; |
} |
} |
else if(pat[j*width+i]=='@') return false; |
else if(get(i,j)=='@') return false; |
} |
} |
return true; |
return true; |
} |
} |
|
vector<pixel> getPixels(int x, int y) const{ |
|
vector<pixel> pixels; |
|
for(int i=0;i<width;i++) |
|
for(int j=0;j<height;j++){ |
|
if(get(i,j)=='@'){ |
|
pixels.push_back(pixel(x+i,y+j)); |
|
} |
|
} |
|
return pixels; |
|
} |
}; |
}; |
|
ostream& operator<<(ostream &os,const PatMatch &pm){ |
|
return os << "PatMatch(width=" << pm.width << ",height=" << pm.height << |
|
",pat=" << pm.pat << "," << pm.assumption << ")"; |
|
} |
|
#endif /* _PAT_MATCH_H */ |