diff options
| -rw-r--r-- | lingo.cpp | 155 |
1 files changed, 142 insertions, 13 deletions
| diff --git a/lingo.cpp b/lingo.cpp index e6c5177..e0d1bfc 100644 --- a/lingo.cpp +++ b/lingo.cpp | |||
| @@ -79,6 +79,7 @@ public: | |||
| 79 | canonical_attempt.erase(canonical_attempt.find("||"), 2); | 79 | canonical_attempt.erase(canonical_attempt.find("||"), 2); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | std::cout << "\"" << canonical_attempt << "\"" << std::endl; | ||
| 82 | if (canonical_attempt == canonical_answer) | 83 | if (canonical_attempt == canonical_answer) |
| 83 | { | 84 | { |
| 84 | bot_->message_add_reaction(event.msg.id, event.msg.channel_id, "✅"); | 85 | bot_->message_add_reaction(event.msg.id, event.msg.channel_id, "✅"); |
| @@ -132,6 +133,7 @@ private: | |||
| 132 | bool generated = false; | 133 | bool generated = false; |
| 133 | while (!generated) | 134 | while (!generated) |
| 134 | { | 135 | { |
| 136 | std::cout << "Generating... " << std::endl; | ||
| 135 | try | 137 | try |
| 136 | { | 138 | { |
| 137 | int hints = 0; | 139 | int hints = 0; |
| @@ -142,11 +144,15 @@ private: | |||
| 142 | if (filters.count({static_cast<Height>(height), static_cast<Colour>(colour)})) { | 144 | if (filters.count({static_cast<Height>(height), static_cast<Colour>(colour)})) { |
| 143 | parts[static_cast<Height>(height)] = static_cast<Colour>(colour); | 145 | parts[static_cast<Height>(height)] = static_cast<Colour>(colour); |
| 144 | hints++; | 146 | hints++; |
| 147 | std::cout << COLOUR_EMOJIS[colour]; | ||
| 148 | } else { | ||
| 149 | std::cout << "▪️"; | ||
| 145 | } | 150 | } |
| 146 | } | 151 | } |
| 147 | } | 152 | } |
| 153 | std::cout << std::endl; | ||
| 148 | 154 | ||
| 149 | if (hints < 2) { | 155 | if (hints < 1) { |
| 150 | continue; | 156 | continue; |
| 151 | } | 157 | } |
| 152 | 158 | ||
| @@ -272,6 +278,7 @@ private: | |||
| 272 | } | 278 | } |
| 273 | 279 | ||
| 274 | verbly::form solution = database_->forms(forwardFilter).first(); | 280 | verbly::form solution = database_->forms(forwardFilter).first(); |
| 281 | verbly::filter admissable = cleanFilter && (verbly::form::proper == false); | ||
| 275 | 282 | ||
| 276 | std::ostringstream msg_stream; | 283 | std::ostringstream msg_stream; |
| 277 | for (int i=0; i<static_cast<int>(kHeightCount); i++) { | 284 | for (int i=0; i<static_cast<int>(kHeightCount); i++) { |
| @@ -401,6 +408,121 @@ private: | |||
| 401 | } | 408 | } |
| 402 | verbly::form questionPart = database_->forms(questionFilter && cleanFilter).first(); | 409 | verbly::form questionPart = database_->forms(questionFilter && cleanFilter).first(); |
| 403 | msg_stream << COLOUR_EMOJIS[*colour] << " " << questionPart.getText() << std::endl; | 410 | msg_stream << COLOUR_EMOJIS[*colour] << " " << questionPart.getText() << std::endl; |
| 411 | |||
| 412 | verbly::filter addedClause = (verbly::form::text == questionPart.getText()); | ||
| 413 | |||
| 414 | switch (*colour) { | ||
| 415 | case kWhite: { | ||
| 416 | switch (height) { | ||
| 417 | case kBottom: { | ||
| 418 | admissable &= (verbly::word::synonyms %= addedClause); | ||
| 419 | break; | ||
| 420 | } | ||
| 421 | case kTop: { | ||
| 422 | admissable &= (verbly::form::pronunciations %= | ||
| 423 | verbly::filter("homophones", false, | ||
| 424 | (verbly::pronunciation::forms %= (addedClause && verbly::filter( | ||
| 425 | verbly::form::id, | ||
| 426 | verbly::filter::comparison::field_does_not_equal, | ||
| 427 | verbly::form::id))))); | ||
| 428 | break; | ||
| 429 | } | ||
| 430 | default: break; // Not supposed yet. | ||
| 431 | } | ||
| 432 | break; | ||
| 433 | } | ||
| 434 | case kBlack: { | ||
| 435 | switch (height) { | ||
| 436 | case kBottom: { | ||
| 437 | admissable &= (verbly::word::antonyms %= addedClause); | ||
| 438 | break; | ||
| 439 | } | ||
| 440 | default: break; // Not supposed yet. | ||
| 441 | } | ||
| 442 | break; | ||
| 443 | } | ||
| 444 | case kBrown: { | ||
| 445 | switch (height) { | ||
| 446 | case kBottom: { | ||
| 447 | admissable &= (verbly::notion::causes %= addedClause); | ||
| 448 | break; | ||
| 449 | } | ||
| 450 | default: break; // Not supposed yet. | ||
| 451 | } | ||
| 452 | break; | ||
| 453 | } | ||
| 454 | case kRed: { | ||
| 455 | switch (height) { | ||
| 456 | case kTop: { | ||
| 457 | admissable &= (verbly::pronunciation::holophones %= addedClause); | ||
| 458 | break; | ||
| 459 | } | ||
| 460 | case kMiddle: { | ||
| 461 | admissable &= (verbly::form::holographs %= addedClause); | ||
| 462 | break; | ||
| 463 | } | ||
| 464 | case kBottom: { | ||
| 465 | admissable &= (verbly::notion::partMeronyms %= addedClause); | ||
| 466 | break; | ||
| 467 | } | ||
| 468 | default: break; // Not supposed yet. | ||
| 469 | } | ||
| 470 | break; | ||
| 471 | } | ||
| 472 | case kBlue: { | ||
| 473 | switch (height) { | ||
| 474 | case kTop: { | ||
| 475 | admissable &= (verbly::pronunciation::merophones %= addedClause); | ||
| 476 | break; | ||
| 477 | } | ||
| 478 | case kMiddle: { | ||
| 479 | admissable &= (verbly::form::merographs %= addedClause); | ||
| 480 | break; | ||
| 481 | } | ||
| 482 | case kBottom: { | ||
| 483 | admissable &= (verbly::notion::partHolonyms %= addedClause); | ||
| 484 | break; | ||
| 485 | } | ||
| 486 | default: break; // Not supposed yet. | ||
| 487 | } | ||
| 488 | break; | ||
| 489 | } | ||
| 490 | case kPurple: { | ||
| 491 | switch (height) { | ||
| 492 | case kMiddle: { | ||
| 493 | admissable &= (verbly::form::merographs %= (verbly::form::length >= 4 && (verbly::form::holographs %= addedClause))); | ||
| 494 | break; | ||
| 495 | } | ||
| 496 | case kTop: { | ||
| 497 | admissable &= (verbly::pronunciation::rhymes %= addedClause); | ||
| 498 | break; | ||
| 499 | } | ||
| 500 | default: break; // Not supposed yet. | ||
| 501 | } | ||
| 502 | break; | ||
| 503 | } | ||
| 504 | case kYellow: { | ||
| 505 | switch (height) { | ||
| 506 | case kTop: { | ||
| 507 | admissable &= (verbly::pronunciation::anaphones %= (addedClause && verbly::filter( | ||
| 508 | verbly::pronunciation::id, | ||
| 509 | verbly::filter::comparison::field_does_not_equal, | ||
| 510 | verbly::pronunciation::id))); | ||
| 511 | break; | ||
| 512 | } | ||
| 513 | case kMiddle: { | ||
| 514 | admissable &= (verbly::form::anagrams %= (addedClause && verbly::filter( | ||
| 515 | verbly::form::id, | ||
| 516 | verbly::filter::comparison::field_does_not_equal, | ||
| 517 | verbly::form::id))); | ||
| 518 | break; | ||
| 519 | } | ||
| 520 | default: break; // Not supposed yet. | ||
| 521 | } | ||
| 522 | break; | ||
| 523 | } | ||
| 524 | default: break; // Not supposed yet. | ||
| 525 | } | ||
| 404 | } else { | 526 | } else { |
| 405 | msg_stream << "▪️" << std::endl; | 527 | msg_stream << "▪️" << std::endl; |
| 406 | } | 528 | } |
| @@ -410,23 +532,30 @@ private: | |||
| 410 | std::string message_text = msg_stream.str(); | 532 | std::string message_text = msg_stream.str(); |
| 411 | std::cout << message_text << std::endl << std::endl << solution.getText() << std::endl; | 533 | std::cout << message_text << std::endl << std::endl << solution.getText() << std::endl; |
| 412 | 534 | ||
| 413 | dpp::message message(channel, message_text); | 535 | std::vector<verbly::form> admissableResults = database_->forms(admissable).all(); |
| 414 | bot_->message_create(message, [this, &solution](const dpp::confirmation_callback_t& userdata) { | 536 | if (admissableResults.size() <= 5) |
| 415 | const auto& posted_msg = std::get<dpp::message>(userdata.value); | 537 | { |
| 416 | std::lock_guard answer_lock(answers_mutex_); | 538 | dpp::message message(channel, message_text); |
| 417 | if (answer_by_message_.size() > 3000) | 539 | bot_->message_create(message, [this, &solution](const dpp::confirmation_callback_t& userdata) { |
| 418 | { | 540 | const auto& posted_msg = std::get<dpp::message>(userdata.value); |
| 419 | answer_by_message_.clear(); | 541 | std::lock_guard answer_lock(answers_mutex_); |
| 420 | } | 542 | if (answer_by_message_.size() > 3000) |
| 421 | answer_by_message_[posted_msg.id] = solution.getText(); | 543 | { |
| 422 | }); | 544 | answer_by_message_.clear(); |
| 545 | } | ||
| 546 | answer_by_message_[posted_msg.id] = solution.getText(); | ||
| 547 | }); | ||
| 423 | 548 | ||
| 424 | generated = true; | 549 | generated = true; |
| 550 | } else { | ||
| 551 | std::cout << "Too many (" << admissableResults.size() << ") results." << std::endl; | ||
| 552 | } | ||
| 425 | } catch (const std::exception& ex) { | 553 | } catch (const std::exception& ex) { |
| 426 | std::cout << ex.what() << std::endl; | 554 | std::cout << ex.what() << std::endl; |
| 427 | } | 555 | } |
| 428 | 556 | ||
| 429 | std::this_thread::sleep_for(std::chrono::minutes(1)); | 557 | std::cout << "Waiting five seconds then trying again..." << std::endl; |
| 558 | std::this_thread::sleep_for(std::chrono::seconds(5)); | ||
| 430 | } | 559 | } |
| 431 | } | 560 | } |
| 432 | 561 | ||
