Landlord AI Algorithm Implementation

Source: Internet
Author: User

Landlords AI Algorithm Implementation 1 (card splitting)

By wojiushi3344

QQ: 513670524

Reprinted, please describe the source


Source code download

PS: I have already written several basic algorithm implementations for the primary game. Today I want to talk about the most important and rare AI Algorithm Implementation in single-host game development. I hereby declare that this blog post is only applicable to cainiao like me. Do not try it out. Thank you for your valuable suggestions and solutions!

If you are still interested in other algorithms of the landlords game, please visit this address: chess and card game development column.

First, let's take a look at the definition of AI:

Artificial intelligence (AI. It is a new technical science that researches and develops Theories, Methods, technologies, and application systems used to simulate, extend, and expand human intelligence. Artificial Intelligence: how to use computers to simulate, extend, and expand human intelligence; how to make computers smarter; how to design and build a computer application system with a high level of intelligence; how to design and manufacture smarter computers and more intelligent computers

---------- From Baidu encyclopedia

Here we mainly talk about how to use computers to simulate human thinking and implement a specific algorithm.

Glossary:

Number of players: assuming that no one else needs to pass the rules, the number of players is called the number of players, you must never understand this procedure.

First, we can divide the landlord AI algorithm into two parts for discussion.

Today we will discuss the first part:

Card Removal

Card splitting is an important part of the landlord ai. The quality of card splitting directly affects the efficiency of the landlord AI algorithm.

First, let's move on to an image. This is more intuitive and will be helpful for further discussions.

Define the size of the weight for each type:

Leaflet 1

Child 2

Three-belt 3

Card 4 (each card has more than one weight + 1)

Connect to 5 (each multiple cards has a weight of + 2)

Aircraft 6 (each pair of planes has a permission value plus 3)

Bomb 7 (including the King)

 

When we see this deck card, let's split it according to the normal train of thought.

Qqq 222

45678910j

AA

Kid 6, 4

Let's discuss a scheme now. Can we see that this scheme can be used in the end?

We will discuss the card splitting process in several steps.

Step 1: Find a card

Define the corresponding Card Type Vector

Vector <Three> // 3

Vector <lianzi> // concatenation

Vector <Duizi> // child

Vector <danzhang> // Leaflet

Vector <fly> // aircraft

 

First, find a deck of cards that can only form one card type (three cards, one card for each pair .) This means that one card is not associated with any of the remaining cards. Of course, whether it is associated with the remaining cards requires defining a rule: whether or not it can be connected to the remaining cards. If neither of the two conditions is met, we call this card irrelevant to the remaining card. In general, you can find several cards through this step, which can reduce the number of tasks for the cards to be removed in the future.

 

For example, we can find out: Kid, 2, A, and then find the cards with the same value as them. That is, Tom, 222, AA, and the remaining cards are: qqqj1098766544. Some may ask why I didn't find QQ Q. This is because Q can not only make up three pairs, you can also combine the remaining cards. It is found that in the final card splitting solution for the pair, three are connected. Article 3> the previous conclusion is as follows.

Vector <Three> 222

Vector <Duizi> AA

Vector <danzhang> little devil

 

Next we will split the remaining cards: qqqj1098766544

Find all the bombs on the card

Find all three of the cards

Find all pairs in the card

Based on the remaining cards, we first proposed qqq 66 44

 

Here we can define the corresponding vector to store the cards we temporarily find. Note that the defined vector is different from the above vector.

Vector <Three> qqq

Vector <two> 66,44

Step 2: calculate the number of hands and weights of each card(Difficulties in card splitting)

We can discuss the problem in several cases. We can only find 5 of the remaining cards at a time, and then splice these 5 cards and the remaining cards to see if they can be combined into a longer card.

After the cards are proposed, all the remaining cards are regarded as single cards, whether it is bombs, 3 cards, or pairs.

1. Raise qqq in the remaining cards. j1098766544: first, find five cards. The minimum or maximum number is determined by you. We will discuss it at least here.

First time: 45678 remaining cards are 4 6 9 10 J

Second: 45678910j 46

The two groups of cards that were finally removed were not linked and the cards were terminated.

Solution: 45678910j 4 6 qqq

Corresponding weights and number of hands: 7 + 1 + 1 + 3 = 12 3 (because three can contain one or one pair, when there is a pair and a single sheet, the number of hands minus 1)

The following solutions follow the same steps. I will not write the process and write the final solution directly.

2. Propose qqq 66 in the remaining cards

Solution: qqq 66 78910j 5 44

Corresponding weights and hands: 3 + 2 + 4 + 1 + 2 = 12 4

 

3. Raise qqq 44 in the remaining cards

Solution: qqq 44 678910j 6

Corresponding weights and hands: 3 + 2 + 5 + 1 = 11 3

 

4. Put forward 66 in the remaining row

Solution: 66 78910jq QQ 5 44

Corresponding weights and hands: 2 + 5 + 2 + 1 + 2 = 10 5

 

5. Propose 44 of the remaining cards

Solution: 44 5678910jq 6 QQ

Corresponding weights and hands: 2 + 7 + 1 + 2 = 12 4

 

6. Do not propose any cards

45678910jq 4 6 q

Corresponding weights and hands: 9 + 1 + 1 + 1 = 12 4

 

Step 3: select the best group of cards as the final card removal solution

Through the above steps, we have identified several licensing schemes, and finally we have found the solution with the smallest number of players.

If the number of hands is the same, find the group with the highest weight.

If both of them are the same, you can choose either of them at random. (This situation is very small)

Through comparison, we have determined the following card removal solution.

 

Solution: 45678910j 4 6 qqq

Corresponding weights and number of hands: 7 + 1 + 1 + 3 = 12 3 (because three can contain one or one pair, when there is a pair and a single sheet, the number of hands minus 1)

Finally, add the cards we first find. The final card removal solution is:

Vector <Three> 222, qqq

Vector <Duizi> AA

Vector <danzhang> kid, 4, 6

Vector <lianzi> 45678910j

 

Oh, isn't the cards removed in this way fit the normal thinking.

We split this card scheme to use it when the computer is playing the card.

Of course, we also need to define a struct to store all the card types that each card can constitute. And the maximum value of each card type, so as to be the most prepared for future cards.

 

Okay, it's time to come and discuss the cards later !!

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.