Advanced random Technology for game AI development, advanced AI Development

Source: Internet
Author: User

Advanced random Technology for game AI development, advanced AI Development
Get3 new rand methods, simple and practical
They are Gaussian distribution random, Filtering Random, perlin random, and perlin old friend. The first two types are described here.
Gaussian Randomness Gaussian distribution is also known as Normal distribution or bell curves. Normal distribution is no longer familiar. It looks like this:
 
Why do we generate a random number based on Gaussian distribution? Here we will refer to the term "central limit theorem )". Central limit theorem: in nature and production, some phenomena are affected by many independent random factors, the overall impact can be seen as obeying a normal distribution. The central limit theorem proves this phenomenon in mathematics. In short, the random probability in real life is in line with the normal distribution. This is why we use Gaussian distribution to make the results more realistic.
Such randomness Based on Gaussian distribution can be used for: speed, human characteristics, the height of trees in a forest, the height of a person, the deviation of bullets, and so on.
Implementation Code in Unity:

using UnityEngine;using System.Collections;public class Gaussian : MonoBehaviour{    public int seed = 61829450;    double sum = 0;    long r = 0;    // Use this for initialization    void Start()    {    }    // Update is called once per frame    void Update()    {        if (Time.frameCount % 7== 0)        {     //       seed = 61829450;            sum = 0;        for (int i = 0; i < 3; i++)        {            long holdseed = seed;            seed ^= seed << 13;            seed ^= seed >> 17;            seed ^= seed << 5;            r = holdseed + seed;            sum += (double)r * (1.0 / 0x7FFFFFFFFFFFFFFF);        }        print( sum); //returns [-3.0, 3.0] at (66.7%, 95.8%, 100%)        }    }}



Show normal pseudo-random and Gaussian random to simulate the deviation of shot bullets respectively
 
Most of the Gaussian distribution points are in the center. The common pseudo-random distribution is relatively uniform, and the obvious Gaussian distribution is more realistic. Players also hope to be accurate, with a higher head-breaking rate.
Application of Gaussian distribution:
1. Speed
2. Acceleration
3. Dimensions, width, height, quality
4. Simulated vision and response time
5. Bullet filling speed and fire speed
6. Refreshing RATE AND COOLING RATE


Random filtering is more about "fairness", that is, the disorder that comes with it. Filtering means that the random numbers are sometimes too close or too many gaps are used to filter out and re-randomize them.
There is evidence that when the random performance is very small, humans do not feel that it is random.
For example, many people do not believe that the result of coin throwing is random, because the result may be as follows:
 
There are a large number of duplicates, 00000 or 11111, which are close together. If you set the brute-force attack to generate a random attack, the random result is as follows: the enemy may launch four or five consecutive attacks to directly link you to death. This is not the result that the player wants. However, this is true at random, so sometimes the fun of players is more important than authenticity.
Binary filtering is blocked in the following situations:
1. If there are already four new numbers, random them again.
2. For example, 11001100 is replaced with 11001101.
3. Replace the last number with 111000 or 000111.

Make a comparison after replacement:
 
Filter Integer 1. If there are two duplicate random numbers, then random new numbers again
2. There is a repetition of a number, such as "8, 3, 8" or "6, 2, 6"
3. Too many limit values, that is, too many limit values and small values, such as "6, 8, 7, 9, 8, 6, 9"
4. There are two groups of duplicates within 10, for example, "5, 7, 3, 1, 5, 7"
5. continuous increase or decrease, such as "3, 4, 5, 6"
6. There are too many repetitions within 10, such as "9, 4, 5, 9, 7, 8, 9, 0, 2, 9"
Make a comparison after replacement:
 
Filter floating point numbers between 0 and 1.
1. The difference between two consecutive numbers is less than 0.02, for example, 0.875 and 0.856.
2. The difference between the three consecutive numbers is less than 0.1, such as 0.345, 0.421, and 0.387.
3. Five consecutive increases or decreases, such as 0.342, 0.572, 0.619, 0.783, and 0.868.
4. Too many limit values, that is, too many limit and small values, 0.325, 0.198, 0.056, and 0.432.



Summary

If you want to produce a more realistic result, it is to use Gaussian distribution random. To make players happier, you can filter the random numbers generated.


------ By wolf96 http://blog.csdn.net/wolf96


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.