Win Popcapbookworm forever

Source: Internet
Author: User
Win Popcapbookworm forever
Bookworm is a good game. if you don't know it, you can search for it in the app store. I used php to write a program that will always spell out the highest score. Hey, I am good or bad.

Fullwordlist.txt is a dictionary. if the file is too long, it will not be pasted out. if you are interested, you can search for one on the Internet.

  1. // Author: huangfeng aiwujia
  2. If (empty ($ _ POST) die;
  3. // Receives and processes raw input data. w represents the character, and v represents the corresponding score.
  4. $ Data = array ();
  5. For ($ I = 1; $ I <= 24; $ I ++ ){
  6. Array_push ($ data, array ('W' => strtoupper (trim ($ _ POST ['W '. $ I]), 'V' => trim ($ _ POST ['V '. $ I]);
  7. }
  8. // Deduplicate to calculate the sum score
  9. $ Data_unduplicated = array ();
  10. Foreach ($ data as $ key => $ value ){
  11. $ Data_unduplicated [] = implode (',', $ value );
  12. }
  13. $ Data_unduplicated = array_unique ($ data_unduplicated );
  14. // Calculate the occurrence frequency of each character
  15. $ Data_frequency = array ();
  16. Foreach ($ data as $ arr ){
  17. $ Data_frequency [] = $ arr ['w'];
  18. }
  19. $ Data_frequency_result = array_count_values ($ data_frequency );
  20. // Read the vocabulary file into the array
  21. $ Words = file ('./fullwordlist.txt', FILE_IGNORE_NEW_LINES );
  22. // Convert all the vocabulary into uppercase English
  23. $ Words = array_map (function ($ word ){
  24. Return strtoupper ($ word );
  25. }, $ Words );
  26. // Determine the frequency of each word
  27. $ Result = array ();
  28. Foreach ($ words as $ k => $ word ){
  29. // Skip a word containing'
  30. If (strpos ($ word, "'")> 0) continue;
  31. // Disassemble $ word to determine the occurrence frequency of each letter
  32. $ Word_arr = str_split ($ word );
  33. $ Word_arr_frequency = array_count_values ($ word_arr );
  34. $ Pass = true;
  35. Foreach ($ word_arr_frequency as $ character => $ frequency ){
  36. If (! Array_key_exists ($ character, $ data_frequency_result) | ($ data_frequency_result [$ character] <$ frequency )){
  37. $ Pass = false;
  38. }
  39. }
  40. // Perform the score calculation operation on the filtered $ word
  41. If ($ pass ){
  42. $ Word_value = 0;
  43. Foreach ($ word_arr as $ wkey => $ wchar ){
  44. Foreach ($ data_unduplicated as $ data_item ){
  45. $ Data_item = explode (',', $ data_item );
  46. // Var_dump ($ data_item); array 0 => string 'A' (length = 1) 1 => string '3' (length = 1)
  47. If ($ wchar! = $ Data_item [0]) continue;
  48. $ Word_value + = $ data_item [1];
  49. }
  50. }
  51. $ Result [] = array ('W' => $ word, 'V' => $ word_value );
  52. }
  53. }
  54. // Finally, only the highest score is selected.
  55. $ K = 0;
  56. $ Highest = 0;
  57. Foreach ($ result as $ key => $ item ){
  58. If (intval ($ item ['V']) >=$ highest ){
  59. $ Highest = $ item ['V'];
  60. $ K = $ key;
  61. }
  62. }
  63. Echo 'the highest score is :'. $ result [$ k] ['w']. '('. $ result [$ k] ['V']. ')';;

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.