[Scummvm-git-logs] scummvm master -> 4539bfa674eec021767c7bdb3b4eed3dae3bf37b

sev- sev at scummvm.org
Fri Oct 29 11:18:13 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:
4539bfa674 GROOVIE: Implemented few WineRack puzzle methods


Commit: 4539bfa674eec021767c7bdb3b4eed3dae3bf37b
    https://github.com/scummvm/scummvm/commit/4539bfa674eec021767c7bdb3b4eed3dae3bf37b
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-29T14:17:39+03:00

Commit Message:
GROOVIE: Implemented few WineRack puzzle methods

Changed paths:
    engines/groovie/logic/winerack.cpp
    engines/groovie/logic/winerack.h


diff --git a/engines/groovie/logic/winerack.cpp b/engines/groovie/logic/winerack.cpp
index e791daea4b..575145cceb 100644
--- a/engines/groovie/logic/winerack.cpp
+++ b/engines/groovie/logic/winerack.cpp
@@ -139,7 +139,44 @@ void WineRackGame::placeBottle(byte pos, byte val) {
 	_wineRackGrid[pos] = val;
 }
 
-byte WineRackGame::calculateNextMove(byte op) {
+int8 WineRackGame::calculateNextMove(byte player) {
+	int8 moves1[24];
+	int8 moves2[24];
+	byte playerIndex = (player == 1) + 1;
+
+	if (!_totalBottles)
+		return randomMoveStart();
+	if (_totalBottles == 1)
+		return randomMoveStart2();
+
+	sub05(player, moves1);
+	sub05(playerIndex, moves2);
+
+	int8 result = sub06(moves1, moves2);
+
+	if (result == -1)
+		return findEmptySpot();
+
+	return result;
+}
+
+int8 WineRackGame::findEmptySpot() {
+	int8 result = 0;
+
+	while (_wineRackGrid[result]) {
+		if (result == 99)
+			return 100;
+		else
+			++result;
+	}
+
+	return result;
+}
+
+void WineRackGame::sub05(int8 player, int8 *moves) {
+}
+
+int8 WineRackGame::sub06(int8 *moves1, int8 *moves2) {
 	return 0;
 }
 
@@ -158,7 +195,41 @@ uint32 WineRackGame::sub09() {
 	return 0;
 }
 
-void WineRackGame::sub10(int8 a1, int8 a2, int a3, int a4, int *a5) {
+void WineRackGame::sub10(int8 endPos, int8 pos, int unused, int player, int *val) {
+	int8 candidates[8];
+
+	if (*val)
+		return;
+
+	if (wineRackLogicTable[12 * pos + player] == -1) {
+		*val = 1;
+
+		return;
+	}
+
+	sub11(pos, candidates);
+
+	for (int i = 0; candidates[i] != 100; i++) {
+		int8 nextPos = candidates[i];
+
+		if (endPos != nextPos)
+			sub10(pos, nextPos, unused, player, val);
+	}
+}
+
+void WineRackGame::sub11(int8 pos, int8 *candidates) {
+	int cnt = 0;
+
+	_wineRackGrid2[pos] = 1;
+
+	for (int i = 0; i < 6; i++) {
+		int8 val = wineRackLogicTable[12 * pos + i];
+
+		if (!_wineRackGrid2[val] && _wineRackGrid[pos] == _wineRackGrid[val])
+			candidates[cnt++] = val;
+	}
+
+	candidates[cnt] = 100;
 }
 
 uint32 WineRackGame::sub12() {
@@ -176,6 +247,18 @@ uint32 WineRackGame::sub12() {
 	return 0;
 }
 
+int8 WineRackGame::randomMoveStart() {
+	const int8 moves[] = { 44, 45, 54, 55 };
+
+	return moves[_random.getRandomNumber(3)];
+}
+
+int8 WineRackGame::randomMoveStart2() {
+	const int8 moves[] = { 25, 26, 63, 64 };
+
+	return moves[_random.getRandomNumber(3)];
+}
+
 namespace {
 
 const int8 wineRackLogicTable[1200] = {
diff --git a/engines/groovie/logic/winerack.h b/engines/groovie/logic/winerack.h
index 59031c622e..a3e7f09118 100644
--- a/engines/groovie/logic/winerack.h
+++ b/engines/groovie/logic/winerack.h
@@ -41,10 +41,16 @@ public:
 private:
 	void initGrid(byte difficulty);
 	void placeBottle(byte pos, byte val);
-	byte calculateNextMove(byte op);
+	int8 calculateNextMove(byte op);
+	int8 findEmptySpot();
+	void sub05(int8 player, int8 *moves);
+	int8 sub06(int8 *moves1, int8 *moves2);
 	uint32 sub09();
-	void sub10(int8 a1, int8 a2, int a3, int a4, int *a5);
+	void sub10(int8 endPos, int8 pos, int unused, int player, int *val);
+	void sub11(int8 pos, int8 *candidates);
 	uint32 sub12();
+	int8 randomMoveStart();
+	int8 randomMoveStart2();
 
 	int _totalBottles;
 	byte _wineRackGrid[100];




More information about the Scummvm-git-logs mailing list