ScummVM API documentation
cake.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  *
21  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, MojoTouch has exclusively licensed
23  * this code on November 10th, 2021, to be use in closed-source products.
24  * Therefore, any contributions (commits) to it will also be dual-licensed.
25  *
26  */
27 
28 #ifndef GROOVIE_LOGIC_CAKE_H
29 #define GROOVIE_LOGIC_CAKE_H
30 
31 #include "common/random.h"
32 #include "common/system.h"
33 
34 namespace Groovie {
35 
36 /*
37  * Cake (Connect Four) puzzle in the dining room (tb.grv)
38  */
39 class CakeGame {
40 public:
41  CakeGame(bool easierAi);
42  void run(byte *scriptVariables);
43 
44 private:
45  static const int WIDTH = 8;
46  static const int HEIGHT = 7;
47  static const int GOAL_LEN = 4;
48  static const int WIN_SCORE = 1000000;
49  static const byte STAUF = 1;
50  static const byte PLAYER = 2;
51  static const int NUM_LINES = 107;
52 
53  Common::RandomSource _random;
54 
56  struct LinesMappings {
57  byte lengths[WIDTH][HEIGHT];
58  byte indecies[WIDTH][HEIGHT][GOAL_LEN * GOAL_LEN];
59  };
60 
62  struct PlayerProgress {
63  int _score;
64  int _linesCounters[NUM_LINES];
65  };
66 
67  PlayerProgress _playerProgress;
68  PlayerProgress _staufProgress;
69 
70  byte _boardState[WIDTH][HEIGHT];
71  byte _columnHeights[WIDTH];
72 
73  int _moveCount;
74  bool _hasCheated;
75 
76  LinesMappings _map;
77  bool _easierAi;
78 
79  void restart();
80  void setLineNum(uint x, uint y, uint index);
81  bool isColumnFull(byte column);
82  PlayerProgress &getPlayerProgress(bool stauf);
83  void updateScores(byte x, bool revert = false);
84  void placeBonBon(byte x);
85  void revertMove(byte x);
86  byte getWinner();
87  bool gameEnded();
88  int getScoreDiff();
89  int aiRecurse(int search_depth, int parent_score);
90  byte aiGetBestMove(int search_depth);
91  void testCake();
92  void runCakeTest(uint seed, const char *moves, bool player_win);
93  void runCakeTestNoAi(const char *moves, bool player_win, bool draw);
94 };
95 
96 } // End of Groovie namespace
97 
98 #endif // GROOVIE_LOGIC_CAKE_H
Definition: cake.h:39
Definition: random.h:44
Definition: cursor.h:32