
Good day to all!
Even at the university at senior courses began to get involved in intellectual agents. Even the theme for the diploma was originally associated with the creation of agents involved in hostilities in an environment that mimics the battlefield. But because of the work had to change the subject.
')
I have long wanted to do this, but all the time was not. Now finally got around to make an environment for agents, although not on such a scale. So if anyone is interested, join us! The repository is open, link below.
Intellectual agent.
In simple words, an agent is an entity placed in a habitat that is able to perceive the environment using sensors and act on it with the help of actuators.
The scheme of the simplest agent, as Wikipedia says, looks like this:

Such an agent has no mind, it acts solely on the list of the simplest if-then rules. There are several types of much more complex agents that are able to analyze their actions and learn. But to them I still far away.
Unity3d
I created a project in Unity3d, in which there is a battlefield (square) and several tanks. The textures of the tanks I took from the good old game Battle City. All that each tank can do is drive around the field and shoot.
This is what the whole project looks like:

2 control scripts are attached to each tank:
- TankBehavior
- BasicTankControls (or its subclass)
TankBehavior is the main script that fully describes one tank. In this script, the methods of displacement, firing and all others are implemented. This script also contains a link to BasicTankControls, which implements tank control. The base script looks like this:
public class BasicTankControls : MonoBehaviour { public void Init(TankBehavior tank) { this.tank = tank; } public virtual void Act(List<TankData> tanksData) {
This is the initialization of the script management in the TankBehavior script:
void Start () { ... controls = GetComponent<BasicTankControls>(); if(controls != null) { controls.Init(this); } ... }
This method is called every physical tick:
void FixedUpdate() { if(controls != null) { GameObject[] tankObjects = GameObject.FindGameObjectsWithTag("Tank"); List<TankData> tanksData = new List<TankData>(); foreach (var item in tankObjects) { if (item.GetInstanceID() != this.GetInstanceID()) { tanksData.Add(item.GetComponent<TankBehavior>().GetData()); } } controls.Act(tanksData); } }
First, data is collected on all tanks on the field. This simulates the collection of information about the environment by agent sensors. This information is then transmitted to the management script, which, already on the basis of the data obtained, will affect the environment.
Data on one tank looks like this:
public class TankData { public TankData(int instanceId, Vector2 position, float health, Direction direction) { this.InstanceID = instanceId; this.Position = position; this.Health = health; this.Direction = direction; } public readonly int InstanceID; public readonly Vector2 Position; public readonly float Health; public readonly Direction Direction; }
That's basically it. Now the task is only to write a control script for the tanks. I wrote one script to control a person, if someone suddenly wants to intervene in the course of events:
public class HumanControls : BasicTankControls { public override void Act(List<TankData> tanksData) { if(Input.GetButton("Up")) { tank.MoveForward(); } else if (Input.GetButton("Down")) { tank.MoveBackward(); } if (Input.GetButtonDown("Left")) { tank.RotateLeft(); } else if (Input.GetButtonDown("Right")) { tank.RotateRight(); } if (Input.GetButton("Fire")) { tank.Fire(); } } }
Tank behavior
To begin with, I plan to make simple autonomous behaviors, such as driving and shooting at random sides. Then there is the idea to add the walls (maybe destroyed) and the very headquarters, which one needs to be protected, and the other destroyed. It may even be joint action planning.
But these are very optimistic plans. I have never written such a thing myself, so I’ll have to study. Any help and advice is welcome! :)
Link to the repository.