Revision Log
Revision: 1.4 - (view) (download) (as text)
| 1 : | ktanaka | 1.2 | #ifndef _PAT_MATCH_H |
| 2 : | #define _PAT_MATCH_H | ||
| 3 : | |||
| 4 : | ktanaka | 1.1 | #include <string> |
| 5 : | ktanaka | 1.4 | #include <iostream> |
| 6 : | ktanaka | 1.1 | #include "BitmapFont.h" |
| 7 : | #include "Assumption.h" | ||
| 8 : | ktanaka | 1.4 | #include <vector> |
| 9 : | ktanaka | 1.1 | |
| 10 : | /* @ : 黒 */ | ||
| 11 : | /* . : 白 */ | ||
| 12 : | /* else(?) : どちらでも */ | ||
| 13 : | class PatMatch{ | ||
| 14 : | ktanaka | 1.4 | friend std::ostream& operator<<(std::ostream &os,const PatMatch &pm); |
| 15 : | ktanaka | 1.2 | protected: |
| 16 : | ktanaka | 1.1 | int width, height; |
| 17 : | ktanaka | 1.4 | std::string pat; |
| 18 : | ktanaka | 1.1 | Assumption assumption; |
| 19 : | public: | ||
| 20 : | ktanaka | 1.4 | PatMatch(int w,int h,std::string s,const Assumption &as) |
| 21 : | ktanaka | 1.1 | :width(w), height(h), pat(s), assumption(as){ |
| 22 : | assert(pat.length() == (unsigned int)width*height); | ||
| 23 : | } | ||
| 24 : | ktanaka | 1.4 | PatMatch(int w,int h,std::string s, const SimpleAssumption &sa) |
| 25 : | ktanaka | 1.2 | :width(w), height(h), pat(s), assumption(){ |
| 26 : | assumption.add(sa); | ||
| 27 : | assert(pat.length() == (unsigned int)width*height); | ||
| 28 : | } | ||
| 29 : | int get(int x,int y) const{ | ||
| 30 : | return pat[y*width+x]; | ||
| 31 : | } | ||
| 32 : | ktanaka | 1.4 | #if 0 |
| 33 : | ktanaka | 1.1 | bool isMatch(const BitmapFont& bf, int x, int y) const{ |
| 34 : | for(int i=0;i<width;i++) | ||
| 35 : | for(int j=0;j<height;j++){ | ||
| 36 : | if(bf.get(x+i,y+j)){ | ||
| 37 : | ktanaka | 1.2 | if(get(i,j)=='.') return false; |
| 38 : | ktanaka | 1.1 | } |
| 39 : | ktanaka | 1.2 | else if(get(i,j)=='@') return false; |
| 40 : | ktanaka | 1.1 | } |
| 41 : | return true; | ||
| 42 : | } | ||
| 43 : | ktanaka | 1.4 | #endif |
| 44 : | int matchPenalty(const BitmapFont& bf, int x, int y) const{ | ||
| 45 : | int penalty=0; | ||
| 46 : | for(int i=0;i<width;i++) | ||
| 47 : | for(int j=0;j<height;j++){ | ||
| 48 : | if(bf.get(x+i,y+j)){ | ||
| 49 : | if(get(i,j)=='.') return -1; | ||
| 50 : | else if(get(i,j)=='*') penalty++; | ||
| 51 : | } | ||
| 52 : | else if(get(i,j)=='@') return -1; | ||
| 53 : | } | ||
| 54 : | return penalty; | ||
| 55 : | } | ||
| 56 : | std::vector<pixel> getPixels(int x, int y) const{ | ||
| 57 : | std::vector<pixel> pixels; | ||
| 58 : | ktanaka | 1.2 | for(int i=0;i<width;i++) |
| 59 : | for(int j=0;j<height;j++){ | ||
| 60 : | ktanaka | 1.3 | if(get(i,j)=='@'){ |
| 61 : | ktanaka | 1.2 | pixels.push_back(pixel(x+i,y+j)); |
| 62 : | } | ||
| 63 : | } | ||
| 64 : | return pixels; | ||
| 65 : | } | ||
| 66 : | ktanaka | 1.1 | }; |
| 67 : | ktanaka | 1.4 | std::ostream& operator<<(std::ostream &os,const PatMatch &pm){ |
| 68 : | ktanaka | 1.2 | return os << "PatMatch(width=" << pm.width << ",height=" << pm.height << |
| 69 : | ",pat=" << pm.pat << "," << pm.assumption << ")"; | ||
| 70 : | } | ||
| 71 : | #endif /* _PAT_MATCH_H */ |
|
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |