September 9th, 2012, 15:44
Posts: 476
Threads: 22
Joined: Apr 2011
How should the AI interface look like?
In special, should this be late-bound?
September 12th, 2012, 20:36
(This post was last modified: September 12th, 2012, 21:04 by WhiteMage.)
Posts: 634
Threads: 13
Joined: Nov 2010
I try to stay on the interface issue, but it overlaps others, so here I go:
AI should be completely independent from game and it should be possible to code it in any language. The principle should be similar to C-Evo, where AI can be selected and placed to play certain sides. AI will not cheat and will have the exact same set of options to choose from as any human player. That means no restrictions either. AI's knowledge will be incomplete, so it will not know where the cities are, what the next random number will be, or what happened on the other side of the map, which it has not discovered yet, for example.
AI development should be allowed to be done in any different ways, such as rule based, expert system based, machine learning based, evolutionary computation based, search based, heuristics based, planning based, Bayesian, agent based, etc. So the interface between AI and the rest of the game should not limit the AI in any way. Determination of how much time to spend on a decision will be up to the AI. If the game will have time limit per turn and the AI violates it, then the AI has to suffer the consequences (not the game).
I see 3 levels of AI for reMOM. Level 1 is human user assisting AI, which includes various Pathfinding algorithms optimized for different objectives, such as speed, safety, exploration, avoiding detection, etc. This level will also include routines such as Grand Vizier to optimize tax collection, building orders, creating battle formations, etc.
The level 2 AI is the battle AI. When called, this module receives a minimal set of knowledge and objectives from the level 3 AI, at the start of a battle, such as the importance of the battle, desired objectives from the level 3 AI, such as trying to survive, trying to cause maximum damage to enemy, trying to preserve mana, trying to drain enemy mana, fight to the last breath, etc. Then it carries out the entire battle based on its own complex decisions. Once the battle is finished, this module releases control and gives it back to the level 3 AI, who may create some post assessment data for the level 2 AI, which can be used for learning in later. The level 2 AI can also be used by human players by selecting it at the beginning of their turns only. This will be valuable for Play by Email type games in the far future.
The level 3 AI is the overland AI, which includes everything else that the level 2 AI does not do. It does everything that level 1 AI does plus more. This includes diplomacy, overland move selection, overland spell casting selection, objective modification, research, production, exploration, personality, emotions, belief on opponent's strength, goals, and trustworthiness, etc.. The level 3 AI maintains a belief system on the current game being played and also on how to play reMOM overall. It will update its belief system as the game progresses. Rules, decisions, etc. are applied to individual game states and subject to the belief system of the AI. In a single turn of the AI player there will be typically hundreds or thousands of game states. Once the level 3 AI goes into battle, it passes control to the level 2 AI. Once a full AI player turn is finished, it saves status of belief and gives control to the next player.
Diplomatic actions are only allowed at the beginning of the turn of each player, which includes the AI and the humans. This will significantly limit abuse and time wasting for all players. Diplomacy will become serious and will aid the AI, as this is a hard part for AI to make correct decisions. Human advantage will be weakened. Player sends and receives diplomatic offers at the beginning of his/her turn. Players are presented with offers at the beginning of their turns. They can accept, reject, and offer a deal. This way the game stays sequential and no need to call up an AI to respond to an offer when it is not the AI's turn. This will also significantly help multiplayer games, so human players can only act in their own turn and makes play by email and hot seat games feasible.
At this point in software development, I strongly recommend that we do not work on level 1 and level 3 AI yet. Most of such work would be wasted. We can work on level 2 AI. Since the original MOM is progressing with the external AI and we focus on the battle AI, perhaps we can attempt to use the same principle and even create AIs which will work for both MOM Insecticide and for reMOM. The coding principles should start from the same roots and depart only when the need rises.
It is very important that the full game state will only be known by the server and the clients will only know as much as they need. Even though this may slow down the game a little due to extra communication, this will make cheating and data corruption much harder by both humans and AIs and will allow tracing of games and competition possible in the far future. AIs therefore always receive game state from the server and not from other client computers, which will also help with debugging. Random numbers can also only be generated and come from the server, not the clients.
Recording a step by step game from beginning to end was solved by C-Evo and is extremely important for both AI tournaments and for eventual popularization of this game. Only recording end of turn snapshots is not sufficient.
To an individual AI wizard, a level 2 and a level 3 AI will be ordered at the start of the game, which should not be changed once the game started. They work and are coded independently. Yet, they may send data to each other. There will be populations of all levels of AI and they can bundle with one another with no restriction. Level 1 AI is for player convenience only and is a simplified version of a mature level 3 AI. Pathfinding, building selection etc. type of decisions maybe coded and tested for level 3 first and copied over to level 1 later.
The communication interface between AI and any other module should be attempted as simple text files, which average humans would be able to learn to understand. The files will contain standard structure, which are parsed by the AI programs (and non-AI programs and humans too). AI (and human player's client) sends an individual move request to the game engine on the server. Server makes the move and sends back the result of the move to the AI (or human's client computer). For simple games, the server is the same as the client.
Eventually, AI programs can run on client computers or on the server, even distributed computing in the cloud if desired. In the far future, AI tournaments, where no humans play will be very important for learning and evolution. AI will rely on statistical methods, which is expected to improve AI's capability.
September 17th, 2012, 04:51
Posts: 20
Threads: 0
Joined: Feb 2012
I don't have the same answer, but I'm not sure we're speaking of the same interface
As a programming contract, the AI Interface should be composed of at least these functions :
- DoMyTurnInBattle(CurrentContext,Ruleset)
- DoMyTurnOverLand(CurrentContext,RuleSet)
- RespondToDiplomacy(CurrentContext,RuleSet)
If we want multithreaded AIS (able to think when it's not their turn), some kind of
- SomethingJustHappened (CurrentContext, RuleSet) would be needed to inform the AI out of his turn that the situation has changed (for example, an enemy unit appeared near one of their cities)
Of course, late-binded, so that AI could be changed/created (as in C-Evo, right)
September 18th, 2012, 09:56
Posts: 634
Threads: 13
Joined: Nov 2010
"RuleSet" should not be an argument of a function. Individual AIs will only be applicable to individual RuleSets. reMOM will have one standard RuleSet (at a time) and the AIs will play under that RuleSet only. Of course in the far-far future once we solved the problems with a single RuleSet and AIs, new RuleSets can be created and the AIs can be modified to play under those (a lot of additional programming and time). So, it is not a good idea to program for this eventually any time soon. Instead, the AI will simply be claimed for users: which version/RuleSet of reMom it is indended for.
Regarding "CurrentContext", it is tricky since it can be either simple game state, which can be passed from the game engine to the AI or it can be game knowledge and goals passed from the level 3 AI to the level 2 AI, such as "try not to lose units in the next battle". So it depends on who the sender and receiver are.
Regarding AIs "able to think when it's not their turn", I think this is a very low priority at this point. First, such (full) knowledge can be passed on in a single message from the server to the AI at the beginning of the AI's turn. So AI (as well as human players) can play back the entire turn like a movie to show them what happened while they were not making their own moves. This gives more complete, more actionable knowledge. I do not worry about AI speed at this early planning stage. It would introduce additional programming needs and minimal if any benefit to AI strength. So it would delay the launch date significantly for both reMOM and AI. By the way, the AI can think in its turn regardless of receiving frequent updates from the server or not. It will be far less efficient than in chess, since reMOM cannot be reduced to a search problem.
September 18th, 2012, 19:44
Posts: 20
Threads: 0
Joined: Feb 2012
WhiteMage Wrote:"RuleSet" should not be an argument of a function By ruleset, I meant things like statistics for units, spells, and so on..
AIs should be able to adapt if the cost for spearmen is modified..
But yes, it should be affected at start, not on each call.
So, one more for the interface
Initialize(RuleSet, StartingContext)
Quote:Regarding "CurrentContext",it is tricky since it can be either simple game state,
In my mind, it was "everything needed for making decisions for the current function". But rather than having the game engine passing the information (more or less directly), maybe the AI could ask the engine for information : some kind of "How many enemy units are near my city"
Quote: So it would delay the launch date significantly for both reMOM and AI.
Not for reMom. If an AI wants be "continuously thinking", it would just have to register as such to reMom, and the game engine would send updates as they are happening, rather that all at once at the end of turn : the additional programming cost, for reMom, is quite small . In fact, for a non-cheating AI, it's exactly the same thing as updating the view for players not currently playing
I'm not saying we should start with this kind of AI, but we should offer the possibilty for anyone wanting to do it.
September 18th, 2012, 22:01
(This post was last modified: September 19th, 2012, 09:03 by WhiteMage.)
Posts: 634
Threads: 13
Joined: Nov 2010
Morningkill Wrote:By ruleset, I meant things like statistics for units, spells, and so on.. Yes, but it should be standard. AI should not be expected to adapt to new Rulesets in early versions. For example, both chess and C-Evo heavily depend on current statistics of individual units, technologies, etc. Imagine just slightly modifying pawn moves in chess. All current lookup tables would fail immediately. C-Evo AI also depends on blueprint strategies. In the far-far future: sure, AI should adapt. However, a whole class of AIs would not be able to adapt. Even those which can, adaptation may take numerous games and if an AI plays under new values (RuleSets) for the first time, chances are that it will do far worse than AIs, which are already trained/adapted (not to mention new programming) to the new rule set.
I don't know what you mean by "everything needed for making decisions for the current function". Decisions are made for current game state and those decisions may be far more complex than simple function calls. Do you talk about interface function that calls up the AI? Game state (or "CurrentContext") is simply passed to the AI. The rest is up to the AI, so no more interface I can see.
Morningkill Wrote:rather than having the game engine passing the information (more or less directly), maybe the AI could ask the engine for information : some kind of "How many enemy units are near my city"
I think it would be better to let the server push information to everyone, including AI. Neither the AI, nor the client should pull information from the server. This has several advantages. One of them is keeping things simple. AI and client can figure out statistics from game states, such as number of known units with x property. There may be too many properties to program even into the server, which is not supposed to know how the AI makes decisions. Also why make so many haphazard, unnecessary, interrupting calls to the server? Again, AI and server code (game engine) should be independent.
Morningkill Wrote:I'm not saying we should start with this kind of AI, but we should offer the possibilty for anyone wanting to do it.
Good, then you and I are saying the same thing on this issue.
December 2nd, 2013, 09:10
Posts: 476
Threads: 22
Joined: Apr 2011
So here is the plan so far.
Ill make an assembly that has teh AI interface in it. It will have:
void InitAi(AIContext) //the context contains all information the AI will need
// to know about the game beforehand (ruleset, whatever else is needed) as well as
//necessary gamestate objects to query gamestate and produce network events
List<NetworkEvent> DoTurnOverland(Wizard aiPlayer) //do part of an overland turn. This will be called repeatedly while the ai is the turnmaster
List<NetworkEvent> DoTurnCombat(Wizard aiPlayer) //do part of the combat turm. This will be called repeatedly while the ai is the combatturnmaster
NetworkEvent RespndToDiplomacy(DiplomacyOption )//this shuold be a simple yes/no answer for player initiated diplomacy options
Ai is then written as a .NET assembly, that uses this interface. A config option will be present to chain the AI in. If the author of the AI wants to use some other language, he will have to write the wrapper assembly for it. (this is because I want the base game to be platform independent).
One issue I see is to have the AI be aware of inbetween turn happenings. For example: player attacks AI city, but loses. The AI will none the wiser, as by querying the gamestate this is not deducible. The problem is, that different AIs may require different notifications: maybe someone want an AI that detects troops coming near its cities, not just attacking ones. It is hard to formalize all possible queries, so maybe AI needs to get notification of all events, and then needs to figure out whats happening by himself. We still need a comprehensive list of things the AI may be interested in. Network events only may not be enough.
December 2nd, 2013, 14:33
Posts: 206
Threads: 13
Joined: Apr 2012
but network events is enough to get started. AI coders can then find out what else they need and tell other coders, so they provide it.
i like AI coding. can we do it in a way that supports multiple AI codes and then picks one of the available for each AI player by difficulty level, player choice, random, whatever? the biggest downfall of all AIs is usually predictability. having multiple AIs would counter that a bit.
dance!
December 2nd, 2013, 15:10
Posts: 591
Threads: 30
Joined: Jul 2012
(September 18th, 2012, 22:01)WhiteMage Wrote: I think it would be better to let the server push information to everyone, including AI. Neither the AI, nor the client should pull information from the server. There are reasons to permit AIs to cheat.
December 2nd, 2013, 17:09
(This post was last modified: December 2nd, 2013, 17:09 by WhiteMage.)
Posts: 634
Threads: 13
Joined: Nov 2010
(December 2nd, 2013, 15:10)Anthony Wrote: There are reasons to permit AIs to cheat. And there are reasons to permit humans to cheat too. . Lame AIs must cheat: this is the standard in TBS games out there since they lack strong AIs. For my planned strong AI, there is no reason for AI to cheat. That is the philosophy in C-Evo and I strongly agree. For initial reMOM target we must attempt to eliminate all cheats: AI and human. In later reMOM mods people can program whatever makes them happy.
|