GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — AIBlockBattle/bitField.h at master · dzou/AIBlockBattle Expand file tree/ Copy pathbitField.hMore file actions 87 lines (68 loc) · 2.2 KB / Copy pathbitField.hFile metadata and controls87 lines (68 loc) · 2.2 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 #ifndef __BIT_FIELD_H #define __BIT_FIELD_H #include <string> #include <vector> #include "shape.h" #define EMPTY_ROW 0xF00000FF #define FULL_ROW 0xFAAAAAFF #define SOLID_ROW 0xFFFFFFFF #define CELL_SELECTOR 3 class BitField { public: int width_; int height_; std::vector<int> grid_; BitField(BitField &&other); BitField& operator=(BitField&& other); BitField& operator=(const BitField& other); BitField(const BitField &other); BitField(int width, int height); BitField(int width, int height, std::string fieldString); bool operator==(const BitField &field) const; bool operator!=(const BitField &field) const; std::string toString() const; bool isTSpin(const Shape &s) const; void printHex() const; void placePiece(const Shape &s); int clearLines(); void dropPiece(Shape &s) const; int getHoleCount() const; bool inField(const Shape &s) const; std::vector<int> getContourProfile() const; std::vector<std::pair<int, int>> getHoles() const; void setCell(int row, int col, Cell cell); bool isPerfectClear() const; inline int getCell(int row, int col) const { return (grid_[row + 2] >> 2 * (width_ - col + 3)) & CELL_SELECTOR; } inline const int& getRow(int row) const { return grid_[row + 2]; } inline bool isValid(const Shape &s, const Move &dir) const { int rOffset = 0; int cOffset = 0; if (dir == Move::DOWN) { rOffset = 1; } else if (dir == Move::UP) { rOffset = -1; } else if (dir == Move::LEFT) { cOffset = -1; } else if (dir == Move::RIGHT) { cOffset = 1; } int adjRow = s.row_ + rOffset + 2; int adjCol = s.col_ + cOffset; const std::vector<int> &blocks = s.getBlocks(); int shapeWidth = blocks.size(); for (int i = 0; i < shapeWidth; ++i) { if ((grid_[adjRow + i] & (blocks[i] << 2 * (14 - shapeWidth - adjCol))) != 0) { return false; } } return true; } inline bool isValid(const Shape &s) const { return isValid(s, Move::SKIP); } }; namespace std { template<> struct hash<BitField> { size_t operator()(const BitField &bf) const { size_t result = 0; for (int i = 0; i < bf.height_; i++) { result ^= bf.grid_[i]; result <<= 1; } return result; } }; } #endif // __BIT_FIELD_H |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |