Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*------------ -------------- -------- --- ----- --- -- - -
  2. * Libre Blackjack - main function
  3. *
  4. * Copyright (C) 2020 jeremy theler
  5. *
  6. * This file is part of Libre Blackjack.
  7. *
  8. * Libre Blackjack is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Libre Blackjack is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
  20. *------------------- ------------ ---- -------- -- - - -
  21. */
  22. #include <iostream>
  23. #include "conf.h"
  24. #include "base.h"
  25. #include "blackjack.h"
  26. #include "tty.h"
  27. #include "stdinout.h"
  28. #include "internal.h"
  29. int main(int argc, char **argv) {
  30. Dealer *dealer = nullptr;
  31. Player *player = nullptr;
  32. Configuration conf(argc, argv);
  33. if (conf.show_version) {
  34. Libreblackjack::shortversion();
  35. Libreblackjack::copyright();
  36. }
  37. if (conf.show_help) {
  38. Libreblackjack::help(argv[0]);
  39. }
  40. if (conf.show_version || conf.show_help) {
  41. return 0;
  42. }
  43. if (conf.getDealerName() == "blackjack") {
  44. dealer = new Blackjack(conf);
  45. } else {
  46. std::cerr << "Unknown dealer for '" << conf.getDealerName() <<"' game." << std::endl;
  47. return -1;
  48. }
  49. if (conf.getPlayerName() == "tty") {
  50. player = new Tty(conf);
  51. } else if (conf.getPlayerName() == "stdinout" || conf.getPlayerName() == "stdio") {
  52. player = new StdInOut(conf);
  53. } else if (conf.getPlayerName() == "internal") {
  54. player = new Internal(conf);
  55. } else {
  56. std::cerr << "Unknown player '" << conf.getPlayerName() <<".'" << std::endl;
  57. return -1;
  58. }
  59. // assign player to dealer
  60. dealer->setPlayer(player);
  61. // let the action begin!
  62. unsigned int unknownCommands = 0;
  63. dealer->nextAction = Libreblackjack::DealerAction::StartNewHand;
  64. while (!dealer->finished()) {
  65. dealer->deal();
  66. if (player->actionRequired != Libreblackjack::PlayerActionRequired::None) {
  67. unknownCommands = 0;
  68. do {
  69. if (unknownCommands++ > conf.max_incorrect_commands) {
  70. std::cerr << "Too many unknown commands." << std::endl;
  71. return -2;
  72. }
  73. player->play();
  74. } while (dealer->process() <= 0);
  75. }
  76. }
  77. player->info(Libreblackjack::Info::Bye);
  78. dealer->reportPrepare();
  79. dealer->writeReportYAML();
  80. delete player;
  81. delete dealer;
  82. return 0;
  83. }