[Scummvm-git-logs] scummvm master -> 7ee08effe8bbb8d4d8c90870dfeb4fec1e4da5d4
bluegr
bluegr at gmail.com
Fri Oct 22 22:54:54 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
7ee08effe8 GROOVIE: Hook up the cake puzzle like the rest. Some cleanup/renaming
Commit: 7ee08effe8bbb8d4d8c90870dfeb4fec1e4da5d4
https://github.com/scummvm/scummvm/commit/7ee08effe8bbb8d4d8c90870dfeb4fec1e4da5d4
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2021-10-23T01:54:41+03:00
Commit Message:
GROOVIE: Hook up the cake puzzle like the rest. Some cleanup/renaming
Changed paths:
engines/groovie/logic/cake.cpp
engines/groovie/logic/cake.h
engines/groovie/logic/t11hgame.cpp
engines/groovie/logic/t11hgame.h
diff --git a/engines/groovie/logic/cake.cpp b/engines/groovie/logic/cake.cpp
index 0f99c7a40d..ebc4eaa4e7 100644
--- a/engines/groovie/logic/cake.cpp
+++ b/engines/groovie/logic/cake.cpp
@@ -36,8 +36,8 @@ namespace Groovie {
* .
* @see UpdateScores()
*/
-T11hCake::T11hCake(Common::RandomSource &rng) : _random(rng) {
- Restart();
+CakeGame::CakeGame() : _random("CakeGame") {
+ restart();
_map = {};
int numLines = 0;
@@ -46,7 +46,7 @@ T11hCake::T11hCake(Common::RandomSource &rng) : _random(rng) {
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x <= WIDTH - GOAL_LEN; x++) {
for (int z = 0; z < GOAL_LEN; z++) {
- SetLineNum(x + z, y, numLines);
+ setLineNum(x + z, y, numLines);
}
numLines++;
}
@@ -56,7 +56,7 @@ T11hCake::T11hCake(Common::RandomSource &rng) : _random(rng) {
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y <= HEIGHT - GOAL_LEN; y++) {
for (int z = 0; z < GOAL_LEN; z++) {
- SetLineNum(x, y + z, numLines);
+ setLineNum(x, y + z, numLines);
}
numLines++;
}
@@ -66,7 +66,7 @@ T11hCake::T11hCake(Common::RandomSource &rng) : _random(rng) {
for (int y = 0; y <= HEIGHT - GOAL_LEN; y++) {
for (int x = 0; x <= WIDTH - GOAL_LEN; x++) {
for (int z = 0; z < GOAL_LEN; z++) {
- SetLineNum(x + z, y + z, numLines);
+ setLineNum(x + z, y + z, numLines);
}
numLines++;
}
@@ -76,48 +76,51 @@ T11hCake::T11hCake(Common::RandomSource &rng) : _random(rng) {
for (int y = GOAL_LEN - 1; y < HEIGHT; y++) {
for (int x = 0; x <= WIDTH - GOAL_LEN; x++) {
for (int z = 0; z < GOAL_LEN; z++) {
- SetLineNum(x + z, y - z, numLines);
+ setLineNum(x + z, y - z, numLines);
}
numLines++;
}
}
}
-byte T11hCake::OpConnectFour(byte &lastMove) {
+void CakeGame::run(byte *scriptVariables) {
+ byte &lastMove = scriptVariables[1];
+ byte &winner = scriptVariables[3];
+ winner = 0;
+
if (lastMove == 8) {
- Restart();
- return 0;
+ restart();
+ return;
}
if (lastMove == 9) {
// samantha makes a move
// TODO: fix graphical bug when samantha makes a move
- lastMove = AiGetBestMove(6);
+ lastMove = aiGetBestMove(6);
_hasCheated = true;
- return 0;
+ return;
}
- if (IsColumnFull(lastMove)) {
+ if (isColumnFull(lastMove)) {
warning("player tried to place a bon bon in a full column, last_move: %d", (int)lastMove);
lastMove = 10;
- return 0;
+ return;
}
- PlaceBonBon(lastMove);
- byte winner = GetWinner();
+ placeBonBon(lastMove);
+ winner = getWinner();
if (winner) {
- return winner;
+ return;
}
- lastMove = AiGetBestMove(4 + (_hasCheated == false));
- PlaceBonBon(lastMove);
- if (GameEnded())
- return STAUF;
-
- return 0;
+ lastMove = aiGetBestMove(4 + (_hasCheated == false));
+ placeBonBon(lastMove);
+ if (gameEnded()) {
+ winner = STAUF;
+ }
}
-void T11hCake::Restart() {
+void CakeGame::restart() {
_playerProgress = {};
_staufProgress = {};
memset(_boardState, 0, sizeof(_boardState));
@@ -129,7 +132,7 @@ void T11hCake::Restart() {
_staufProgress._score = NUM_LINES;
}
-void T11hCake::SetLineNum(uint x, uint y, uint index) {
+void CakeGame::setLineNum(uint x, uint y, uint index) {
assert(x < WIDTH);
assert(y < HEIGHT);
byte slot = _map.lengths[x][y]++;
@@ -138,11 +141,11 @@ void T11hCake::SetLineNum(uint x, uint y, uint index) {
_map.indecies[x][y][slot] = index;
}
-bool T11hCake::IsColumnFull(byte column) {
+bool CakeGame::isColumnFull(byte column) {
return _columnHeights[column] >= HEIGHT;
}
-T11hCake::PlayerProgress &T11hCake::GetPlayerProgress(bool stauf) {
+CakeGame::PlayerProgress &CakeGame::getPlayerProgress(bool stauf) {
if (stauf)
return _staufProgress;
else
@@ -158,9 +161,9 @@ T11hCake::PlayerProgress &T11hCake::GetPlayerProgress(bool stauf) {
* .
* .
*/
-void T11hCake::UpdateScores(byte x, bool revert) {
+void CakeGame::updateScores(byte x, bool revert) {
bool stauf = _moveCount % 2;
- PlayerProgress &pp = GetPlayerProgress(stauf);
+ PlayerProgress &pp = getPlayerProgress(stauf);
byte y = _columnHeights[x] - 1;
@@ -186,7 +189,7 @@ void T11hCake::UpdateScores(byte x, bool revert) {
pp._score += WIN_SCORE * mult;
}
else {
- PlayerProgress &pp2 = GetPlayerProgress(!stauf);
+ PlayerProgress &pp2 = getPlayerProgress(!stauf);
int len2 = pp2._linesCounters[index];
if (len == 0) {
// we started a new line, take away the points the opponent had from this line since we ruined it for them
@@ -200,29 +203,29 @@ void T11hCake::UpdateScores(byte x, bool revert) {
}
}
-void T11hCake::PlaceBonBon(byte x) {
+void CakeGame::placeBonBon(byte x) {
byte y = _columnHeights[x]++;
if (_moveCount % 2)
_boardState[x][y] = STAUF;
else
_boardState[x][y] = PLAYER;
- UpdateScores(x);
+ updateScores(x);
_moveCount++;
}
-void T11hCake::RevertMove(byte x) {
+void CakeGame::revertMove(byte x) {
// PlaceBonBon in reverse, this is used for the AI's recursion rollback
_moveCount--;
- UpdateScores(x, true);
+ updateScores(x, true);
byte y = --_columnHeights[x];
_boardState[x][y] = 0;
}
-byte T11hCake::GetWinner() {
+byte CakeGame::getWinner() {
if (_playerProgress._score >= WIN_SCORE)
return PLAYER;
@@ -232,8 +235,8 @@ byte T11hCake::GetWinner() {
return 0;
}
-bool T11hCake::GameEnded() {
- if (GetWinner())
+bool CakeGame::gameEnded() {
+ if (getWinner())
return true;
if (_moveCount >= WIDTH * HEIGHT)
@@ -242,25 +245,25 @@ bool T11hCake::GameEnded() {
return false;
}
-int T11hCake::GetScoreDiff() {
+int CakeGame::getScoreDiff() {
if (_moveCount % 2)
return _staufProgress._score - _playerProgress._score;
else
return _playerProgress._score - _staufProgress._score;
}
-int T11hCake::AiRecurse(int search_depth, int parent_score) {
+int CakeGame::aiRecurse(int search_depth, int parent_score) {
int best_score = 0x7fffffff;
for (byte move = 0; move < WIDTH; move++) {
- if (IsColumnFull(move))
+ if (isColumnFull(move))
continue;
- PlaceBonBon(move);
- int score = GetScoreDiff();
- if (search_depth > 1 && !GameEnded())
- score = AiRecurse(search_depth - 1, best_score);
- RevertMove(move);
+ placeBonBon(move);
+ int score = getScoreDiff();
+ if (search_depth > 1 && !gameEnded())
+ score = aiRecurse(search_depth - 1, best_score);
+ revertMove(move);
if (score < best_score)
best_score = score;
@@ -273,27 +276,27 @@ int T11hCake::AiRecurse(int search_depth, int parent_score) {
return -best_score;
}
-uint T11hCake::Rng() {
+uint CakeGame::rng() {
return _random.getRandomNumber(UINT_MAX);
}
-byte T11hCake::AiGetBestMove(int search_depth) {
+byte CakeGame::aiGetBestMove(int search_depth) {
int best_move = 0xffff;
uint counter = 1;
for (int best_score = 0x7fffffff; best_score > 999999 && search_depth > 1; search_depth--) {
for (byte move = 0; move < WIDTH; move++) {
- if (IsColumnFull(move))
+ if (isColumnFull(move))
continue;
- PlaceBonBon(move);
- if (GetWinner()) {
- RevertMove(move);
+ placeBonBon(move);
+ if (getWinner()) {
+ revertMove(move);
return move;
}
- int score = AiRecurse(search_depth - 1, best_score);
- RevertMove(move);
+ int score = aiRecurse(search_depth - 1, best_score);
+ revertMove(move);
if (score < best_score) {
counter = 1;
best_move = move;
@@ -301,7 +304,7 @@ byte T11hCake::AiGetBestMove(int search_depth) {
} else if (best_score == score) {
// rng is only used on moves with equal scores
counter++;
- uint r = Rng() % 1000000;
+ uint r = rng() % 1000000;
if (r * counter < 1000000) {
best_move = move;
}
diff --git a/engines/groovie/logic/cake.h b/engines/groovie/logic/cake.h
index b75220a64b..168d51c45f 100644
--- a/engines/groovie/logic/cake.h
+++ b/engines/groovie/logic/cake.h
@@ -31,11 +31,10 @@ namespace Groovie {
/*
* Connect Four puzzle, the cake in the dining room
*/
-class T11hCake {
+class CakeGame {
public:
- T11hCake(Common::RandomSource &rng);
-
- byte OpConnectFour(byte &lastMove);
+ CakeGame();
+ void run(byte *scriptVariables);
private:
static const int WIDTH = 8;
@@ -46,7 +45,7 @@ private:
static const byte PLAYER = 2;
static const int NUM_LINES = 107;//!< how many potential victory lines there are
- Common::RandomSource &_random;
+ Common::RandomSource _random;
//! ID numbers for all of the potential victory lines for each spot on the board
struct LinesMappings {
@@ -71,19 +70,19 @@ private:
LinesMappings _map;//!< ID numbers for all of the potential victory lines for each spot on the board
- void Restart();
- void SetLineNum(uint x, uint y, uint index);
- bool IsColumnFull(byte column);
- PlayerProgress &GetPlayerProgress(bool stauf);
- void UpdateScores(byte x, bool revert = false);
- void PlaceBonBon(byte x);
- void RevertMove(byte x);
- byte GetWinner();
- bool GameEnded();
- int GetScoreDiff();
- int AiRecurse(int search_depth, int parent_score);
- uint Rng();
- byte AiGetBestMove(int search_depth);
+ void restart();
+ void setLineNum(uint x, uint y, uint index);
+ bool isColumnFull(byte column);
+ PlayerProgress &getPlayerProgress(bool stauf);
+ void updateScores(byte x, bool revert = false);
+ void placeBonBon(byte x);
+ void revertMove(byte x);
+ byte getWinner();
+ bool gameEnded();
+ int getScoreDiff();
+ int aiRecurse(int search_depth, int parent_score);
+ uint rng();
+ byte aiGetBestMove(int search_depth);
};
} // End of Groovie namespace
diff --git a/engines/groovie/logic/t11hgame.cpp b/engines/groovie/logic/t11hgame.cpp
index f6d79aeac8..ab654f613f 100644
--- a/engines/groovie/logic/t11hgame.cpp
+++ b/engines/groovie/logic/t11hgame.cpp
@@ -35,7 +35,7 @@
namespace Groovie {
T11hGame::T11hGame(byte *scriptVariables)
- : _random("GroovieT11hGame"), _scriptVariables(scriptVariables), _cake(NULL) {
+ : _random("GroovieT11hGame"), _scriptVariables(scriptVariables) {
}
T11hGame::~T11hGame() {
@@ -45,7 +45,7 @@ void T11hGame::handleOp(uint8 op) {
switch (op) {
case 1:
debugC(1, kDebugScript, "Groovie::Script Op42 (0x%02X): T11H Connect four in the dining room. (tb.grv)", op);
- opConnectFour();
+ _cake.run(_scriptVariables);
break;
case 2:
@@ -152,30 +152,6 @@ void T11hGame::opMouseTrap() {
}
}
-void T11hGame::opConnectFour() {
- byte &last_move = _scriptVariables[1];
- byte &winner = _scriptVariables[3];
- winner = 0;
-
- if (_cake == NULL) {
- clearAIs();
- _cake = new T11hCake(_random);
- }
-
- winner = _cake->OpConnectFour(last_move);
-
- if (winner) {
- clearAIs();
- }
-}
-
-void T11hGame::clearAIs() {
- if (_cake != NULL) {
- delete _cake;
- _cake = NULL;
- }
-}
-
void T11hGame::opPente() {
// FIXME: properly implement Pente game (the final puzzle)
// for now just auto-solve the puzzle so the player can continue
diff --git a/engines/groovie/logic/t11hgame.h b/engines/groovie/logic/t11hgame.h
index c78cee7b5b..e1130bb8e4 100644
--- a/engines/groovie/logic/t11hgame.h
+++ b/engines/groovie/logic/t11hgame.h
@@ -26,16 +26,13 @@
#include "common/textconsole.h"
#include "common/random.h"
#include "groovie/logic/beehive.h"
+#include "groovie/logic/cake.h"
#include "groovie/logic/gallery.h"
namespace Groovie {
class GroovieEngine;
-#ifdef ENABLE_GROOVIE2
-class T11hCake;
-#endif
-
class T11hGame {
public:
#ifdef ENABLE_GROOVIE2
@@ -48,18 +45,12 @@ private:
Common::RandomSource _random;
void opMouseTrap();
- void opConnectFour();
void opPente();
- void opGallery();
void opTriangle();
- byte opGalleryAI(byte *pieceStatus, int depth);
-
- void clearAIs();
-
- T11hCake *_cake;
byte *_scriptVariables;
+ CakeGame _cake;
BeehiveGame _beehive;
GalleryGame _gallery;
#endif
More information about the Scummvm-git-logs
mailing list