How to get the AI adapt to the matchup

Started by imbalisk, March 03, 2010, 04:45:56 PM

Previous topic - Next topic

imbalisk

Hey guys.


I've been playing SC1 since 2004 and I'm also interested in coding, so lets see if I can help the coders with some cool scripts to improve the AI :)


In Starcraft 1 I choose my build order or general gameplan based on the situation: is it a 1v1 or a 3v3? Or even a FFA?
When its a 1v1, what race I am playing against?
Wouldn't it be cool if the AI make the same decisions like a REAL (clever) player?
Here is the script:


First of all, we want to know how many players are in the game. I've tried AIGetNumEnemies (player); but it didn't work (returned a constant 13 no matter how much players are in). Here is the code of a working AI that analyze the game situation:



static void ProtossInit (int player) {
        ...   
   int numberOfPlayers = 0;
   string s = null;
   int i = 1;
   int enemyID;
   
   // Counting the players   
   while(i<=8){ // Asuming that blizzard has a maximum of 8 players
      s = PlayerRace(i); // getting a "Terr", "Zerg", "Prot" if this ID is used
      if(s != null) {  // otherwise a null if there is no player
          numberOfPlayers = numberOfPlayers + 1;
      }
      i = i + 1;
   }
   if(numberOfPlayers == 2) {
          // Lets find out our opponents playerID. It can't be our ID:
      if(player == 1) { // is my ID == 1?
         enemyID = 2;
      }
      else { // ok, my ID is 2
         enemyID = 1;
      }
      TriggerDebugOutput(1, StringToText("1v1 Mode vs " + PlayerRace(enemyID) ), true);
                 // add a state setting code here
                 // example: state = e_mainState_OpenGnd0; if you want to execute the ProtossOpenGnd0
   }
   else {
      TriggerDebugOutput(1, StringToText("FFA Mode vs " +               IntToString(numberOfPlayers-1)), true);

                // add a state setting code here
                // example: state = e_mainState_OpenGnd1; whatever
   }

Lets say AI is protoss and this script tells him that are 2 players in the game (1v1 baby) and PlayerRace(enemyID) == "Terr".
We can choose an opening that is good against Terran, lets say a Stalker into Immortal build.
If it's a FFA we could ajust our build so that if the AI is attacking, we make some defense, cause nobody likes an attack from player 3 when we attack player 2. Well thats what happens in FFA :)


Hope that helps a little bit, pls give me credit if you use that in your own AI.
- imbalisk
edit:
thx @ sYkO for providing this nice 1v1 obsmaps

itsarabbit

I believe most of them don't use c++(or is that just an extremely similar language?), but if it's possible to implement it, it might prove useful :)
Want Beta key! :D

imbalisk

Quote from: itsarabbit on March 03, 2010, 05:10:36 PM
I believe most of them don't use c++(or is that just an extremely similar language?), but if it's possible to implement it, it might prove useful :)
This is written in the galaxy language

hd

my ai already takes opponents race into account, though i wasn't aware of PlayerRace(int player) and as a result built bloated and convoluted functions to find the enemy race ;\

cvax

#4
Where did you get that map? Found it

Kernel64

Quote from: hd on March 03, 2010, 08:50:55 PM
my ai already takes opponents race into account, though i wasn't aware of PlayerRace(int player) and as a result built bloated and convoluted functions to find the enemy race ;\

I'd love to know more of these functions as well. The guy who released that Protoss AI clearly knows something. I wish he/she would document some of the functions.