Blackjack Decision Maker
GamePlay.h
Go to the documentation of this file.
1 /*
2 Copyright 2023 Georgios Titas
3 Copyright 2023 Alexander Douglas
4 Copyright 2023 Jijo Varghese
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 */
9 
10 #ifndef PLAY_GAME_H
11 #define PLAY_GAME_H
12 
13 #include "ToggleLED.h"
14 #include "StrategyEngine.h"
15 #include "Card.h"
16 #include "CallbackLinker.h"
17 
18 /* Number of detection before accumulator
19 determines the card's rank */
20 #define ACCUM_CNTR_THRESH 4
21 
26 class GamePlay : public CallbackLinker
27 {
28 private:
29  /* y increments from left to right (width) */
30  /* x increments from top to bottom (height) */
31  double frame_w, frame_h = 0;
32  double frame_w_midpoint, frame_h_midpoint = 0;
33  bool gameStarted = false;
34  int num_dealer_cards = 0;
35  int num_player_cards = 0;
36  int total_cards = 0;
37  int prev_total_cards = 0;
38  ToggleLED leds;
39  StrategyEngine game_engine;
40 
41  struct Hand{
42  std::vector<int> cards;
43  std::vector<cv::Point_<int>> card_midpoint;
44  };
45  Hand playersHand;
46  Hand dealersHand;
47  /* Helps find index of which card belongs to who */
48  std::vector<bool> whos_hand; /* true == player, false == dealer*/
49 
50  int accum_cntr = 0;
51  std::vector<std::vector<int>> card_accum;
52  std::vector<std::vector<cv::Point_<int>>> card_midpoint_accum;
53 
54  void accumulator(std::vector<int> &cards_names_int, std::vector<cv::Point_<int>> &cards_centre_pts);
55  std::vector<int> convertStr2Int(std::vector<cv::String> &card_names);
56  void whosHand(cv::Point_<int> &card_midpoint);
57  void clear_whosHand();
58  void play_game(std::vector<int> cards_played, std::vector<cv::Point_<int>> cards_centre_pts);
59  void game_reset();
60  CallbackLinker* ledCallback = nullptr;
61  CallbackLinker* strategyCallback = nullptr;
62 
63 public:
64  GamePlay(double res_w, double res_h);
65  ~GamePlay();
66  void nextCallback(AcePlaysUtils &callbackData);
68  void unregisterLEDCallback();
71 };
72 
73 #endif /* PLAY_GAME_H */
Generic abstract Callback Interface class.
Definition: CallbackLinker.h:20
Class to implement the gameplay logic/architecture.
Definition: GamePlay.h:27
void unregisterLEDCallback()
Unregister callback for the LED class.
Definition: GamePlay.cpp:323
void nextCallback(AcePlaysUtils &callbackData)
Implement the nextCallback virtual method to pass information down the pipeline.
Definition: GamePlay.cpp:222
void unregisterStrategyCallback()
Unregister callback for the LED class.
Definition: GamePlay.cpp:340
GamePlay(double res_w, double res_h)
Construct a new Game Play:: Game Play object.
Definition: GamePlay.cpp:18
void registerLEDCallback(CallbackLinker *cb)
Register callback for the LED class.
Definition: GamePlay.cpp:315
~GamePlay()
Destroy the Game Play:: Game Play object.
Definition: GamePlay.cpp:348
void registerStrategyCallback(CallbackLinker *cb)
Register callback for the Strategy Engine class.
Definition: GamePlay.cpp:332
Class implementing the optimum Blackjack strategy.
Definition: StrategyEngine.h:22
Class to control the Rasp Pi pins and toggle LEDs ON/OFF.
Definition: ToggleLED.h:20
Utility structure used by the AcePlays repo for passing necessary information down the processing pip...
Definition: Card.h:80