Esempio n. 1
0
bool AI::checkNode(vector<vector<int>> tempBoard, vector<Piece> teamCopy, vector<Piece> enemyTeamCopy, Directions direction, bool enemy){
    int x, y;
    int teamNumber = TEAM_NUMBER;
    int enemyTeamNumber = ENEMY_TEAM_NUMBER;

    if (enemy) {
        x = enemyTeamCopy[enemyCurrentIndex].x;
        y = enemyTeamCopy[enemyCurrentIndex].y;
        teamNumber = ENEMY_TEAM_NUMBER;
        enemyTeamNumber = TEAM_NUMBER;
    }
    else{
        x = teamCopy[currentIndex].x;
        y = teamCopy[currentIndex].y;
    }

    // Makes sure the changed x & y values are applied (Just incase)
    if(!changeWithDirection(x , y, direction, enemy)){
        return false;
    }

    // Team piece in the way
    if(sameTeam(tempBoard[x][y], teamNumber)){
        return false;
    }

    // Enemy might be unkillable
    if(sameTeam(tempBoard[x][y], enemyTeamNumber)){
        return killCheckArea(tempBoard, x, y, direction, enemy);
    }

    return true;
}
Esempio n. 2
0
void DaktaklakpakVivisector::inflict_damage(SpaceObject *other)
{
  if (drillFrames > 0)
    if (!latched)
      if ((!(sameTeam(other))) &&
        (other->isShip())) {
          latched=TRUE;
          grabbed= (Ship *) other;
          grabangle= (trajectory_angle(other) );
          grabdistance = (distance(other) * 1.1);
          grabshipangle = (other->get_angle());
          drillDamageLeft = weaponDamage;
          play_sound2(data->sampleExtra[1]);
          if ((drillFrames / frame_time)< weaponDamage) {
            drillDamagePerDamageFrame = (weaponDamage/drillFrames)
              + ((weaponDamage % drillFrames) > 0.00001);
            damageFrameLeft = 1;
            damageFrameAmount = 1;
          } else {
            damageFrameAmount = (drillFrames/weaponDamage);
            damageFrameLeft = damageFrameAmount;
            drillDamagePerDamageFrame = 1;
            }
    }
  Ship::inflict_damage(other);
}
Esempio n. 3
0
void TeronDroneLaser::inflict_damage( SpaceObject* other )
{
	STACKTRACE;
	Laser::inflict_damage( other );
	if ( !other->isShip() && sameTeam( other )) {
		//other->repair++;
		//other->handle_damage( this );
		other->handle_damage( this, -1 );
	}
	if ( other->isAsteroid() ) collecting = other;
}
Esempio n. 4
0
void AI::getEnemyTeam(){
    enemyTeam.clear();
    for(int x=0;x<8;x++){
        for(int y=0;y<8;y++){
            if (sameTeam(Board->virtualBoard[x][y],ENEMY_TEAM_NUMBER)) {
                enemyTeam.push_back(Piece());
                if (Board->virtualBoard[x][y] == ENEMY_TEAM_NUMBER+2){
                    enemyTeam.back().makeKing();
                }
                enemyTeam.back().x = x;
                enemyTeam.back().y = y;
            }
        }
    }
}
Esempio n. 5
0
void AI::updateTeam(vector<vector<int>> &tempBoard, vector<Piece> &teamCopy, bool enemy) {
    // Updates team when team.size() has been altered
    int teamNumber = TEAM_NUMBER;

    if (enemy) {
        teamNumber = ENEMY_TEAM_NUMBER;
    }

    for(int index=0;index<teamCopy.size();index++){
        if (!sameTeam(tempBoard[teamCopy[index].x][teamCopy[index].y], teamNumber)) {
            teamCopy.erase(teamCopy.begin()+index);
            index--;
        }
    }
}
Esempio n. 6
0
void Game::update()
{
  addWonCards( currentTrick->getLeader()->name, currentTrick->getAllCards() );

  // if the Fool has been played, decide who must keep it.
  if( currentTrick->getFoolPlayer() != nullptr 
      && 
      !sameTeam(currentTrick->getFoolPlayer(), currentTrick->getLeader() ) )
  {
    toSwap = true;
    foolGiver = currentTrick->getLeader();
    foolReceiver = currentTrick->getFoolPlayer();
  }

  setNext( currentTrick->getLeader() );
  //currentTrick->getLeader()->score = currentTrick->getScore();
  history.push( currentTrick );
}
Esempio n. 7
0
bool AI::makeMove(SDL_Event *event){

    // Init enemyTeam that this class can use
    getEnemyTeam();

    for(int index=0;index<team.size();index++){
        currentIndex = index;

        team[index].directionValues[0] = maxValue(Board->virtualBoard, team, enemyTeam, MAX_DEPTH, LEFT);
        team[index].directionValues[1] = maxValue(Board->virtualBoard, team, enemyTeam, MAX_DEPTH, RIGHT);

        if (team[index].isKing()) {
            team[index].directionValues[3] = maxValue(Board->virtualBoard, team, enemyTeam, MAX_DEPTH, BACK_RIGHT);
            team[index].directionValues[2] = maxValue(Board->virtualBoard, team, enemyTeam, MAX_DEPTH, BACK_LEFT);
        }
        cout<<"Index: "<<index<<" ("<< team[index].x << "," << team[index].y;
        cout<<") Left: "<<team[index].directionValues[0]<<" Right: "<<team[index].directionValues[1];
        cout<<" bLeft: "<<team[index].directionValues[2]<<" bRight: "<<team[index].directionValues[3]<<endl;

        team[index].findBestDirection();
        team[index].findLargestPotenial();
    }

    int bestPieceIndex = bestPiece(team);
    cout<< "The chosen one: " << bestPieceIndex << " -> ("<< team[bestPieceIndex].x << "," << team[bestPieceIndex].y;

    int x = team[bestPieceIndex].x;
    int y = team[bestPieceIndex].y;

    // Makes sure the move isnt out of bounds //
    if (team[bestPieceIndex].potential != OUT_OF_BOUND) {

        changeWithDirection(x, y, team[bestPieceIndex].bestDirection, false);

        if(sameTeam(Board->virtualBoard[x][y],ENEMY_TEAM_NUMBER)){
            // Changes it again for moving 2 units diagonally //
            changeWithDirection(x, y, team[bestPieceIndex].bestDirection, false);
        }
        cout<<") best move: (" << x << "," << y <<")"<< endl;
        movePiece(Board->virtualBoard, team, bestPieceIndex, x, y);
        return true;
    }
    return false;
}
Esempio n. 8
0
int AI::minValue(vector<vector<int>> tempBoard, vector<Piece> teamCopy, vector<Piece> enemyTeamCopy, int depth, Directions direction){

    bool killMove = false;

    if(!checkNode(tempBoard, teamCopy, enemyTeamCopy, direction, true)){
        return OUT_OF_BOUND;
    }

    int x = enemyTeamCopy[enemyCurrentIndex].x;
    int y = enemyTeamCopy[enemyCurrentIndex].y;

    changeWithDirection(x, y, direction, true);
    if(sameTeam(tempBoard[x][y],TEAM_NUMBER)){
        if(!killCheckArea(tempBoard, x, y, direction, true)){
            return OUT_OF_BOUND;
        }
        else{
            changeWithDirection(x, y, direction, true);
            killMove = true;
        }
    }

    //This should move on the tempBoard
    movePiece(tempBoard, enemyTeamCopy, enemyCurrentIndex, x, y);
    updateKings(tempBoard, enemyTeamCopy, true);
    if (killMove) {
        updateTeam(tempBoard, teamCopy, false);
        if (teamCopy.size()<=0) {
            //smallest number
            return -1 * WIN_VALUE;
        }
    }

    if (depth <= 0) {
        return valueCalculator(teamCopy, enemyTeamCopy);
    }
    else{
        return maxMove(tempBoard, teamCopy, enemyTeamCopy, depth-1);
    }

}