/** * Play moves on move at a time */ void Board::playMoves() { std::list<Coords>::const_iterator iterator; bool allMovesGood = true; for (iterator = moves.begin(); iterator != moves.end(); ++iterator) { Coords move = *iterator; if (legalCoord(move)) { if (move.isStartMove()) { cmatrix[move.m_y][move.m_x].m_pointType = PointType::Start; currentMove = move; printBoardBasic(); continue; } else if (move.isEndMove()) { cmatrix[move.m_y][move.m_x].m_pointType = PointType::End; } else { cmatrix[move.m_y][move.m_x].m_pointType = PointType::Normal; } if (!isValidMove(currentMove, move)) { allMovesGood = false; cout << "Move " << move << " is invalid" << endl; } else { cout << "Move " << move << " is valid" << endl; } currentMove = move; printBoardBasic(); } else { allMovesGood = false; cout << "Move " << move << " is invalid" << endl; } } if (allMovesGood) { cout << "Summary: All moves are valid" << endl; } else { cout << "Summary: There are some invalid moves in the sequence" << endl; } }
bool InCollectionSolver::SolveSquare(Coords coords) { bool didSomething = false; Square * toSolve = _theBoard->GetSquare(coords); const vector<int> values = toSolve->Values(); if (CheckIn(toSolve, _theBoard->GetCol(coords), coords.YCoord())) { _stats[ColToken]++; didSomething = true; } if (CheckIn(toSolve, _theBoard->GetRow(coords), coords.XCoord())) { _stats[RowToken]++; didSomething = true; } if (CheckIn(toSolve, _theBoard->GetArea(coords), _theBoard->IndexInAreaMap(coords))) { _stats[AreaToken]++; didSomething = true; } // Return whether we have managed to eliminate any possibilities return didSomething; }
Coords GetSeedPoints() { Coords seedPoints; for( int row = 0; row < 15; ++row ) { for( int col = 0; col < 15; ++col ) { int cell = row * 15 + col; if( !isalpha( board_state[cell] ) ) { int n = row * 15 + col; if( row > 0 ) n -= 15; int s = row * 15 + col; if( row < 14 ) s += 15; int e = row * 15 + col; if( col > 0 ) e -= 1; int w = row * 15 + col; if( col < 14 ) w += 1; bool ns = false; if( isalpha( board_state[n] ) || isalpha( board_state[s] ) ) ns = true; bool ew = false; if( isalpha( board_state[e] ) || isalpha( board_state[w] ) ) ew = true; if( ns || ew ) seedPoints.push_back( Coord( row, col ) ); } } } if( seedPoints.empty() ) seedPoints.push_back( Coord( 7, 7 ) ); return seedPoints; }
bool Coords::operator==(const Coords& c) const { double tol = 0.05; if (std::abs(c.getX() - this->getX()) < tol and std::abs(c.getY() - this->getY()) < tol) { return true; } return false; }
void TestCoord::test_DegreeToDecimal(){ cutDecLat=cutNumber(mssr_veljav.getDecLatitude()); cutDecLong=cutNumber(mssr_veljav.getDecLongitude()); QCOMPARE(cutDecLat,48.26071); QCOMPARE(cutDecLong,17.16328); cutDecLat=cutNumber(mssr_bucen.getDecLatitude()); cutDecLong=cutNumber(mssr_bucen.getDecLongitude()); QCOMPARE(cutDecLat,48.30554); QCOMPARE(cutDecLong,19.87072); cutDecLat=cutNumber(mie_mor.getDecLatitude()); cutDecLong=cutNumber(mie_mor.getDecLongitude()); QCOMPARE(cutDecLat,48.06166); QCOMPARE(cutDecLong,17.37638); cutDecLat=cutNumber(mich_p37.getDecLatitude()); cutDecLong=cutNumber(mich_p37.getDecLongitude()); QCOMPARE(cutDecLat,48.72360); QCOMPARE(cutDecLong,21.95121); cutDecLat=cutNumber(po_mor5.getDecLatitude()); cutDecLong=cutNumber(po_mor5.getDecLongitude()); QCOMPARE(cutDecLat,49.03201); QCOMPARE(cutDecLong,21.31433); }
/// Tries to add another sequence onto the start or end of this one. /// If it succeeds, the other sequence may also be modified and /// should be considered "spent". bool tryAdd(CoordinateSequence &other) { //add the sequence at the end if (last()==other.first()) { coordinates.pop_back(); addToEnd(other.coordinates); return true; } //add the sequence backwards at the end if (last()==other.last()) { coordinates.pop_back(); other.reverse(); addToEnd(other.coordinates); return true; } //add the sequence at the beginning if (first()==other.last()) { coordinates.pop_front(); addToBegin(other.coordinates); return true; } //add the sequence backwards at the beginning if (first()==other.first()) { coordinates.pop_front(); other.reverse(); addToBegin(other.coordinates); return true; } return false; }
size_t Board::coordsToIndex(const Coords &c) const { if (!inRange(c)) { throw std::out_of_range("Passed coords are outside of board range."); } return dim.getX() * c.getX() + c.getY(); }
bool UniqueInCollectionSolver::SolveSquare(Coords coords) { bool madeProgress = false; Square * toSolve = _theBoard->GetSquare(coords); // For this solver, as we will solve the square as soon as we make progress // there is no point in checking any other collections as soon as one returns // true if (CheckForUniqueSolution(_theBoard->GetArea(coords), toSolve, _theBoard->IndexInAreaMap(coords))) { _stats[AreaToken]++; madeProgress = true; } if (!madeProgress && CheckForUniqueSolution (_theBoard->GetRow(coords), toSolve, coords.XCoord())) { _stats[RowToken]++; madeProgress = true; } if (!madeProgress && CheckForUniqueSolution(_theBoard->GetCol(coords), toSolve, coords.YCoord())) { _stats[ColToken]++; madeProgress = true; } return madeProgress; }
Coords ChunkManager::blockToChunkCoords(Coords in) { int newX = std::floor((float)in.x() / (float)Chunk::chunkWidth); int newY = std::floor((float)in.y() / (float)Chunk::chunkWidth); int newZ = std::floor((float)in.z() / (float)Chunk::chunkHeight); Coords result = Coords(newX, newY, newZ); return result; }
// Make a mapping between some coordinates on the board an an integer // representing the area it is part of. So for a 3x3 board this will // look like: // 000|111|222 // 000|111|222 // 000|111|222 // ----------- // 333|444|555 // 333|444|555 // 333|444|555 // ----------- // 666|777|888 // 666|777|888 // 666|777|888 // int Board::GetAreaIdForCoords(Coords coords) { int areaSize = GetAreaSideSize(); // Assumes we down fractions down when assigning to int int xComponent = coords.XCoord() / areaSize; int yComponent = coords.YCoord() / areaSize; return yComponent * areaSize + xComponent; }
int Board::IndexInAreaMap(Coords coords) { // If we are using the boards area map, derive the index in the area // returned which signifies the square at the x/y coords. This assumes // that the squares in an area are populated by x coord, and then by // y. int areaSideSize = GetAreaSideSize(); return coords.XCoord() % areaSideSize + (areaSideSize * (coords.YCoord() % areaSideSize)); }
void print() { std::cout << "Actor is holding: " << std::endl; if (run != "") { std::cout << "run: " << run << std::endl; coords_run->print(); } if (hit != "") { std::cout << " hit: " << hit << std::endl; coords_hit->print(); } }
bool Board::IsSquareValid(Coords coords, int solvedValue) { // Check that the solved value of this square doesn't appear in any of // the rows, columns or areas it belongs to as a solved value too if (ContainsSolvedValue(GetRow(coords), solvedValue, coords.XCoord()) || ContainsSolvedValue(GetCol(coords), solvedValue, coords.YCoord()) || ContainsSolvedValue(GetArea(coords), solvedValue, IndexInAreaMap(coords))) { cout << "Found invalid repeated value of " << solvedValue << endl; return false; } return true; }
void ClassCPV::move(const e_Dir d) { if(clientstate == CS_NORMAL) // regular movement Network::send_action(XN_MOVE, d); else if(clientstate == CS_AIMING) // moving the aimer { aimer = aimer.in(d); if(aimer.x > VIEWSIZE/2) aimer.x--; else if(aimer.x < -VIEWSIZE/2) aimer.x++; if(aimer.y > VIEWSIZE/2) aimer.y--; else if(aimer.y < -VIEWSIZE/2) aimer.y++; redraw_view(); } else if(clientstate == CS_DIR) // waiting for dir input (and now got it!) { if(myclass == C_FIGHTER) Network::send_action(XN_CIRCLE_ATTACK, d); else if(myclass == C_HEALER) Network::send_action(XN_HEAL, d); else if(myclass == C_MINER) Network::send_action(XN_MINE, d); else if(myclass == C_COMBAT_MAGE) Network::send_action(XN_ZAP, d); clientstate = CS_NORMAL; } // else ignore }
void ChunkManager::setCenterChunk(Coords center, bool force) { if (center == _center && !force) return; _center = center; //Delete out-of-range chunks for (chunkMap_type::iterator it = _chunkMap.begin(); it != _chunkMap.end(); /* No increment */) { if (it->first.dist_squared_2D(center) > _visibility * _visibility) { delete it->second; it = _chunkMap.erase(it); //returns next element } else { it++; } } //load missing chunks for (int x = center.x() - _visibility; x <= center.x() + _visibility; x++) { for (int y = center.y() - _visibility; y <= center.y() + _visibility; y++) { for (int z = 0; z <= BlockGrid::gridHeight / Chunk::chunkHeight; z++) { if (z < 0) z = 0; //ensure we don't go too low Coords coords(x, y, z); if (coords.dist_squared_2D(center) < _visibility * _visibility) { Coords coords(x, y, z); chunkMap_type::iterator it = _chunkMap.find(coords); if (it == _chunkMap.end()) { chunkLoader.requestLoadChunk(coords); //_dirtyChunks.push_front(chunk); } } } } } }
/** * Set first move as start move, set newly add move as end move * Automatically set move sequence number */ void Board::addMove(Coords move) { if (moves.empty()) { move.m_pointType = PointType::Start; } else { if (moves.size() >= 2) { Coords& lastMove = moves.back(); lastMove.setMoveType(PointType::Normal); } move.setMoveType(PointType::End); } move.m_seq = moves.size() + 1; moves.push_back(move); }
// RECURSION bool MazeBoard::checkPath(Coords start_pos, Coords end_pos, std::vector<Coords> &open_queue) { if (start_pos == end_pos) return true; open_queue.push_back(start_pos); // expand to right if (board[INDEX_C(start_pos)].canGo(RIGHT) && onBoard(start_pos.right()) && board[INDEX_C(start_pos.right())].canGo(LEFT) && notInQueue(start_pos.right(), open_queue) && checkPath(start_pos.right(), end_pos, open_queue)) return true; else if (board[INDEX_C(start_pos)].canGo(DOWN) && onBoard(start_pos.down()) && board[INDEX_C(start_pos.down())].canGo(UP) && notInQueue(start_pos.down(), open_queue) && checkPath(start_pos.down(), end_pos, open_queue)) return true; else if (board[INDEX_C(start_pos)].canGo(LEFT) && onBoard(start_pos.left()) && board[INDEX_C(start_pos.left())].canGo(RIGHT) && notInQueue(start_pos.left(), open_queue) && checkPath(start_pos.left(), end_pos, open_queue)) return true; else if (board[INDEX_C(start_pos)].canGo(UP) && onBoard(start_pos.up()) && board[INDEX_C(start_pos.up())].canGo(DOWN) && notInQueue(start_pos.up(), open_queue) && checkPath(start_pos.up(), end_pos, open_queue)) return true; return false; }
virtual double getArea() { return fabs((c2.getX()-c1.getX())*(c2.getY()-c1.getY())); }
bool isClosed() const { return coordinates.size() > 1 && coordinates[0]==coordinates[coordinates.size() - 1]; }
bool containsRing(const Coords &other) const { return std::all_of(other.begin(), other.end(), [&](const GeoCoordinate &c) { return utymap::utils::GeoUtils::isPointInPolygon(c, coordinates.begin(), coordinates.end()); }); }
virtual void operator()(const Coords &r, Coords &x, const double t = 0) const { x = Coords(r.size(),0.);x[pol_] = field_->operator()(t); }
GeoCoordinate last() const { return coordinates[coordinates.size() - 1]; }
bool Board::inRange(const Coords &c) const { return c.getX() < dim.getX() && c.getY() < dim.getY(); }
void addToEnd(const Coords &other) { coordinates.insert(coordinates.end(), other.begin(), other.end()); }
bool Coords::operator<(const Coords& c) const { return this->getX() < c.getX() or(this->getX() == c.getX() and this->getY() < c.getY()); }
void reverse() { std::reverse(coordinates.begin(), coordinates.end()); }
virtual void operator()(const Coords &r, Coords &x, const double t=0) const {x = Coords(r.size(),0);};
void CTwoOptDlg::OnPaint() { // device context for painting //CDC memDC ; // buffer context CPaintDC dc(this); if (IsIconic()) { SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { if ( CoordsMatrix_.size() < 1 ) return; // device context for painting CPen penDot(PS_DOT,1,RGB(255,0,0)); CPen penblack(PS_SOLID,3,RGB(0,0,0)); CRect rect; GetClientRect(&rect); int rectx1 = rect.left + 20; int rectx2 = rect.right - 170; int recty1 = rect.top + 25; int recty2 = rect.bottom - bottom_limit; dc.Rectangle(rectx1-5,recty1-5,rectx2+5,recty2+5); // Plot each node size_t tour_size = CoordsMatrix_.size(); for ( count = 0; count < tour_size; count++ ) { Coords mat = CoordsMatrix_[count]; xc1 =static_cast<int>(mat.GetX()); yc1 = static_cast<int>(mat.GetY()); xn1 = (float) ( xc1 - MinX ) / (float) ( MaxX - MinX ); yn1 = (float) ( yc1 - MinY ) / (float) ( MaxY - MinY ); xcoord1 = rectx1 + (int) (float) ( xn1 * abs( rectx1 - rectx2 ) ); ycoord1 = recty2 - (int) (float) ( yn1 * abs( recty1 - recty2 ) ); dc.SelectObject(&penblack); dc.Ellipse( xcoord1 - 2, ycoord1 - 2, xcoord1 + 2, ycoord1 + 2 ); //draw lines dc.SelectObject(&penDot); //draw last tour if ( hasRun && count < tour_size - 1 && m_lasttour.Tour.size()) { m_lasttour.Tour[count]; cc1 = static_cast<int>(m_lasttour.Tour[count]); cc2 = static_cast<int>(m_lasttour.Tour[count +1]); DrawNodes(cc1 , cc2, rectx1, rectx2, recty2, recty1, dc); } dc.SelectObject(&penblack); if ( hasRun && count < tour_size - 1 && m_besttour.Tour.size()) { cc1 = static_cast<int>(m_besttour.Tour[count]); cc2 = static_cast<int>(m_besttour.Tour[count +1]); DrawNodes(cc1 , cc2, rectx1, rectx2, recty2, recty1, dc); } } // Draw final link if ( hasRun ) { if(m_lasttour.Tour.size()) { cc1 = static_cast<int>(m_lasttour.Tour[tour_size-1]); cc2 = static_cast<int>( m_lasttour.Tour[0]); dc.SelectObject(&penDot); DrawNodes(cc1 , cc2, rectx1, rectx2, recty2, recty1, dc); } if(m_besttour.Tour.size()) { dc.SelectObject(&penblack); cc1 = static_cast<int>(m_besttour.Tour[tour_size-1]); cc2 = static_cast<int>(m_besttour.Tour[0]); DrawNodes(cc1 , cc2, rectx1, rectx2, recty2, recty1, dc); } } CDialogEx::OnPaint(); } }
void mapGen(int** checkWall, int** checkVisited, int X, int Y) { int x = 0, y = 1, tolerance = 0; //x and y are the starting coordinates of the path through the maze int sum = 0; Coords temp; temp.setCoords(1, 0); stack<Coords> coordinates; coordinates.push(temp); while (!coordinates.empty()) { //continues the loop until the stack is emptied ////////////////////////////////////////////////// cout << "size of stack: " << coordinates.size() << endl; mapgen << "size of stack: " << coordinates.size() << endl; ///////////////////////////////////////////////// int* possible = checkAvail(coordinates.top(), checkVisited, X, Y, tolerance); //ptr to the array of size 4 that contains the four directions' validity sum = 0; for (int i = 0; i < 4; i++) { sum += possible[i]; //sets sum to the total number of choices } //////////////////////////////////// Coords test = coordinates.top(); int testX = test.getX(); int testY = test.getY(); mapgen << "options: " << sum << " coords: " << testX << " " << testY << endl; /////////////////////////////////////// if (sum == 0) { //executes if there are no choices at the current location (dead end) coordinates.pop(); //pops the top layer off the stack tolerance = 1; //allows checkAvail to evaluate to true even if the location has been visited once before (allows the making of intersections ///////////////////////////////////////// mapgen << "pop" << endl; ///////////////////////////////////////// continue; //back up to beginning of the while loop } tolerance = 0; //for checkAvail on the next run through the loop temp = coordinates.top(); //local variables for the x- and y-coordinates of the current location x = temp.getX(); y = temp.getY(); int Picked = pickDir(possible); ////////////////////////// mapgen << "direction:" << Picked << endl; ///////////////////////// if (x > 0) //updates checkVisited now that we've moved checkVisited[x - 1][y] ++; // if (x < X - 2) // checkVisited[x + 1][y] ++; // if (y > 0) // checkVisited[x][y - 1] ++; // if (y < Y - 2) // checkVisited[x][y + 1] ++; // switch (Picked) //moves us to the next location { // case 0: { //up // y--; // break; // } // case 1: { //left // x--; // break; // } // case 2: { //down // y++; // break; // } // case 3: { //right // x++; // break; // } // } temp.setCoords(x, y); //puts the new location into a Coords object coordinates.push(temp); //adds the new location to the stack checkWall[x][y] = 0; //makes the new location a space checkVisited[x][y] += 2;//sets it to "double visited," so it can never be visited again } }
void deriv(const Coords &r, Coords &x, const double t = 0) const { x = Coords(r.size(),0.);x[pol_] = r[pol_] * field_->deriv(t); }