[Scummvm-git-logs] scummvm master -> 3a0e9d98fcb69ee201ad5a0bd6b4182868877350

Die4Ever noreply at scummvm.org
Fri Jan 14 08:21:51 UTC 2022


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c3a82f55ba GROOVIE: debug logging for o_keyboardaction
3a0e9d98fc GROOVIE: logic AI puzzles tweaks to easier AI and tests


Commit: c3a82f55bad411e71be017b41df0eaf0b4421604
    https://github.com/scummvm/scummvm/commit/c3a82f55bad411e71be017b41df0eaf0b4421604
Author: Die4Ever (die4ever2005 at gmail.com)
Date: 2022-01-14T02:21:30-06:00

Commit Message:
GROOVIE: debug logging for o_keyboardaction

Changed paths:
    engines/groovie/script.cpp


diff --git a/engines/groovie/script.cpp b/engines/groovie/script.cpp
index 3c0f9d1a191..ff4583e19cb 100644
--- a/engines/groovie/script.cpp
+++ b/engines/groovie/script.cpp
@@ -1025,11 +1025,11 @@ void Script::o_keyboardaction() {
 
 	// Check the typed key
 	if (_kbdChar == val) {
-		debugC(5, kDebugScript, "Groovie::Script: Test key == 0x%02X @0x%04X - match", val, address);
+		debugC(1, kDebugScript, "Groovie::Script: Test key == %c (0x%02X) @0x%04X - match", val, val, address);
 
 		executeInputAction(address);
 	} else {
-		debugC(5, kDebugScript, "Groovie::Script: Test key == 0x%02X @0x%04X", val, address);
+		debugC(5, kDebugScript, "Groovie::Script: Test key == %c (0x%02X) @0x%04X", val, val, address);
 	}
 }
 


Commit: 3a0e9d98fcb69ee201ad5a0bd6b4182868877350
    https://github.com/scummvm/scummvm/commit/3a0e9d98fcb69ee201ad5a0bd6b4182868877350
Author: Die4Ever (die4ever2005 at gmail.com)
Date: 2022-01-14T02:21:36-06:00

Commit Message:
GROOVIE: logic AI puzzles tweaks to easier AI and tests

Changed paths:
    engines/groovie/logic/beehive.cpp
    engines/groovie/logic/beehive.h
    engines/groovie/logic/cake.cpp
    engines/groovie/logic/cake.h
    engines/groovie/logic/cell.cpp
    engines/groovie/logic/pente.cpp
    engines/groovie/logic/pente.h


