void qrw::DeploymentZone::crop(const Coordinates& size)
{
	auto iter = zone_.begin();
	while(iter != zone_.end())
	{
		Coordinates square = *iter;
		if(square.getX() >= size.getX() || square.getY() >= size.getY())
			iter = zone_.erase(iter);
		else
			++iter;
	}
}
Exemple #2
0
std::set< std::string > BoggleSolver::giveMeWords(std::string base, Coordinates start, std::set< Coordinates > alreadyUsed) const
{
  std::set< std::string > result;
  std::set< std::string > otherResult;
  base+=getLetter(start.getX(),start.getY());
  alreadyUsed.insert(start);
  if(base.size()>=MIN_WORD_LENGTH )
  {
    //Attention, upper != lower+1
    std::string upperBound = dictionnary.getUpperBound(base);

   if(dictionnary.isValid(base))
    result.insert(base);
    
   //Optimisation : si on ne trouve pas base dans le début de upper bound, on peut arreter
    if(upperBound.compare(0,base.size(),base)!=0)
      return result;

    
  }
  
  std::vector<Coordinates> adj = start.getAdjacent(gridSize-1,gridSize-1);
  for(std::vector<Coordinates >::const_iterator it = adj.begin(); it != adj.end();++it)
  {
    
      if(alreadyUsed.find(*it)==alreadyUsed.end())
      {
	otherResult = giveMeWords(base,*it,alreadyUsed);
	std::set_union(result.begin(), result.end(), otherResult.begin(), otherResult.end(), std::inserter(result,result.end()));

      }
   
  }
  return result;
}
Exemple #3
0
//------------------------------------------------------------------------------
void Game::findTeleportLocation(const string teleport_letter,
    const Coordinates& position, Coordinates& teleport_exit)
{
  int portal_x=0, portal_y=0;
  for (std::size_t y = 0; y < board_->size(); y++)
  {
    for (std::size_t x = 0; x < board_->at(y).size(); x++)
    {
      string symbol = board_->at(y).at(x)->getFieldSymbol(Field::FOR_GAME);
      
      // If the momentary field in this loop is not the one the player wants to
      // enter and if it has the same portal letter as the one he wants to enter
      // it must be the corresponding portal of that field.
      std::size_t player_x = position.getX();
      std::size_t player_y = position.getY();
      if (((x != player_x) || (y != player_y))
          && symbol == teleport_letter)
      {
        portal_x = static_cast<int>(x);
        portal_y = static_cast<int>(y);
      }
    }
  }

  teleport_exit.setX(portal_x);
  teleport_exit.setY(portal_y);
}
Exemple #4
0
/**
 * Does the damages. Damage is linear inside the damage radius.
 * @param capsule           The capsule.
 * @param collidingLocation The coordinates of the collision.
 */
void Projectile::doDamages( const BodyProjectile &capsule,
                            const Coordinates &collidingLocation )
{
	
	Body *body;
	BodyCannon *cannon;
	float damage;
	int i;
	
	for ( i = 0; ( body = capsule.getWorld().getBody( i ) ) != NULL; i++ ) {

		cannon = dynamic_cast<BodyCannon*>(body);
		if ( cannon ) {

			damage =
				this->getDamage( cannon->getLocation().getDistance(
					collidingLocation.getX(),
					collidingLocation.getY() ) );
					
			if ( damage )
				cannon->getOwner().doDamage( this->shooter, damage );
			
		}
			
	}
	
}
Exemple #5
0
void Display::displayText(std::string text, Coordinates position){
    const char* textTemp = text.c_str();
    		//Ne fonctionne pas tout le temps a verifier
    al_draw_text(font, (al_map_rgba(255, 0, 0, 255)), 
        position.getX(), position.getY(), ALLEGRO_ALIGN_CENTRE, textTemp);
    al_flip_display();
}
/*************************************************************************
* Function name: showTurn
* The Input: name of the player who played the turn, his guess and result
* The output: -
* The Function operation: displays the information about the played turn
*************************************************************************/
void Game::showTurn(string name, Coordinates& guess, HitStatus& status) {
	string hitStatuses[] = {"HIT", "MISS", "KILL"};

	cout << "\n" << name << " hits: "
			"(" << guess.getX() << ", " << guess.getY() << ")."
			"\tResult: " << hitStatuses[status] << "!\n";
	if (status != MISS) {
		cout << name << " gets another turn.\n";
	}
}
Exemple #7
0
/**
 * Handles mouse up events
 */
