[How do I] Programming enemy players

0 favourites
  • 5 posts
From the Asset Store
Player's Follower
$7 USD
30% off
Players follower. use it for anything which follows the player
  • Hi, had pretty speedy results last time i posted here so I'm gonna make use of the community more often, I'm building a game, it's essentially M.U.L.E. (for those of you that know the game) but customized to specifically reflect the town in which we live, anyway, most aspects are running smoothly and are relatively easy to program, what i am struggling with, mainly because of the absence of the other programmer, I'm left to teach myself how to get the enemy players to do what they need to do each turn alongside the player, I've programmed enemies in other games that simply attack the player or chase the player whilst firing at them, I've also done classic platform enemy movements, but this is different to anything i have experience with, essentially the turns go like this:

    -players take turns to choose a plot of land

    -player, and enemies, then go and fetch "mule" and choose which resource it will carry

    -players then take their chosen "mule" to their plot of land where the "mule" will produce the chosen resource

    -players then go and end their turns by going to the pub, where the remaining time is converted into a reward for the players

    -next the players' plots of land produce resources the players can use in the next stage of the turn

    -the players now head into the commerce stage, where each players can sell excess and buy needed resources to each other

    -at the end of the commerce stage random events trigger that can both benefit and hinder the players

    -The turn then ends and the sequence starts again beginning with plot choice

    what i need help with is programming the enemy players so that each turn they choose their land and buy their resources and participate in the auctions, now, it's easy enough to make them do this stuff in sequence, what i dont know how I'm going to do, is get the enemies doing this by their own choice sort of thing, a reeeeally primitive AI, so they buy relevant resources when they need them and to sell or buy resources intelligently, this is essential because if the enemies just do the same thing every turn, the player will face no challenge and after playing the game once, they'll know what is coming every time and therefore would have no interest in playing a second time, and obviously, as game designers pouring our time and effort into building a game, we want people to enjoy our game enough to play again and again, any help will be greatly appreciated, thank you.

  • Your question is a pretty complex one to answer, because there are numerous ways to implement AI and in general its not easy to make. So I doubt you will get any "this is how you do it" solutions.

    But a way to get you started, you can think about it like this. This is just an example based on what you write you would like in the game and how I would approach it.

    You could give each AI a personality, which is basically just a lot of stats that will govern how they tend to react. Since i don't really know what your game is about, but understand that it have something to do with buying resources and land. You could give them some stats called Trading and Expanding for instance, where an AI with high Trading might prefer buying resources over land. Since you don't want to risk the AI keep trading forever. You would have to take currently owned resources into consideration as well. So you could check versus these as well and make it so an AI with a high Trading stat, prefer having a bigger stockpile than one that prefer buying land. However if the prices of resources changes these have to be taken into account as well, as it would be poor AI if they just buy resources regardless of price and need. So what you could do is to add a "Max buying price" to each AI and as their stockpile gets lower and start to need a certain resource they will also be willing to pay more for it, and then you could add their current amount of money into it as well as it might not be good for an AI to spend all their money on resources.

    So you can keep expanding on this depending on how complex you want the AI to be, for instant they could take player actions into account or the players current resources and buy up those that the player seem to need to simply push them and so forth.

    But again there is not really a simple solution, but what you will most likely end of with in the end is some sort of state machine that is used differently by each AI depending on their stats, preferences, needs and whatever you think is important.

  • expanding on ninos personality build i would add a sort of needs order/preference depending on the goals of your game (kind of like a rts ai order to build in) which if its a very open ended type of choices you could add heavy random with a global variable+floor(random(x,x)) with an event that sub events with each number you want to check condition system-between values-global var lower bound 1 upper bound 2-action result and then repeat for each number roll possibility with a new sub event

    otherwise if its specific with personality in mind you can have a 50/50 roll that uses a number random as well as takes their specific traits into account (in order to have them act closely to a strategic playout with higher randomness) if 50 or below and trading is greater than expanding conditions subbed to the roll as well as the greater than and 2 for expanding greater than as well (at that rate id have a reroll function or 1 point random bumb to trading and expanding in case they level) this would basically give them 4 choice options or even more with a build order/needs order

    id also make a check to see what each ai is lacking and requires the most as part of the build/takes into account the auction house pricings to determine its best course of current action and then after deciding what its after rolls off of the 2nd set up in a list for each need meaning id have 8 lists with 4 options per personality amounting to 320 options per turn with 10 personalities and 8 resources

  • I was expecting difficulty, given the specifics of the build i didn't think anyone would be able to give a "do this that and this" answer, i was expecting replies like these, that give me the general idea and i'd have to build on top, which is what i've gotten, it still seems like a daunting aspect, but i'm pretty sure i understand what i've gotta do now, at least enough to get started, currently im experimenting with pathfinding to control the movements of a character based on two stats (taste&inventory) at the start of the layout taste is designated 0 or 1 and the character chooses its food based on that number, when the inventory reaches its capacity, the character heads back to his starting point, i started this test out after reading the initial response from nimos, using a crude stat system to give the character its motive, i'm going to continue to build upon this and the other tips and info from both replies, thank you both for the help so far, i at least have an idea of how to move forward with this now.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • i would need to know more for specifics on the pathfinding sort if you need halp with that but if you mean ai difficulty level you can use what i previously said and when player selects the difficulty level you set the min max of the random to be within the fields of how intelligent aggresive or effective they are probably based on the AH stats since that would impact their chosen results the most (lower bound rolls poor higher bound rolls strong using between values instead of straight greater than and less than compares)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)