Geek game-tank vs. AI Compilation
Today I saw a particularly interesting thing called CODE GAME. You can write AI for your tank in the Javascripe language and then compete with other AI tanks.
Traditional games are game elements operated by people. Unlike this game, you need to write a set of algorithms to control your tanks. After the game starts, all you can do is watch the two tanks fight against each other. Their flexibility and combat power make "intelligence" depend on your algorithm.
This reminds me of the "core war" Many years ago. This is the oldest game and the predecessor of computer viruses. Two scientists use assembly languages to write programs that can destroy each other's programs, the winner will survive. Today, few of us are capable of writing programs in assembly languages, but CODEGAME gives us the possibility of "creation.
The world of CODEGAME is composed of 16 × 12 grids, some of which are unobstructed roads and some are stones that cannot be crossed by bullets or tanks, some of them are soft and concealed lawns. If a tank is in the lawn, it will not find it to the other party. A tank can launch a bullet, move forward, or turn left or right. In fact, this is almost all the operations you can have.
These operations are composed of commands, such
- Tank forward: me. go ()
-
- Tank steering: me. turn (n) n = left or right
-
- Tank bullets: me. fire ()
This is all we can do, but we can also use some functions to perceive ourselves or our surroundings, such
- Coordinates of your tank: me. tank. position
-
- Orientation of your tank: me. tank. direction
-
- Enemy tank coordinates: enemy. tank. position
-
- Enemy tank orientation: enemy. tank. Position
-
- Map: game. map [x] [y] x is the horizontal coordinate, and y is the vertical coordinate. The returned result is the stone, lawn, or nothing.
-
- Star coordinates: star. position
Our goal is to let our small tanks eat as many stars as possible, or destroy enemy tanks, and be careful not to be hit by places. In the above conditions, we also need to make the algorithm as efficient as possible.
This is very easy to get started. The code in the official guide is directly pasted to get a tank that can turn to be able to launch bullets, but if you want your tank to be smarter, you need to do it yourself.
First, I added a pathtracing system to my tank. The algorithm of this system is implemented by a series of statements, which enables my tank to change in time before encountering obstacles, and can quickly come out in the dead end:
Then I wrote an attack system that allows me to track and launch bullets at the right time.
These two systems basically guarantee that my small tank is very majestic and can be shot along the way. But as a smart tank, it should also have an algorithm for finding stars, Because eating as many stars as possible is also one of the conditions for winning, so I wrote an algorithm for finding stars.
Searching for stars is of a low priority. When you hit an enemy, you rushed to the enemy. But if it was okay, the tank would still look for the stars. This is almost the same, but I noticed that I was often hit by other tanks during the battle, so I added a Dodge system, this allowed my tank to quickly escape from the enemy's bullets and increased the odds.
So far, a small "smart" tank was born. This tank will take the initiative to discover the enemy, and then turn to the correct direction to open the gun. when it encounters the other party's bullets, it will dodge, at the same time, it will search for stars in the whole map. Although I write all the AI for it, I still admire its flexibility and wisdom, the simple "Left turn", "forward", "Right turn", and "shooting" combined with perception of the status can actually make things flexible. This flexibility is not a "control" but an uncontrolled flexibility. You cannot operate your tank. You can only watch it move around.
This is really the pleasure of AI.
Life and wisdom are sometimes not as complicated as we think. Maybe they are more like a kind of sophistication evolved from simple, and every gene in a creature is not complicated, however, they are combined into an amazing life system. The simple commands in the program can be restored to some extent.
Although my tank has six hundred lines of code, it is still not enough in many aspects, such as advanced judgment on obstacles, pre-Calculation of enemy tank routes to launch bullets, etc, these can be improved. It is worth mentioning that this is not a "programmer" game. It requires very little programming knowledge. Official documents allow everyone to get started in 10 minutes, and this is enough. This game needs to consider behavior and algorithms. I think it is suitable for every geek and anyone interested in artificial intelligence, computers, and biology.
If you have compiled your tank, you are welcome to challenge me. My username is wdkwdkwdk. Enter my name in the competitor's username to compete with my tank ~