void WindowLocations::mouseUp(SDL_MouseButtonEvent button) {
	if (button.x > 824  &&  this->scrollMode == false) {
		//Clicking sidebar. Find out if a component was hit.
		UIComponent *component = findComponent(button.x, button.y);

		//'Next player' button
		if (component == butNext) {
			if (playerInTurn >= gameEngine.getPlayerCount())
				this->startGame();
			else
				this->nextPlayer();
		}
		
		//'Back to main menu' button
		else if (component == butQuit) {
			this->close(0);
		}
	} else {
		//Clicking game area
		
		//Convert to world coordinates
		Coordinates* coords = this->graphics.getWorldCoordinates(button.x, button.y);
		
		Player *player;
		Ai *ai = NULL;
		player = gameEngine.getPlayer(playerInTurn);
		
		if (player)
			ai = player->getAI();
		
		//If AI is in turn, disable controls
		if (ai)
			player = NULL;
			
		//Set location
		if (player  &&  this->dragDistance < 5) {
			if (player->setLocation(coords->getX(), coords->getY()) == 0) {
				this->sounds.playSound(SOUND_CLICK);
				nextPlayer();
			} else {
				this->sounds.playSound(SOUND_TICK);
			}
		}
		
		delete coords;
	}

	//Deactivate scroll mode
	if (this->scrollMode) {
		SDL_WM_GrabInput(SDL_GRAB_OFF);
		SDL_ShowCursor(SDL_ENABLE);
		this->scrollMode = false;
	}
}
/*************************************************************************
* Function name: isNewGuess
* The Input: guess coords
* The output: true if this coordinates were never tried before
* The Function operation: checks if this coordinates were never tried before
*************************************************************************/
bool ComputerPlayer::isNewGuess(const Coordinates candidate) {
	std::vector<Coordinates>::iterator oldGuess;

	// Check if the guess was made already
	for (oldGuess = oldGuesses.begin(); oldGuess != oldGuesses.end(); ++oldGuess) {
		if (oldGuess->getX() == candidate.getX() &&
				oldGuess->getY() == candidate.getY()) {
			return false;
		}
	}
	return true;
}
/*************************************************************************
* Function name: pushNeighbours
* The Input: guess coords
* The output: -
* The Function operation: saves all the neighbour coordinates of this guess
* 							to be guessed later (to reveal the hit ship)
*************************************************************************/
void ComputerPlayer::pushNeighbours(Coordinates& guess) {
	// Go down
	Coordinates candidate = Coordinates(guess.getX() + 1, guess.getY());
	if (isNewGuess(candidate) && candidate.getX() < BOARD_SIZE) {
		futureHits.push(candidate);
	}

	// Go right
	candidate = Coordinates(guess.getX(), guess.getY() + 1);
	if (isNewGuess(candidate) && candidate.getY() < BOARD_SIZE) {
		futureHits.push(candidate);
	}

	// Go up
	candidate = Coordinates(guess.getX() - 1, guess.getY());
	if (isNewGuess(candidate) && candidate.getX() > 0) {
		futureHits.push(candidate);
	}

	// Go left
	candidate = Coordinates(guess.getX(), guess.getY() - 1);
	if (isNewGuess(candidate) && candidate.getY() > 0) {
		futureHits.push(candidate);
	}
}
Exemple #10
0
/**
 * Creates an explosion.
 * @param capsule           The capsule.
 * @param collidingLocation The coordinates of the explosion.
 * @param velocity          Velocity of the explosion, if wanted.
 */
