ScummVM API documentation
othello.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_OTHELLO_H
29 #define GROOVIE_LOGIC_OTHELLO_H
30 
31 #include "common/random.h"
32 #include "common/system.h"
33 
34 namespace Groovie {
35 
36 /*
37  * Othello/Reversi Cursed Coins puzzle in Clandestiny and UHP.
38  */
39 struct Freeboard {
40  int _score;
41  byte _boardstate[8][8]; // 0 is empty, 1 is player, 2 is AI
42 
43  // for sorting an array of pointers
44  friend bool operator<(const Freeboard &a, const Freeboard &b) {
45  return a._score > b._score;
46  }
47 };
48 
49 class OthelloGame {
50 public:
51  OthelloGame(bool easierAi);
52  void run(byte *scriptVariables);
53 
54 private:
55  int scoreEdge(byte (&board)[8][8], int x, int y, int slopeX, int slopeY);
56  int scoreEarlyGame(Freeboard *freeboard);
57  int scoreLateGame(Freeboard *freeboard);
58  int scoreBoard(Freeboard *board);
59  void restart(void);
60  void writeBoardToVars(Freeboard *board, byte *vars);
61  void readBoardStateFromVars(byte *vars);
62  Freeboard getPossibleMove(Freeboard *freeboard, int moveSpot);
63  void checkPossibleMove(Freeboard *board, Freeboard (&boards)[30], int8 **lineSpot, int &numPossibleMoves, int moveSpot, byte player, byte opponent);
64  int getAllPossibleMoves(Freeboard *board, Freeboard (&boards)[30]);
65  int aiRecurse(Freeboard *board, int depth, int parentScore, int opponentBestScore);
66  byte aiDoBestMove(Freeboard *pBoard);
67  void initLines(void);
68  uint makeMove(Freeboard *freeboard, uint8 x, uint8 y);
69  byte getLeader(Freeboard *f);
70  void opInit(byte *vars);
71  void tickBoard();
72  void opPlayerMove(byte *vars);
73  void op3(byte *vars);
74  void opAiMove(byte *vars);
75  void op5(byte *vars);
76 
77  void test();
78  void testMatch(Common::Array<int> moves, bool playerWin);
79 
80  Common::RandomSource _random;
81  byte _flag1;
82  int8 _flag2;
83  const int _depths[60];
84  int _counter;
85  const int _movesLateGame; // this is 52, seems to be a marker of when to change the function pointer to an aleternate scoring algorithm for the late game
86  bool _isLateGame; // used to choose the scoring function, true means scoreLateGame
87  const int8 _lookupPlayer[3]; // used to convert from internal values that represent piece colors to what the script uses in vars, {21, 40, 31}
88  const int8 _scores[3][4];
89  const int8 _edgesScores[112];
90  const int _cornersScores[105];
91  int _isAiTurn;
92  int8 **_lines[64];
93  int8 *_linesStorage[484];
94  int8 _lineStorage[2016];
95  Freeboard _board;
96  bool _easierAi;
97 };
98 
99 } // End of Groovie namespace
100 
101 #endif // GROOVIE_LOGIC_OTHELLO_H
Definition: othello.h:49
Definition: random.h:44
Definition: othello.h:39
Definition: cursor.h:32