[Cocos2dx] an algorithm for making the landlords & amp; quot; sort

Source: Internet
Author: User

When building a landlord, there is another sort of cards after the cards are issued, which is one of the issues to consider. The sorting here is not a general simple bubble sort, my idea is to arrange the card 0-51, with 13 as a benchmark classification, for example, 0-12 respectively correspond to the peach A-K, 13-25 corresponds to the peach A-K, 26-38 corresponds to the square A-K, 39-51 is plum blossom A-K. The server then sorts the 17 numbers allocated to each player into card arrays. The algorithm is given below. Thanks to @!

Code:

Using System; using System. collections. generic; using System. linq; using System. text; namespace random sorting {class Program {static void Main (string [] args) {int [] array = {1, 2, 6, 33, 44, 23, 36, 5, 9, 14,0, 14,15}; // shuffling from large to small // int [] array = {1, 2, 3, 4, 5, 6, 0 }; bubbleSortFunction (array); foreach (int I in array) {Console. write (I + ",") ;}// bubble sort (traversal starts from the starting position of the array, with a large number of benchmarks: sinking a large number) private static void Bubb LeSortFunction (int [] array) {int length = array. length; int temp; bool hasExchangeAction; // record whether two adjacent numbers in this large loop have been swapped (if not SWAps, the array is already ordered) for (int I = 0; I <length-1; I ++) // There are N numbers in the array, then you can use the N-1 to complete the Large Loop {hasExchangeAction = false; // each large loop assumes that the array is ordered for (int j = 0; j <length-I-1; j ++) // traverses from the array subscript 0, (length-I-1 is the calculated large number.) {int p1 = array [j] % 13; int p2 = array [j + 1] % 13; if (p1 = 0) p1 = 14; if (P2 = 0) p2 = 14; if (p1 = 1) p1 = 15; if (p2 = 1) p2 = 15; if (array [j] = 52) p1 = 16; if (array [j + 1] = 52) p2 = 16; if (array [j] = 53) p1 = 17; if (array [j + 1] = 53) p2 = 17; if (p1 <p2) // compare two adjacent numbers, if the preceding number is greater than the following number, the two adjacent numbers are swapped. {temp = array [j]; array [j] = array [j + 1]; array [j + 1] = temp; hasExchangeAction = true; // swapping occurred} if (! HasExchangeAction) // if no swaps have occurred, the array is already ordered and the loop {break ;}}} exists ;}}}}}

Result:



Note: according to the rules I mentioned above, we will find that the cards are actually sorted from big to small. The leftmost is Hongtao 2, then taotao 2, and then Hongtao, and so on!

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.