Announcement

Collapse
No announcement yet.

Terrorist Trigger

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Terrorist Trigger

    Hi all;

    Well I think I have settled on a formula for terrorism that I am happy with. I was basing the eqns on a players score vs the average but then as the average score climbed climbed I found the gap between the leader (invariable me) and the average needed to get stupid large before terrorism took place.

    So the eqn I settled on has nothing to do with actual score but with ratios of scores.
    For example if the scores are:
    1x 2x 3x 4x 5x 6x 7x 8x then the number of terror strikes will be the same no matter how big x might be.

    In addition I have included a factor of how popular the target is. If everyone in the world (or at least those with lower scores) love you then you will not suffer any strikes. The number of strikes in my spreadsheets can climb as high as 12 if your score is 60% of the total and everyone is at war with you.

    The code follows but I have NOT TESTED this yet. I am particularly leary about the RegardLevel function and how things will pan out in the early game when scores are very low, but I'll let everyone know how the testing goes. If any are adventurous then feel free:

    //Trigger Setup
    trigger 'Setup' when ((g.player == 0) && (g.year == 0)) {
    // This is the value from userprofile.txt that details the number of players that STARTED the game.
    // This may of course be very different from the number currently in the game.
    numberOfPlayers = Preference("NumPlayers");
    // note the 196 is the map bonus for the gigantic map and I have not figured out the right values for other sized maps.
    // If smalled map sizes are used without updating this value it will cause fewer strikes and cause funny stuff as the scores rise.
    scoreBonus = g.maxscore - 3600 + (75 * numberOfPlayers) + 196;
    }

    messagebox 'PopTerrorized' {
    // POP_TERRORIZED defined in info_str.txt reads like:
    // POP_TERRORIZED "Foreign backed terrorists strike in [city.1.name]. Casualties are high."
    Text(ID_POP_TERRORIZED);
    MessageType("WARNING");
    }

    trigger 'AveScoreEff' when (g.player >= 0) {
    // Player = 0 is the Barbarian who does not suffer from terrorist attacks
    // but we still need the total score
    if (g.player == 0) {
    totalScore = 0;
    index = 1;
    while (index < Preference("NumPlayers")) {
    if (IsPlayerAlive(index) == 1) {
    SetPlayer(1,index);
    totalScore = totalScore + player.1.score - scoreBonus;
    }
    index = index + 1;
    }
    totalScoreSqd = totalScore * totalScore;
    } else {
    SetPlayer(1,g.player);
    strikes = 0;
    index = 1;
    // The following is the sum for each enemy still alive and with a lower score than me:
    // Regard(enemy towards me) * (myScore/enemyScore -1) * enemyScore/totalScore * myScore/totalScore
    // = his opinion of me * how much I am beating him by * how strong he is * how strong I am
    // = 1/totalScore^2 * SUM ( Regard * myScore * (myScore - enemyScore) )
    while (index < numberOfPlayers) {
    SetPlayer(2,index);
    // this enemy must be alive and have a lower score to make terrorist strikes.
    if ((IsPlayerAlive(index) == 1) && (player.1.score > player.2.score)) {
    myScore = player.1.score - scoreBonus;
    enemyScore = player.2.score - scoreBonus;
    strikes = strikes + RegardLevel(index,g.player) * myScore * (myScore - enemyScore);
    }
    index = index +1;
    }
    // This division is deferred til now for speed and accuracy from rounding errors.
    strikes = strikes / totalScoreSqd;

    // Now resolve all the strikes.
    // Note that CityCount > 0 is not the same as IsPlayerAlive. Consider turn 0.
    // The chances that a terrorist strike kills a civ's last city is small but not nil
    cityCount = Cities (g.player);
    while ((strikes > 0) && (cityCount > 0)) {
    destCity = Random (cityCount);
    SetCityByIndex(1,g.player,destCity);
    // Always message BEFORE reducing pop since it might destroy the city
    Message(g.player, 'PopTerrorized');
    AddPops(city.1, -1);
    cityCount = Cities (g.player);
    strikes = strikes - 1;
    }
    }
    }
    }


    Gedrin
    [This message has been edited by Gedrin (edited October 20, 2000).]

  • #2
    One more thing with respect to playing with more or less than 8 players.

    my spreadsheets are indicating that with 8 players if your score represents 30% of the total then you will start to get hits.

    *sigh* I could do a great deal of math here but sufice to say that you will start getting hits when you have 3 times the average.

    I think my play balance testing will result in replacing the line:
    strikes = strikes / totalScoreSqd;
    with:
    strikes = (numberOfPlayers*strikes) / (3*totalScoreSqd);

    to make strikes start sooner and not be affected by 16 or 32 player games... but I need to check my math on this one.

    Gedrin

    Comment


    • #3
      Hi All;

      Well I have no idea whether anyone out there is actually following this but I did some testing this weekend and found a problem in my formula... which frankly I should have seen before.

      The principle parts of this formula are:
      (m^2-m*e)/t^2
      Which gives nice curves for reasonable values of m and e but I forgot to consider limits. Specifically the limit as e -> 0 which happens when you try and wipe out a civ (or the barbarians get them). Well it happened and the number of strikes hit m^2 and every civ in the world got rocked... royally. Ooops

      So I revised the formula to:
      // Regard(enemy towards me) * (myScore/enemyScore -1) * (enemyScore/totalScore)^2
      // = his opinion of me * how strong I am compared to him * how strong he is
      // = 1/totalScore^2 * SUM ( Regard * enemyScore * (myScore - enemyScore) )

      And this time I plotted the surface with XL and noted no harsh local extremes. This has much nicer behavior when as limit e -> 0 = 0 and also the limit m -> inf*e = 1/m instead of m^2 so when you are the undisputed ruler of the world you don't get terrorist strikes either. (By inf*e I mean m is infinitely larger than e... I know it's not a realistic notation )

      I also considered
      // Regard(enemy towards me) * (myScore/enemyScore -1) * (enemyScore/totalScore)^2 * (myScore/totalScore)^2

      but this resulted in far too slow a growth as limit e -> m/2 which is the maximum.

      I also noted that the curves on the power graph only include those numbers that reduce to 0 when you loose all your cities. While I could not figure out how to remove the number of years at peace from the player.score value, removing the number of player.discoveries is simple. I left the Wonders in since you have no wonders when you loose the last city.

      So the new and improved terrorist trigger is below:
      The number of strikes this results in are theoretically good. (ie I have confirmed via XL that the formuala produce good numbers for all numbers of players. Generally speaking strikes should start when your score is 50% more than the average but that varies greatly on who gets angry at you. The biggest threat is the civ who hates you and has 1/2 your score. If you annoy all the strong civs you should be ok but if you annoy the weak ones then you better go squash them.

      Oh and lastly I decided to MessageAll since it was handy for testing and then I saw no reason not to.

      Gedrin


      trigger 'AveScoreEff' when ((g.player >= 0) && (g.year > 10)) {
      // Player = 0 is the Barbarian who does not suffer from terrorist attacks
      // but we still need the total score since ave = total/number
      if (g.player == 0) {
      totalScore = 0;
      index = 1;
      while (index < Preference("NumPlayers")) {
      if (IsPlayerAlive(index) == 1) {
      SetPlayer(1,index);
      totalScore = totalScore + player.1.score - 15*player.1.discoveries - scoreBonus;
      }
      index = index + 1;
      }
      } else {
      SetPlayer(1,g.player);
      strikes = 0;
      myScore = player.1.score - 15*player.1.discoveries - scoreBonus;
      enemyScore = player.2.score - 15*player.2.discoveries - scoreBonus;
      // The following is the sum for each enemy still alive and with a lower score than me:
      // Regard(enemy towards me) * (myScore/enemyScore -1) * (enemyScore/totalScore)^2
      // = his opinion of me * how strong I am compared to him * how strong he is
      // = 1/totalScore^2 * SUM ( Regard * enemyScore * (myScore - enemyScore) )
      index = 1;
      while (index < numberOfPlayers) {
      SetPlayer(2,index);
      // this enemy must be alive and have a lower score to make terrorist strikes.
      if ((IsPlayerAlive(index) == 1) && (myScore > enemyScore)) {
      strikes = strikes+(5-RegardLevel(index,g.player))*enemyScore*(myScore-enemyScore);
      }
      index = index +1;
      }
      // This division is deferred til now for speed and accuracy from rounding errors.
      strikes = (numberOfPlayers*strikes) / (totalScore*totalScore);

      // Now resolve all the strikes.
      // Note that CityCount > 0 is not the same as IsPlayerAlive. Consider turn 0.
      // The chances that a terrorist strike kills a civ's last city is small but not nil
      cityCount = Cities (g.player);
      while ((strikes > 0) && (cityCount > 0)) {
      destCity = Random (cityCount);
      SetCityByIndex(1,g.player,destCity);
      // Always message BEFORE reducing pop since it might destroy the city
      MessageAll('PopTerrorized');
      AddPops(city.1, -1);
      cityCount = Cities (g.player);
      strikes = strikes - 1;
      }
      }
      }
      }


      Comment


      • #4
        Once again further testing has shown a mistake.

        This time it was in my spreadsheet I used to justify the line:
        strikes = (numberOfPlayers*strikes) / (totalScore*totalScore);

        Since the number of terrorists increases as the number of players these two combine to introduce a factor of numberOfPlayers^2

        So I corrected my spreadsheet and found out why in my 8 players games I get royally screwed when I've only got about 20% of the total score.
        So the correction to:
        strikes = (5*strikes) / (totalScore*totalScore);
        keeps the strikes high enough without spelling doom.

        So with every civ holding you in neutral regard this will cause the following number of strikes:

        numberOf Targets Score as % of Total
        Players 0.4 0.5 0.6 0.7
        1 #DIV/0! #DIV/0! #DIV/0! #DIV/0!
        2 0.00 0.00 1.20 1.80
        3 0.90 1.88 2.40 2.48
        4 1.80 2.50 2.80 2.70
        5 2.25 2.81 3.00 2.81
        6 2.52 3.00 3.12 2.88
        7 2.70 3.13 3.20 2.93
        8 2.83 3.21 3.26 2.96
        9 2.93 3.28 3.30 2.98
        10 3.00 3.33 3.33 3.00
        11 3.06 3.38 3.36 3.02
        12 3.11 3.41 3.38 3.03
        13 3.15 3.44 3.40 3.04
        14 3.18 3.46 3.42 3.05
        15 3.21 3.48 3.43 3.05
        16 3.24 3.50 3.44 3.06
        17 3.26 3.52 3.45 3.07
        18 3.28 3.53 3.46 3.07
        19 3.30 3.54 3.47 3.08
        20 3.32 3.55 3.47 3.08
        21 3.33 3.56 3.48 3.08
        22 3.34 3.57 3.49 3.09
        23 3.35 3.58 3.49 3.09
        24 3.37 3.59 3.50 3.09
        25 3.38 3.59 3.50 3.09
        26 3.38 3.60 3.50 3.10
        27 3.39 3.61 3.51 3.10
        28 3.40 3.61 3.51 3.10
        29 3.41 3.62 3.51 3.10
        30 3.41 3.62 3.52 3.10
        31 3.42 3.63 3.52 3.11
        32 3.43 3.63 3.52 3.11


        Note also that all civs with whom you have no contact hold you in the same regard as 'love' meaning they do not contribute. Another reason not to build the P. Stone.

        Notice also the strikes you suffer increase with more players and the top of the curve decreases. Which makes sense when I think about it.

        I think I am finally done my terrorist trigger.

        Gedrin
        [This message has been edited by Gedrin (edited October 27, 2000).]
        [This message has been edited by Gedrin (edited October 27, 2000).]

        Comment


        • #5
          Well, I for one am following this Gedrin, and I must say it's very exciting This could drasticly the game and I will definitely give this a try as soon as I get the oppurtunity.
          I especially like how this trigger promotes players to be more peaceful and have other civs like them (CtP is way too war-centred as it is, IMHO), especially when they're big already. I think that this trigger will make the game more realistic and more challenging at the same time.
          Keep up the good work!
          Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

          Comment


          • #6
            Cool;

            Thanks Locutus.

            This weekend cropped up another bug that I frankly introduced with some over-zelous cut'n'paste effeciency changes:

            You may have noticed that I moved myScore = player.1.score - scoreBonus;
            enemyScore = player.2.score - scoreBonus;
            up out of the while loop since hey, I don't need to calculate myScore n times...
            Yeah well since SetPlayer(2,index) is not yet called the first time player.2 and so enemyScore is random and after that it is the last player... always. No wonder my results made no sense at all.

            I just noticed it now too. Oh well I'll have to start another game.

            I've been toying with another idea too.

            I have set the factors in diffDB for all those things I cannot determine to 0. Just to get them out of the eqn. Seemed to work but since I just noticed this logic flaw above I have no idea if it matters.
            IE years of peace, units lost, riots, revolutions...

            I think I should go back to the painters principle on my triggers so I don't look like a bubling idiot. |)
            You know... no one sees it til its finished.

            Gedrin



            [This message has been edited by Gedrin (edited October 30, 2000).]

            Comment


            • #7
              Haha. Well, if it's any comfort to you, I made a fool out of myself with buggy code at numerous occasions as well
              Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

              Comment

              Working...
              X