So you can always win PopCap Bookworm

Source: Internet
Author: User
Bookworm is a very good game, if you don't know it, then you can search in the App Store. I used PHP to write a forever will spell out the highest score vocabulary program, hey, I am good or bad

Fullwordlist.txt is a dictionary, the document is too long, it is not posted out, interested friends can search the internet casually.

  1. Author:huangfeng Love Wu Jiazheng
  2. if (empty ($_post)) die;
  3. Receives and processes the original 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. Go to weight 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. To find the frequency of each character's occurrence
  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. Reading a glossary file into an array
  21. $words = File ('./fullwordlist.txt ', file_ignore_new_lines);
  22. Turn glossary all into uppercase English
  23. $words = Array_map (function ($word) {
  24. Return Strtoupper ($word);
  25. }, $words);
  26. Make a frequency judgment on each word
  27. $result = Array ();
  28. foreach ($words as $k = = $word) {
  29. Meet the words containing ', skip
  30. if (Strpos ($word, "'") > 0) continue;
  31. $word the letter to determine the 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 fractional operations on 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. And then only the highest scores were chosen.
  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. The word echo ' highest score is: '. $result [$k] [' W ']. ' ('. $result [$k] [' V ']. ') ';
Copy Code
  • 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.