void Projectile::explode( const BodyProjectile &capsule,
                          const Coordinates &collidingLocation,
                          const Vector *velocity )
{
	
	//Create an explosion and put it into the world.
	BodyExplosion *explosionBody = new BodyExplosion(capsule.getWorld(),
	                                                 collidingLocation.getX(),
	                                                 collidingLocation.getY(),
	                                                 this->explosionIndex);
	                                                  
	explosionBody->setActionFlag( capsule.getActionFlag() );
	capsule.getWorld().addBody( *explosionBody );
	if ( velocity ) {
		explosionBody->setVelocity( velocity->getX(), velocity->getY() );
	}
	
}
Exemple #11
0
// move the mouse according to the movement of the point within the box
void Box::moveMouse(Coordinates point){
	float sectorWidth;
	float sectorHeight;
	
	sectorWidth  = (float)(xMax - xCenter) / 4.0;
	sectorHeight = (float)(yMax - yCenter) / 4.0;
	
	Mouse.begin();
	  // X motion
	if (point.getX() > (float)xMax - sectorWidth)             // fast right tracking
		Mouse.move(3,0,0);
	else if (point.getX() < (float)xMin + sectorWidth)        // fast left tracking
		Mouse.move(-3,0,0);
	else if (point.getX() > (float)xMax - 2.0 * sectorWidth)  // medium right tracking
		Mouse.move(2,0,0);
	else if (point.getX() < (float)xMin + 2.0 * sectorWidth)  // medium left tracking
		Mouse.move(-2,0,0);
	else if (point.getX() > (float)xMax - 3.0 * sectorWidth)  // slow right tracking
		Mouse.move(1,0,0);
	else if (point.getX() < (float)xMin + 3.0 * sectorWidth)  // slow left tracking
		Mouse.move(-1,0,0);
    
	// Y motion
	if (point.getY() > (float)yMax - sectorHeight)            // fast right tracking
		Mouse.move(0,3,0);
	else if (point.getY() < (float)yMin +       sectorHeight) // fast left tracking
		Mouse.move(0,-3,0);
	else if (point.getY() > (float)yMax - 2.0 * sectorHeight) // medium right tracking
		Mouse.move(0,2,0);
	else if (point.getY() < (float)yMin + 2.0 * sectorHeight) // medium left tracking
		Mouse.move(0,-2,0);
	else if (point.getY() > (float)yMax - 3.0 * sectorHeight) // slow right tracking
		Mouse.move(0,1,0);
	else if (point.getY() < (float)yMin + 3.0 * sectorHeight) // slow left tracking
		Mouse.move(0,-1,0);
	Mouse.end();
}
/*************************************************************************
* Function name: isAt
* The Input: coordinates to search for
* The output: whether or not the block is on the spec. coordinates
* The Function operation: tells if the block is on the spec. coordinates
*************************************************************************/
bool Block::isAt(const Coordinates coords) {
	return (x == coords.getX() &&
			y == coords.getY());
}
Exemple #13
0
//------------------------------------------------------------------------------
int Game::singleMove(Coordinates& tmp_pos, Coordinates& go_to,
    vector <Coordinates>& bonus_list, string go_to_str, int& bonus)
{
  int enter_code = 0;
  bool turn_is_over = false;
  
  // if game already finished or no more turns left => invalid move
  if (finished_)
  {
    return -1; //invalid move
  }
  
  while(turn_is_over == false)
  {
    int nxt_field_code = calculateNextField(tmp_pos, go_to, go_to_str);
    
    // if next field is valid but not the exit portal of a teleport field
    if (nxt_field_code == 0)
    {
      int x_tmp = tmp_pos.getX();
      int y_tmp = tmp_pos.getY();
      
      // check if we can leave the field in the desired direction
      bool can_leave = board_->at(y_tmp).at(x_tmp)->isAbleToLeave(&go_to);
      if (can_leave == false)
      {
        return -1; //invalid move
      }
      
      string entering_from;
      int go_x = go_to.getX();
      int go_y = go_to.getY();
      
      // check if we can enter the next field in the desired direction
      bool can_enter = board_->at(go_y).at(go_x)->isAbleToEnter(&tmp_pos,
          entering_from);
      if ((can_enter == false) && (enter_code != 1))
      {
        return -1; //invalid move
      }
      
      // If enter_code is 1, we previously entered an ice field which we now
      // leave again. Move should still be valid when leaving an ice field
      // to a field which can't be entered (stop in front of field which
      // can't be entered)
      else if ((can_enter == false) && (enter_code == 1))
      {
        turn_is_over = true;
        go_to = tmp_pos;
      }
      
      
      enter_code = board_->at(go_y).at(go_x)->enter(entering_from, bonus);
      turn_is_over = board_->at(go_y).at(go_x)->isTurnOver(go_to_str);
      
      if (bonus > 0)
      {
        Coordinates found_bonus(go_x, go_y);
        bonus_list.push_back(found_bonus);
      }
    }
    
    // if next field is a exit portal of a teleport field
    else if (nxt_field_code == 1)
    {
      // prevents from endlessly jumping between portals
      turn_is_over = true;
    }
    
    // single move has been successful. Update new temporary position
    tmp_pos = go_to;
  }
  
  return 0; // All OK
}
Exemple #14
0
	Node::Node(const Coordinates& coordinates)
	 :	Node(coordinates.getX(), coordinates.getY())
	{}
	Coordinates Coordinates::operator+(const Coordinates& rhs) const
	{
		return Coordinates(getX() + rhs.getX(), getY() + rhs.getY());
	}
	bool Coordinates::operator==(const Coordinates& rhs)
	{
		return (getX() == rhs.getX() && getY() == rhs.getY());
	}