diff --git a/engines/groovie/logic/beehive.cpp b/engines/groovie/logic/beehive.cpp
index fffd222d4d8..46684556c55 100644
--- a/engines/groovie/logic/beehive.cpp
+++ b/engines/groovie/logic/beehive.cpp
@@ -77,7 +77,7 @@ void BeehiveGame::run(byte *scriptVariables) {
 
 	switch (op) {
 	case 0:	// Init board's hexagons
-		_maxDepth = _easierAi ? 1 : 4;
+		_maxDepth = 4;
 		memset(_beehiveState, 0, HEXCOUNT);
 		_beehiveState[0] = kBeehiveColorYellow;
 		_beehiveState[4] = kBeehiveColorRed;
@@ -126,7 +126,7 @@ void BeehiveGame::run(byte *scriptVariables) {
 	case 4:	// Stauf plays
 		scriptVariables[24] = 1;
 		scriptVariables[4] = 1;
-		sub08(&v24, &v22, hexDifference, &v21, (int8 *)scriptVariables + 16, (int8 *)scriptVariables + 17);
+		calcStaufMove(&v24, &v22, hexDifference, &v21, (int8 *)scriptVariables + 16, (int8 *)scriptVariables + 17);
 		// Execute method tail
 		break;
 
@@ -154,7 +154,7 @@ void BeehiveGame::run(byte *scriptVariables) {
 	case 6:
 		scriptVariables[24] = 1;
 		scriptVariables[4] = 2;
-		sub07(&v24, &v22, hexDifference, &v21, (int8 *)scriptVariables + 16, (int8 *)scriptVariables + 17);
+		calcSamanthaMove(&v24, &v22, hexDifference, &v21, (int8 *)scriptVariables + 16, (int8 *)scriptVariables + 17);
 		// Execute method tail
 		break;
 
@@ -305,16 +305,14 @@ void BeehiveGame::sub04(int8 a1, int8 a2, int8 *scriptVariables) {
 	}
 }
 
-void BeehiveGame::sub07(int8 *a1, int8 *a2, int8 *a3, int8 *a4, int8 *a5, int8 *a6) {
+void BeehiveGame::calcSamanthaMove(int8 *a1, int8 *a2, int8 *a3, int8 *a4, int8 *a5, int8 *a6) {
 	int8 params[4];
 
 	*a4 = 0;
-	int8 depth = 4;
-	if (_easierAi)
-		depth = 1;
+	_maxDepth = 5;// in the original game Samantha did 4 like Stauf
 
-	if (calcMove(_beehiveState, -125, -1, depth, 0, params) == 125
-			&& (*a4 = 1, calcMove(_beehiveState, -125, -1, depth, 1, params) == 125)) {
+	if (calcMove(_beehiveState, -125, -1, _maxDepth, 0, params) == 125
+			&& (*a4 = 1, calcMove(_beehiveState, -125, -1, _maxDepth, 1, params) == 125)) {
 		*a1 = -1;
 		*a2 = -1;
 		for (int i = 0; i < HEXCOUNT; ++i) {
@@ -329,14 +327,25 @@ void BeehiveGame::sub07(int8 *a1, int8 *a2, int8 *a3, int8 *a4, int8 *a5, int8 *
 	}
 }
 
-void BeehiveGame::sub08(int8 *a1, int8 *a2, int8 *a3, int8 *a4, int8 *a5, int8 *a6) {
+void BeehiveGame::calcStaufMove(int8 *a1, int8 *a2, int8 *a3, int8 *a4, int8 *a5, int8 *a6) {
 	int8 params[4];
 
 	*a4 = 0;
-	int8 depth = _maxDepth;
 
-	if (calcMove(_beehiveState, 125, 1, depth, 0, params) == -125
-			&& (*a4 = 1, calcMove(_beehiveState, 125, 1, depth, 1, params) == -125)) {
+	_maxDepth = 4;
+	if (_easierAi) {
+		int numPieces = 0;
+		for (int i = 0; i < HEXCOUNT; ++i)
+			numPieces += _beehiveState[i] != 0;
+
+		if (numPieces < 16)
+			_maxDepth = 3;
+		else
+			_maxDepth = 1;
+	}
+
+	if (calcMove(_beehiveState, 125, 1, _maxDepth, 0, params) == -125
+			&& (*a4 = 1, calcMove(_beehiveState, 125, 1, _maxDepth, 1, params) == -125)) {
 		*a1 = -1;
 		*a2 = -1;
 		for (int i = 0; i < HEXCOUNT; ++i) {
@@ -821,16 +830,6 @@ void BeehiveGame::tests() {
 		/**/ 39, 23
 	}, false);
 
-	// easier AI, early elimination win from darkshoxx
-	_easierAi = true;
-	testGame({/**/ 34, 42, /**/ 34, 41, /**/ 56, 50, /**/ 50, 35, /**/ 35, 43, /**/ 35, 27, /**/ 27, 19, /**/ 27, 20,
-			  /**/ 20, 28, /**/ 56, 44, /**/ 20, 5, /**/ 12, 20, /**/ 43, 50, /**/ 43, 37, /**/ 37, 45, /**/ 28, 20,
-			  /**/ 12, 13, /**/ 51, 38, /**/ 20, 21, /**/ 13, 7, /**/ 7, 1, /**/ 13, 14, /**/ 21, 22, /**/ 41, 23,
-			  /**/ 6, 8, /**/ 42, 24, /**/ 15, 9, /**/ 30, 39, /**/ 39, 53, /**/ 46, 51, /**/ 30, 39, /**/ 30, 31,
-			  /**/ 23, 32, /**/ 3, 1, /**/ 44, 52, /**/ 58, 57, /**/ 24, 33, /**/ 24, 34, /**/ 42, 48, /**/ 49, 55,
-			  /**/ 49, 42},
-			 true);
-
 	// copy the moveset from one of the tests to play it out yourself
 	overrideMoves = {};
 	overrideIndex = 0;
diff --git a/engines/groovie/logic/beehive.h b/engines/groovie/logic/beehive.h
index d123fc7de02..e5d3e2dd955 100644
--- a/engines/groovie/logic/beehive.h
+++ b/engines/groovie/logic/beehive.h
@@ -57,8 +57,8 @@ public:
 private:
 	void sub02(int8 *a1, int8 *a2);
 	void sub04(int8 a1, int8 a2, int8 *scriptVariables);
-	void sub07(int8 *a1, int8 *a2, int8 *a3, int8 *a4, int8 *a5, int8 *a6);
-	void sub08(int8 *a1, int8 *a2, int8 *a3, int8 *a4, int8 *a5, int8 *a6);
+	void calcSamanthaMove(int8 *a1, int8 *a2, int8 *a3, int8 *a4, int8 *a5, int8 *a6);
+	void calcStaufMove(int8 *a1, int8 *a2, int8 *a3, int8 *a4, int8 *a5, int8 *a6);
 	int8 sub11(int8 *beehiveState, int8 *a2, int8 *a3, int8 *a4, int8 a5, int8 a6, int8 *a7);
 	int8 sub12(int8 *beehiveState, int8 a2, int8 a3, int8 a4);
 	int8 sub13(int8 *beehiveState, int8 a2, int8 a3);
diff --git a/engines/groovie/logic/cake.cpp b/engines/groovie/logic/cake.cpp
index 8c7fe63583f..a8afa0b220a 100644
--- a/engines/groovie/logic/cake.cpp
+++ b/engines/groovie/logic/cake.cpp
@@ -107,7 +107,6 @@ void CakeGame::run(byte *scriptVariables) {
 
 	if (lastMove == 9) {
 		// samantha makes a move
-		// TODO: fix graphical bug when samantha makes a move
 		lastMove = aiGetBestMove(6);
 		_hasCheated = true;
 		return;
@@ -126,7 +125,9 @@ void CakeGame::run(byte *scriptVariables) {
 	}
 
 	int depth = 4 + (_hasCheated == false);
-	if (_easierAi)
+	if (_easierAi && _moveCount > 8)
+		depth = 3;
+	else if (_easierAi)
 		depth = 2;
 
 	lastMove = aiGetBestMove(depth);
@@ -292,10 +293,6 @@ int CakeGame::aiRecurse(int search_depth, int parent_score) {
 	return -best_score;
 }
 
-uint CakeGame::rng() {
-	return _random.getRandomNumber(UINT_MAX);
-}
-
 byte CakeGame::aiGetBestMove(int search_depth) {
 	int best_move = 0xffff;
 	uint counter = 1;
@@ -320,7 +317,7 @@ byte CakeGame::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 = _random.getRandomNumber(1000000 - 1);
 				if (r * counter < 1000000) {
 					best_move = move;
 				}
diff --git a/engines/groovie/logic/cake.h b/engines/groovie/logic/cake.h
index 031f5d654be..95859fe546e 100644
--- a/engines/groovie/logic/cake.h
+++ b/engines/groovie/logic/cake.h
@@ -87,7 +87,6 @@ private:
 	bool gameEnded();
 	int getScoreDiff();
 	int aiRecurse(int search_depth, int parent_score);
-	uint rng();
 	byte aiGetBestMove(int search_depth);
 	void testCake();
 	void runCakeTest(uint seed, const char *moves, bool player_win);
diff --git a/engines/groovie/logic/cell.cpp b/engines/groovie/logic/cell.cpp
index 67d4b8180c5..b908d2ad6a4 100644
--- a/engines/groovie/logic/cell.cpp
+++ b/engines/groovie/logic/cell.cpp
@@ -757,7 +757,7 @@ void CellGame::calcMove(int8 color, uint16 depth) {
 			int newDepth;
 
 			newDepth = depths[3 * (depth - 2) + _moveCount % 3];
-			if (_easierAi)
+			if (_easierAi && _moveCount > 7)
 				newDepth = 1;
 
 			_flag2 = true;
diff --git a/engines/groovie/logic/pente.cpp b/engines/groovie/logic/pente.cpp
index e377d3053bf..f0896d443bf 100644
--- a/engines/groovie/logic/pente.cpp
+++ b/engines/groovie/logic/pente.cpp
@@ -230,6 +230,7 @@ void PenteGame::calcTouchingPieces(byte moveX, byte moveY, bool revert) {
 }
 
 void PenteGame::updateScore(byte x, byte y, bool isStauf) {
+	assert(_table->boardState[x][y] == 0);
 	_table->boardState[x][y] = isStauf ? STAUF : PLAYER;
 	uint16 lines = _table->linesTable[x][y][0];
 
@@ -246,6 +247,7 @@ void PenteGame::updateScore(byte x, byte y, bool isStauf) {
 }
 
 void PenteGame::revertScore(byte x, byte y) {
+	assert(_table->boardState[x][y] != 0);
 	bool stauf_turn = _table->boardState[x][y] == STAUF;
 	_table->boardState[x][y] = 0;
 	_table->moveCounter--;
@@ -762,6 +764,13 @@ void PenteGame::test() {
 			/*x=*/15, /*y=*/11, /*x=*/14, /*y=*/10, /*x=*/17, /*y=*/12, /*x=*/16, /*y=*/10, /*x=*/13, /*y=*/10, /*x=*/18, /*y=*/10
 		}, false);
 
+	for (uint32 i = 0; i < 10; i++)
+		testRandomGame(i);
+
+	_easierAi = true;
+	for (uint32 i = 10; i < 20; i++)
+		testRandomGame(i);
+
 	_random.setSeed(oldSeed);
 	warning("finished PenteGame::test()");
 }
@@ -821,4 +830,55 @@ void PenteGame::testGame(uint32 seed, Common::Array<int> moves, bool playerWin)
 	warning("finished PenteGame::testGame(%u, %u, %d)", seed, moves.size(), (int)playerWin);
 }
 
+void PenteGame::testRandomGame(uint32 seed) {
+	byte vars[1024];
+	byte &winner = vars[5];
+	byte &op = vars[4];
+
+	warning("starting PenteGame::testRandomGame(%u)", seed);
+	memset(vars, 0, sizeof(vars));
+	_random.setSeed(seed);
+
+	op = 0;
+	run(vars);
+
+	while (1) {
+		// Player makes a random move
+		int x, y;
+		do {
+			x = _random.getRandomNumber(19);
+			y = _random.getRandomNumber(14);
+		} while (_table != nullptr && _table->boardState[x][y]);
+
+		moveXYToVars(x, y, vars[0], vars[1], vars[2]);
+		op = 1;
+		run(vars);
+
+		do {
+			op = 2;
+			run(vars);
+		} while (winner == 1);
+
+		if (winner)
+			break;
+
+		// Stauf's move
+		op = 3;
+		run(vars);
+
+		do {
+			op = 4;
+			run(vars);
+		} while (winner == 1);
+
+		if (winner)
+			break;
+	}
+
+	if (winner != 2)
+		error("Stauf didn't win, winner: %d", (int)winner);
+
+	warning("finished PenteGame::testRandomGame(%u)", seed);
+}
+
 } // namespace Groovie
diff --git a/engines/groovie/logic/pente.h b/engines/groovie/logic/pente.h
index 4b41e49d3c7..be36bfcc526 100644
--- a/engines/groovie/logic/pente.h
+++ b/engines/groovie/logic/pente.h
@@ -69,6 +69,7 @@ private:
 	uint16 aiGetBestMove(byte depth);
 	void test();
 	void testGame(uint32 seed, Common::Array<int> moves, bool playerWin);
+	void testRandomGame(uint32 seed);
 
 	Common::RandomSource _random;
 




More information about the Scummvm-git-logs mailing list