Random in the game--transformation thinking

Source: Internet
Author: User

The title of the article is "random in the game-conversion thinking", there is a key word is "random", but random this statement is too general, so I mainly say a materialized example: random coordinates.

Random coordinates are fairly common in the game, such as dropping, spawning mobs, gathering and spawning, or some of the treasure spots in the event.

A random coordinate is not difficult.

What about a random, non-repeating coordinate? In fact, it's not difficult!

Is it good to bcause?

is to tell how to make an efficient and concise random coordinate module!

I know that quite a few people have thought of designing random coordinate modules as follows:

A, is from a large basket, pumping table tennis, each draw a table tennis, only record its number, table tennis does not take out the basket, continue to extract;

If it is found that the table tennis has been extracted, then do not record, continue to extract.

The biggest disadvantage of this approach is that the more table-tennis you draw, the lower the efficiency. The efficiency of extracting a table tennis is undoubtedly the highest, as it is impossible to repeat.

B, Maybe you saw my language hint in a, and already thought of what I was going to say. is to put more than a basket of table tennis, drawn from the baskets 1, put into the baskets 2, 1 no table tennis, and then to the basket 2 extract.

The advantage of this approach is that each extraction does not need to check whether the table tennis has been extracted. The downside is that you need to waste a lot of resources. This is a way of using space to change time.


See here, I want to say, the above two do a key word is: pumping. In the jargon of the computer: rand;

In the beginning of the efficient and concise method C, I first say a small example, that is to play poker cards.

When we play poker, we take the form of a roll-dice draw and distribute each card to each player's hands. Obviously not.

We actually distribute the cards directly to each player in order, but we still think that these cards are random. The reason is that we have already washed the cards before the cards are dealt.

We do not take the roll dice draw, because it is obvious that this is an inefficient practice.


Similarly, method C is the use of this idea. Method C, replace the slot with a basket and become a table tennis container.

C, before removing the table tennis, put the table tennis disorderly sequence into the groove. Remove the ping-pong ball at one end of the slot and put it back at the other end of the table tennis that has been recorded. If necessary, the table tennis order in the slot can be disrupted again.

The advantage of this approach is that you only need to do one uniform random, then use it, no more extraction, directly in order to obtain.


In general, this is an efficient and concise way to compare the first two methods.

At this point, the game in the random has been finished, conversion thinking is also contained in the above explanation. In fact, the focus of this article is on "conversion thinking", we can not know all the use of the conversion of the instance, but need to always keep the conversion thinking.

A step back, a brighter sky.


Random in the game--transformation thinking

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.