Advertisement
maziari

Untitled

Oct 3rd, 2017 (edited)
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.10 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void next_rand(unsigned int *rand);
  4. void init_arr_puyo(int arr[256], int color);
  5. void shuffle_arr_puyo(int arr[256], unsigned int *rand);
  6. void init_arr_sort(int arr[126]);
  7. void count_puyo_color(int arr_12[24], int arr_count[4]);
  8. void dispos_puyo(long long int board[3], int arr[24], int num);
  9. int count_bit(long long int bits);
  10. int count_erase_puyo(long long int board[5]);
  11.  
  12. int main(void) {
  13.     int i, j, k;
  14.  
  15.     unsigned int seed;
  16.     unsigned int tmp_seed;
  17.     unsigned int rand;
  18.  
  19.     int arr_amakuchi[256];
  20.     int arr_tyukara[256];
  21.     int arr_sort[126];
  22.     int arr_puyo_12[24];
  23.     int arr_num_puyo_color[4];
  24.     long long int board_puyo[5];
  25.  
  26.     int num_erase_puyo;
  27.  
  28.     board_puyo[0] = 0;
  29.     board_puyo[4] = 0;
  30.    
  31.     long long int tmp[3];
  32.  
  33.  
  34.     for (i = 0x42000; i <= 0x400000; i++) {
  35.         seed = i;   // First Seed
  36.         tmp_seed = seed;
  37.  
  38.         for (j = 0; j < 5; j++) {
  39.             next_rand(&tmp_seed);
  40.         }
  41.  
  42.         /* Init Rand */
  43.         rand = tmp_seed >> 16;
  44.         for (j = 0; j < 5; j++) {
  45.             next_rand(&rand);
  46.         }
  47.  
  48.         /* Init Memory */
  49.         init_arr_puyo(arr_amakuchi, 3);
  50.         init_arr_puyo(arr_tyukara, 4);
  51.  
  52.         /* Shuffle Memory */
  53.         shuffle_arr_puyo(arr_amakuchi, &rand);
  54.         shuffle_arr_puyo(arr_tyukara, &rand);
  55.  
  56.         for (j = 0; j < 4; j++) {
  57.             arr_tyukara[j] = arr_amakuchi[j];
  58.             arr_num_puyo_color[j] = 0;
  59.         }
  60.  
  61.         /* Make Sort Array*/
  62.         init_arr_sort(arr_sort);
  63.  
  64.         /* Init 12 Puyo Array */
  65.         for (j = 0; j < 24; j++) {
  66.             arr_puyo_12[j] = arr_tyukara[j];
  67.            
  68.         }
  69.  
  70.         /* Count Each Puyo Color */
  71.         count_puyo_color(arr_puyo_12, arr_num_puyo_color);
  72.  
  73.         if (arr_num_puyo_color[0] < 8 | arr_num_puyo_color[3] < 4) {
  74.             continue;
  75.         }
  76.  
  77.  
  78.         for (j = 0; j < 126; j++) {
  79.             /* Disposition Puyo*/
  80.             dispos_puyo(&board_puyo[1], arr_puyo_12, arr_sort[j]);
  81.  
  82.             tmp[2] = board_puyo[3];
  83.             tmp[1] = board_puyo[2];
  84.             tmp[0] = board_puyo[1];
  85.  
  86.             /* Rensa and Count Erasing Puyo */
  87.             num_erase_puyo = count_erase_puyo(board_puyo);
  88.             if (num_erase_puyo >= 4) {
  89.                 num_erase_puyo = count_erase_puyo(board_puyo);
  90.                 if (num_erase_puyo >= 19) {
  91.                     printf("seed: %08x, sort_num: %d\n", seed, j);
  92.  
  93.                     printf("\nsort: %d\n", arr_sort[j]);
  94.                     printf("\n%016llx\n", tmp[2]);
  95.                     printf("%016llx\n", tmp[1]);
  96.                     printf("%016llx\n", tmp[0]);
  97.  
  98.                     printf("\n%016llx\n", board_puyo[3]);
  99.                     printf("%016llx\n", board_puyo[2]);
  100.                     printf("%016llx\n", board_puyo[1]);
  101.  
  102.                     printf("\n%d\n", num_erase_puyo);
  103.                 }
  104.             }
  105.         }
  106.     }
  107.    
  108.    
  109.     printf("end.");
  110.  
  111.     return 0;
  112. }
  113.  
  114.  
  115. void next_rand(unsigned int *rand) {
  116.     *rand = (*rand * 0x5D588B65 + 0x269EC3) & 0xFFFFFFFF;
  117. }
  118.  
  119. void init_arr_puyo(int arr[256], int color) {
  120.     int i;
  121.     for (i = 0; i < 256; i++) {
  122.         arr[i] = i % color;
  123.     }
  124. }
  125.  
  126. void shuffle_arr_puyo(int arr[256], unsigned int *rand) {
  127.     int i, j;
  128.     int tmp;
  129.     unsigned int num1, num2;
  130.  
  131.     for (i = 0; i < 15; i++) {
  132.         for (j = 0; j < 8; j++) {
  133.             next_rand(rand);
  134.             num1 = (*rand >> 28) + i * 0x10;
  135.             next_rand(rand);
  136.             num2 = (*rand >> 28) + (i + 1) * 0x10;
  137.  
  138.             tmp = arr[num1];
  139.             arr[num1] = arr[num2];
  140.             arr[num2] = tmp;
  141.         }
  142.     }
  143.  
  144.     for (i = 0; i < 7; i++) {
  145.         for (j = 0; j < 16; j++) {
  146.             next_rand(rand);
  147.             num1 = (*rand >> 27) + i * 0x20;
  148.             next_rand(rand);
  149.             num2 = (*rand >> 27) + (i + 1) * 0x20;
  150.  
  151.             tmp = arr[num1];
  152.             arr[num1] = arr[num2];
  153.             arr[num2] = tmp;
  154.         }
  155.     }
  156.  
  157.     for (i = 0; i < 3; i++) {
  158.         for (j = 0; j < 32; j++) {
  159.             next_rand(rand);
  160.             num1 = (*rand >> 26) + i * 0x40;
  161.             next_rand(rand);
  162.             num2 = (*rand >> 26) + (i + 1) * 0x40;
  163.  
  164.             tmp = arr[num1];
  165.             arr[num1] = arr[num2];
  166.             arr[num2] = tmp;
  167.         }
  168.     }
  169. }
  170.  
  171. void init_arr_sort(int arr[126]) {
  172.     int i, j;
  173.     int bit_cnt, arr_cnt = 0;
  174.  
  175.     for (i = 0; i < 512; i++) {
  176.  
  177.         bit_cnt = 0;
  178.         for (j = 0; j < 9; j++) {
  179.             if (i & (1 << j)) bit_cnt++;
  180.         }
  181.  
  182.         if (bit_cnt == 4) {
  183.             arr[arr_cnt] = i;
  184.             arr_cnt++;
  185.         }
  186.     }
  187. }
  188.  
  189. void count_puyo_color(int arr_12[24], int arr_count[4]) {
  190.     int i, j;
  191.  
  192.     for (i = 0; i < 24; i++) {
  193.         arr_count[arr_12[i]]++;
  194.     }
  195.  
  196.     for (i = 0; i < 3; i++) {
  197.         for (j = 3; j > i; j--) {
  198.             if (arr_count[j - 1] < arr_count[j]) {
  199.                 arr_count[j - 1] ^= arr_count[j] ^= arr_count[j - 1] ^= arr_count[j];
  200.             }
  201.         }
  202.     }
  203. }
  204.  
  205. void dispos_puyo(long long int board[3], int arr[24], int num) {
  206.     int i, j;
  207.     unsigned long long int bit_mask;
  208.     int cnt_column_4, cnt_column_5;
  209.  
  210.     for (i = 0; i < 3; i++) {
  211.         board[i] = 0;
  212.     }
  213.     cnt_column_4 = 1;
  214.     cnt_column_5 = 1;
  215.  
  216.  
  217.     for (j = 0; j <= 11; j++) {
  218.         if (j == 0) {
  219.             board[1] |= (long long int)1 << arr[1];
  220.             board[2] |= (long long int)1 << arr[0];
  221.         }
  222.         if (j >= 1 && j <= 9) {
  223.             if (num & (1 << (j - 1))) {
  224.                 board[2] |= (long long int)1 << (arr[j * 2 + 1] + cnt_column_5 * 4);
  225.                 board[2] |= (long long int)1 << (arr[j * 2] + (cnt_column_5 + 1) * 4);
  226.                 cnt_column_5 += 2;
  227.             }
  228.             else {
  229.                 board[1] |= (long long int)1 << (arr[j * 2 + 1] + cnt_column_4 * 4);
  230.                 board[1] |= (long long int)1 << (arr[j * 2] + (cnt_column_4 + 1) * 4);
  231.                 cnt_column_4 += 2;
  232.             }
  233.         }
  234.         if (j == 10) {
  235.             board[1] |= (long long int)1 << (arr[20] + 44);
  236.             board[1] |= (long long int)1 << (arr[21] + 48);
  237.         }
  238.         if (j == 11) {
  239.             board[0] |= (long long int)1 << arr[23];
  240.             board[0] |= (long long int)1 << (arr[22] + 4);
  241.         }
  242.     }
  243.  
  244.     bit_mask = ((board[1] >> 4) ^ board[1]) & 0x00000f000000000;
  245.     bit_mask = (bit_mask << 4) | bit_mask;
  246.     board[1] ^= bit_mask;
  247.  
  248. }
  249.  
  250. int count_bit(long long int bits) {
  251.     const int bit_table[256] = {
  252.         0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  253.         1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  254.         1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  255.         2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  256.         1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  257.         2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  258.         2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  259.         3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
  260.     };
  261.  
  262.     return  bit_table[bits & 0xff] + bit_table[(bits >> 8) & 0xff]
  263.             + bit_table[(bits >> 16) & 0xff] + bit_table[(bits >> 24) & 0xff]
  264.             + bit_table[(bits >> 32) & 0xff] + bit_table[(bits >> 40) & 0xff]
  265.             + bit_table[(bits >> 48) & 0xff] + bit_table[(bits >> 56) & 0xff];
  266. }
  267.  
  268. int count_erase_puyo(long long int board[5]) {
  269.     int i, j;
  270.  
  271.     long long int link[5];
  272.     long long int link_link_2[5];
  273.     long long int link_3[5];
  274.     long long int erase_color[5];
  275.     long long int erase_integ[5];
  276.     long long int abst_color[5];
  277.  
  278.     long long int drop_prot_mask[5];
  279.     long long int drop_diff_mask[5];
  280.     long long int tmp_board;
  281.  
  282.     int num_erase_puyo = 0;
  283.  
  284.     for (i = 0; i < 5; i++) {
  285.         erase_integ[i] = 0;
  286.     }
  287.    
  288.     for (i = 0; i < 4; i++) {
  289.         for (j = 0; j < 5; j++) {
  290.             link[j] = 0;
  291.             link_link_2[j] = 0;
  292.             link_3[j] = 0;
  293.             erase_color[j] = 0;
  294.             abst_color[j] = (board[j] >> i) & 0x1111111111111111;
  295.             drop_prot_mask[j] = 0;
  296.             drop_diff_mask[j] = 0;
  297.         }
  298.  
  299.         for (j = 1; j <= 3; j++) {
  300.             link[j] += (abst_color[j] & abst_color[j - 1]) & 0x0000ffffffffffff;
  301.             link[j] += (abst_color[j] & abst_color[j + 1]) & 0x0000ffffffffffff;
  302.             link[j] += (abst_color[j] & (abst_color[j] << 4)) & 0x0000ffffffffffff;
  303.             link[j] += (abst_color[j] & ((abst_color[j] & 0x0000ffffffffffff) >> 4)) & 0x0000ffffffffffff;
  304.         }
  305.  
  306.         for (j = 1; j <= 3; j++) {
  307.             link_3[j] |= (link[j] + 0x1111111111111111 >> 2) & 0x1111111111111111;
  308.         }
  309.  
  310.         for (j = 1; j <= 3; j++) {
  311.             link[j] = ((link[j] + 0x2222222222222222) >> 2) & 0x1111111111111111;
  312.         }
  313.  
  314.         for (j = 1; j <= 3; j++) {
  315.             link_link_2[j] |= link[j] & link[j - 1] & 0x1111111111111111;
  316.             link_link_2[j] |= link[j] & link[j + 1] & 0x1111111111111111;
  317.             link_link_2[j] |= link[j] & (link[j] << 4) & 0x1111111111111111;
  318.             link_link_2[j] |= link[j] & (link[j] >> 4) & 0x1111111111111111;
  319.         }
  320.  
  321.         for (j = 1; j <= 3; j++) {
  322.             erase_color[j] |= abst_color[j] & (link_link_2[j] | link_3[j]);
  323.             erase_color[j] |= abst_color[j] & (link_link_2[j - 1] | link_3[j - 1]);
  324.             erase_color[j] |= abst_color[j] & (link_link_2[j + 1] | link_3[j + 1]);
  325.             erase_color[j] |= abst_color[j] & ((link_link_2[j] | link_3[j]) >> 4);
  326.             erase_color[j] |= abst_color[j] & ((link_link_2[j] | link_3[j]) << 4);
  327.             num_erase_puyo += count_bit(erase_color[j]);
  328.  
  329.             erase_color[j] = erase_color[j] + (erase_color[j] << 1) + (erase_color[j] << 2) + (erase_color[j] << 3);
  330.  
  331.             erase_integ[j] |= erase_color[j];
  332.         }
  333.     }
  334.  
  335.     while (erase_integ[1] | erase_integ[2] | erase_integ[3]) {
  336.         for (j = 1; j <= 3; j++) {
  337.             drop_prot_mask[j] = (erase_integ[j] ^ (erase_integ[j] - (long long int)1)) >> 1;
  338.             drop_diff_mask[j] = (~erase_integ[j] - ((erase_integ[j] - 1) ^ erase_integ[j])) & erase_integ[j];
  339.  
  340.             tmp_board = board[j] & drop_prot_mask[j];
  341.             board[j] = ((board[j] >> count_bit(drop_diff_mask[j])) & ~drop_prot_mask[j]) | tmp_board;
  342.  
  343.             erase_integ[j] = (erase_integ[j] ^ drop_diff_mask[j]) >> count_bit(drop_diff_mask[j]);
  344.         }
  345.     }
  346.  
  347.     return num_erase_puyo;
  348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement