// Mouse is moved void GLWidget::mouseMoveEvent(int x, int y) { double dx = x + _scrollOffset.x(); dx /= _zoomFactor; double dy = y + _scrollOffset.y(); dy /= _zoomFactor; // break markers if(_isMouseDown) { AnIndex idx = GetIndex(AVector(dx, dy)); AVector gVec(idx.x * _gridSpacing, idx.y * _gridSpacing); _drawBreakLine.XB = gVec.x; _drawBreakLine.YB = gVec.y; _drawEndIndex.x = idx.x; _drawEndIndex.y = idx.y; if(_drawBreakLine.GetLineType() == LineType::LINE_HORIZONTAL || _drawBreakLine.GetLineType() == LineType::LINE_VERTICAL) { std::vector<ALine> linev; linev.push_back(_drawBreakLine); PrepareLinesVBO(linev, &_drawBreakVbo, &_drawBreakVao, QVector3D(0.0, 0.0, 0.0)); } } // update canvas this->repaint(); }
// Mouse is pressed void GLWidget::mousePressEvent(int x, int y) { _isMouseDown = true; double dx = x + _scrollOffset.x(); dx /= _zoomFactor; double dy = y + _scrollOffset.y(); dy /= _zoomFactor; // break markers AnIndex idx = GetIndex(AVector(dx, dy)); if(_cells[idx.x][idx.y]._cellSign != CellSign::SIGN_EMPTY) { AVector gVec(idx.x * _gridSpacing, idx.y * _gridSpacing); _drawBreakLine.XA = gVec.x; _drawBreakLine.YA = gVec.y; _drawBreakLine.XB = gVec.x; _drawBreakLine.YB = gVec.y; _drawStartIndex.x = idx.x; _drawStartIndex.y = idx.y; _drawEndIndex.x = idx.x; _drawEndIndex.y = idx.y; if(_drawBreakVao.isCreated()) { _drawBreakVao.destroy(); } } // update canvas this->repaint(); }
// only contains digits string getHint(string secret, string guess) { int aCnt = 0; int bCnt = 0; vector<int> sVec(10, 0); // 0 ~ 9 for secret vector<int> gVec(10, 0); // 0 ~ 9 for guess if (secret.size() != guess.size() || secret.empty()) { return "0A0B"; } for (int i = 0; i < secret.size(); ++i) { char c1 = secret[i]; char c2 = guess[i]; if (c1 == c2) { ++aCnt; } else { ++sVec[c1-'0']; ++gVec[c2-'0']; } } // count b for (int i = 0; i < sVec.size(); ++i) { bCnt += min(sVec[i], gVec[i]); } return to_string(aCnt) + 'A' + to_string(bCnt) + 'B'; }