Exemple #17
0
Point::Point(const Coordinates<double> & coords) :
		x(coords.getX()), y(coords.getY()), z(coords.getZ()) {

}
Exemple #18
0
void Box::calibrate(Driver dr,byte targetR, byte targetG, byte targetB,
					byte rTolerance, byte gTolerance, byte bTolerance){
	Serial.println("In calibrate");
	Serial.flush();
	int currentXMax = 0;
	int currentYMax = 0;
	int currentXMin = 10000;
	int currentYMin = 10000;
	Coordinates current;
	int i = 0;
	int t = 0; // debugging
	// reads 100 frames to find the min and max y/y values for the calibrated box
	while(i<20){
		/*t++;
		if (t%100 == 0){
			Serial.print("Reading: ");
			Serial.println(t);
			Serial.flush();
		}*/
		//dr.read();
		if (dr.isImageComplete()){
			Serial.println("Frame complete. Extracting image.");
			Serial.flush();
			i++;
			
			/*bool frameTest = dr.getFrame().testFrame();
			if (frameTest)
				Serial.println("Frame successfully constructed");
			else
				Serial.println("Frame incomplete");
			*/
			current = dr.getFrame().locate(targetR, targetG, targetB, rTolerance, gTolerance, bTolerance);
			Serial.print("X: ");
			Serial.print(current.getX());
			Serial.print("   ");
			Serial.print("Y: ");
			Serial.println(current.getY());
			Serial.flush();
			if (current.getX() > currentXMax)
				currentXMax = current.getX();
				
			if (current.getY() > currentYMax)
				currentYMax = current.getY();
			
			if (current.getX() < currentXMin)
				currentXMin = current.getX();
			
			if (current.getY() < currentYMin)
				currentYMin = current.getY();
		}
		// now we have collected the max/min values so we build this box
		int xDiff = currentXMax - currentXMin;
		int yDiff = currentYMax - currentYMin;
		
		xCenter = currentXMin + xDiff / 2;
		yCenter = currentYMin + yDiff / 2;

		xMax = currentXMax;
		yMax = currentYMax;
		xMin = currentXMin;
		yMin = currentYMin;
		
	}
	Serial.println("Calibration complete, ready to activate mouse.");
	Serial.flush();
}