[Scummvm-git-logs] scummvm master -> 7b2150af508ae143493b8c26ef4aeb74a77a3799
Die4Ever
30947252+Die4Ever at users.noreply.github.com
Sun Oct 31 01:36:16 UTC 2021
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:
84937df1f8 GROOVIE: pente refactor run function
7b2150af50 GROOVIE: pente reorder arguments
Commit: 84937df1f8d784698606902cc54bd8e76f4b9c6c
https://github.com/scummvm/scummvm/commit/84937df1f8d784698606902cc54bd8e76f4b9c6c
Author: Die4Ever (die4ever2005 at gmail.com)
Date: 2021-10-30T19:53:45-05:00
Commit Message:
GROOVIE: pente refactor run function
Changed paths:
engines/groovie/logic/pente.cpp
engines/groovie/logic/pente.h
diff --git a/engines/groovie/logic/pente.cpp b/engines/groovie/logic/pente.cpp
index c32bc2d1eb..a3c9927734 100644
--- a/engines/groovie/logic/pente.cpp
+++ b/engines/groovie/logic/pente.cpp
@@ -323,7 +323,7 @@ uint PenteGame::scoreCapture(byte y, byte x) {
return bitMask;
}
-void PenteGame::animateCapture(short move, byte *bitMaskG, short *param_3, short *param_4) {
+void PenteGame::animateCapture(short move, byte *bitMaskG, short *outCapture1, short *outCapture2) {
byte x;
byte y;
@@ -342,42 +342,42 @@ void PenteGame::animateCapture(short move, byte *bitMaskG, short *param_3, short
short sVar4;
switch (bVar3) {
case 0:
- *param_3 = (x + 2) * 0xf - (uint16)y;
- *param_4 = ((uint16)x * 0xf - (uint16)y) + 0x2e;
+ *outCapture1 = (x + 2) * 0xf - (uint16)y;
+ *outCapture2 = ((uint16)x * 0xf - (uint16)y) + 0x2e;
return;
case 1:
- *param_3 = (x + 1) * 0xf - (uint16)y;
- *param_4 = ((uint16)x * 0xf - (uint16)y) + 0x10;
+ *outCapture1 = (x + 1) * 0xf - (uint16)y;
+ *outCapture2 = ((uint16)x * 0xf - (uint16)y) + 0x10;
return;
case 2:
sVar4 = (uint16)x * 0xf - (uint16)y;
- *param_3 = sVar4;
- *param_4 = sVar4 + -0xe;
+ *outCapture1 = sVar4;
+ *outCapture2 = sVar4 + -0xe;
return;
case 3:
sVar4 = (uint16)x * 0xf - (uint16)y;
- *param_3 = sVar4 + -1;
- *param_4 = sVar4 + -0x10;
+ *outCapture1 = sVar4 + -1;
+ *outCapture2 = sVar4 + -0x10;
return;
case 4:
sVar4 = (uint16)x * 0xf - (uint16)y;
- *param_3 = sVar4 + -2;
- *param_4 = sVar4 + -0x12;
+ *outCapture1 = sVar4 + -2;
+ *outCapture2 = sVar4 + -0x12;
return;
case 5:
sVar4 = (uint16)x * 0xf - (uint16)y;
- *param_3 = sVar4 + 0xd;
- *param_4 = sVar4 + 0xc;
+ *outCapture1 = sVar4 + 0xd;
+ *outCapture2 = sVar4 + 0xc;
return;
case 6:
sVar4 = (uint16)x * 0xf - (uint16)y;
- *param_3 = sVar4 + 0x1c;
- *param_4 = sVar4 + 0x2a;
+ *outCapture1 = sVar4 + 0x1c;
+ *outCapture2 = sVar4 + 0x2a;
return;
case 7:
sVar4 = (uint16)x * 0xf - (uint16)y;
- *param_3 = sVar4 + 0x1d;
- *param_4 = sVar4 + 0x2c;
+ *outCapture1 = sVar4 + 0x1d;
+ *outCapture2 = sVar4 + 0x2c;
}
return;
}
@@ -583,12 +583,57 @@ void moveXYToVars(uint x, uint y, byte &var0, byte &var1, byte &var2) {
moveToVars(move, var0, var1, var2);
}
-void PenteGame::run(byte *vars) {
- uint16 uVar1;
- int iVar2;
- byte ai_depth;
- short local_2;
+void PenteGame::animateCapturesCheckWinner(byte *vars) {
+ if (_animateCapturesBitMask != 0 && _nextCapturedSpot < 0) {
+ short capturedSpot;
+ animateCapture(_previousMove, &_animateCapturesBitMask, &capturedSpot, &_nextCapturedSpot);
+ vars[5] = 1;
+ moveToVars(capturedSpot, vars[0], vars[1], vars[2]);
+ return;
+ }
+ if (_animateCapturesBitMask != 0 || _nextCapturedSpot > -1) {
+ vars[0] = (byte)((int)_nextCapturedSpot / 100);
+ vars[1] = (byte)((int)(_nextCapturedSpot % 100) / 10);
+ vars[2] = (byte)(_nextCapturedSpot % 10);
+ _nextCapturedSpot = -1;
+ vars[5] = 1;
+ return;
+ }
+
+ if (_table->playerScore >= WIN_SCORE || _table->moveCounter >= _table->boardSize)
+ vars[5] = 3; // player wins
+ else if (_table->staufScore >= WIN_SCORE)
+ vars[5] = 2; // Stauf wins
+ else {
+ // the match continues
+ vars[5] = 0;
+ return;
+ }
+
+ penteDeInit();
+}
+
+void PenteGame::opQueryPiece(byte *vars) {
+ // this runs multiple times to check if pieces belong to stauf or the player?
+ // this happens when you close the gamebook
+ byte x, y;
+ varsMoveToXY(vars[0], vars[1], vars[2], x, y);
+ byte piece = _table->boardState[x][y];
+ if (piece == 0) {
+ vars[3] = 0;
+ return;
+ }
+ if (piece == 0x4f) {
+ vars[3] = 2;
+ return;
+ }
+ if (piece != 0x58) {
+ return;
+ }
+ vars[3] = 1;
+}
+void PenteGame::run(byte *vars) {
byte op = vars[4];
if (_table == NULL && op != 0) {
penteInit(20, 15, 5);
@@ -600,100 +645,52 @@ void PenteGame::run(byte *vars) {
penteDeInit();
return;
case 1:
- _globalPlayerMove = varsMoveToXY(vars[0], vars[1], vars[2], _globalX, _globalY);
- debugC(kDebugLogic, "player moved to %d, %d", (int)_globalX, (int)_globalY);
- updateScore(_globalY, _globalX, _table->moveCounter % 2);
- _global2 = scoreCapture(_globalY, _globalX);
+ byte x, y;
+ _previousMove = varsMoveToXY(vars[0], vars[1], vars[2], x, y);
+ debugC(kDebugLogic, "player moved to %d, %d", (int)x, (int)y);
+ updateScore(y, x, _table->moveCounter % 2);
+ _animateCapturesBitMask = scoreCapture(y, x);
return;
case 2:
case 4:
- if (_global2 != '\0') {
- if (_global1 < 0) {
- animateCapture(_globalPlayerMove, (byte *)&_global2, &local_2, &_global1);
- vars[5] = 1;
- moveToVars(local_2, vars[0], vars[1], vars[2]);
- return;
- }
- LAB_00412da4:
- vars[0] = (byte)((int)_global1 / 100);
- vars[1] = (byte)((int)(_global1 % 100) / 10);
- iVar2 = (int)_global1;
- vars[2] = (byte)(iVar2 % 10);
- _global1 = -1;
- vars[5] = 1;
- return;
- }
- if (-1 < _global1)
- goto LAB_00412da4;
- if (_table->playerScore < WIN_SCORE) {
- if ((_table->staufScore < WIN_SCORE) &&
- (uVar1 = _table->moveCounter)) {
- vars[5] = 0;
- return;
- }
- if (_table->playerScore < WIN_SCORE) {
- vars[5] = 2; // Stauf wins
- if (_table->staufScore < WIN_SCORE) {
- vars[5] = 4; // player wins because the board is full?
- }
- goto DEALLOC;
- }
- }
- vars[5] = 3; // player wins
- DEALLOC:
- penteDeInit();
+ animateCapturesCheckWinner(vars);
return;
case 3:
break;
case 5:
- // asking Samantha to make a move? this does a bunch of queries to check if pieces belong to stauf or the player?
- byte x, y;
- varsMoveToXY(vars[0], vars[1], vars[2], x, y);
- ai_depth = _table->boardState[x][y];
- if (ai_depth == 0) {
- vars[3] = 0;
- return;
- }
- if (ai_depth == 0x4f) {
- vars[3] = 2;
- return;
- }
- if (ai_depth != 0x58) {
- return;
- }
- vars[3] = 1;
+ opQueryPiece(vars);
default:
return;
}
- ai_depth = vars[6];
+
+ byte ai_depth = vars[6];
if (ai_depth == 0) {
ai_depth = 3;
+ } else if (ai_depth == 1) {
+ ai_depth = 4;
} else {
- if (ai_depth == 1) {
- ai_depth = 4;
- } else {
- if (ai_depth != 2)
- goto LAB_00412e85;
- ai_depth = 5;
- }
+ ai_depth = 5;
}
- _globalPlayerMove = aiGetBestMove(0, 0, 0, ai_depth);
-LAB_00412e85:
- aiMoveToXY(_globalPlayerMove, _globalX, _globalY);
- debugC(kDebugLogic, "Stauf moved to %d, %d", (int)_globalX, (int)_globalY);
- updateScore(_globalY, _globalX, _table->moveCounter % 2);
- _global2 = scoreCapture(_globalY, _globalX);
- _globalPlayerMove = ((uint16)_globalX * 0xf - (uint16)_globalY) + 0xe;
- moveXYToVars(_globalX, _globalY, vars[0], vars[1], vars[2]);
+
+ if (ai_depth != 2)
+ _previousMove = aiGetBestMove(0, 0, 0, ai_depth);
+ else
+ warning("pente unknown else");
+
+ byte x, y;
+ aiMoveToXY(_previousMove, x, y);
+ debugC(kDebugLogic, "Stauf moved to %d, %d", (int)x, (int)y);
+ updateScore(y, x, _table->moveCounter % 2);
+ _animateCapturesBitMask = scoreCapture(y, x);
+ _previousMove = ((uint16)x * 0xf - (uint16)y) + 0xe;
+ moveXYToVars(x, y, vars[0], vars[1], vars[2]);
}
PenteGame::PenteGame() : _random("PenteGame") {
_table = NULL;
- _global1 = -1;
- _globalY = 0;
- _globalX = 0;
- _global2 = 0;
- _globalPlayerMove = 0;
+ _nextCapturedSpot = -1;
+ _animateCapturesBitMask = 0;
+ _previousMove = 0;
#if 0
test();
#endif
diff --git a/engines/groovie/logic/pente.h b/engines/groovie/logic/pente.h
index 87eb1689c2..26d505ffc9 100644
--- a/engines/groovie/logic/pente.h
+++ b/engines/groovie/logic/pente.h
@@ -41,6 +41,9 @@ public:
void run(byte *vars);
private:
+ void animateCapturesCheckWinner(byte *vars);
+ void opQueryPiece(byte *vars);
+
void addLine(int x, int y, int linesCounter);
void buildLookupTable();
void penteDeInit();
@@ -52,7 +55,7 @@ private:
void revertScore(byte y, byte x);
byte scoreCaptureSingle(byte x, byte y, int slopeX, int slopeY);
uint scoreCapture(byte y, byte x);
- void animateCapture(short param_1, byte *param_2, short *param_3, short *param_4);
+ void animateCapture(short param_1, byte *param_2, short * outMove, short *param_4);
void revertCapture(byte y, byte x, byte y2);
int scoreMoveAndRevert(byte x, byte y, char depth, int parentScore, bool &gameOver);
int scoreMoveAndRevert(byte x, byte y, char depth, int parent_score);
@@ -64,11 +67,9 @@ private:
Common::RandomSource _random;
- byte _globalY;
- byte _globalX;
- char _global2;
- short _globalPlayerMove;
- short _global1;
+ byte _animateCapturesBitMask;
+ short _previousMove;
+ short _nextCapturedSpot;
penteTable *_table;
};
Commit: 7b2150af508ae143493b8c26ef4aeb74a77a3799
https://github.com/scummvm/scummvm/commit/7b2150af508ae143493b8c26ef4aeb74a77a3799
Author: Die4Ever (die4ever2005 at gmail.com)
Date: 2021-10-30T20:35:50-05:00
Commit Message:
GROOVIE: pente reorder arguments
Changed paths:
engines/groovie/logic/pente.cpp
engines/groovie/logic/pente.h
diff --git a/engines/groovie/logic/pente.cpp b/engines/groovie/logic/pente.cpp
index a3c9927734..8187a5496d 100644
--- a/engines/groovie/logic/pente.cpp
+++ b/engines/groovie/logic/pente.cpp
@@ -139,9 +139,9 @@ uint &PenteGame::getPlayerTable(bool staufTurn, pentePlayerTable *&pt) {
return staufTurn ? _table->staufScore : _table->playerScore;
}
-void PenteGame::scoreLine(uint16 lineIndex, bool stauf_turn, bool revert) {
+void PenteGame::scoreLine(uint16 lineIndex, bool isStaufTurn, bool revert) {
pentePlayerTable *playerTable;
- uint &score = getPlayerTable(stauf_turn, playerTable);
+ uint &score = getPlayerTable(isStaufTurn, playerTable);
int lineLength, mult;
if (revert) {
@@ -156,12 +156,12 @@ void PenteGame::scoreLine(uint16 lineIndex, bool stauf_turn, bool revert) {
score = (int)score + (int)WIN_SCORE * mult;
} else {
pentePlayerTable *opponentTable;
- uint &opponentScore = getPlayerTable(!stauf_turn, opponentTable);
+ uint &opponentScore = getPlayerTable(!isStaufTurn, opponentTable);
int opponentLineLength = opponentTable->lines[lineIndex];
if (lineLength == 0) {
opponentScore += (-(1 << ((byte)opponentLineLength & 0x1f))) * mult;
if (_table->lineLength - opponentLineLength == 1) {
- if (stauf_turn)
+ if (isStaufTurn)
_table->playerLines -= mult;
else
_table->staufLines -= mult;
@@ -171,7 +171,7 @@ void PenteGame::scoreLine(uint16 lineIndex, bool stauf_turn, bool revert) {
score += (1 << ((byte)lineLength & 0x1f)) * mult;
if (_table->lineLength - lineLength == 2) {
byte b;
- if (stauf_turn)
+ if (isStaufTurn)
b = (_table->staufLines += mult);
else
b = (_table->playerLines += mult);
@@ -222,23 +222,23 @@ void PenteGame::calcTouchingPieces(byte moveX, byte moveY, bool revert) {
}
}
-void PenteGame::updateScore(byte move_y, byte move_x, bool stauf_turn) {
- _table->boardState[move_x][move_y] = stauf_turn ? 88 : 79;
- uint16 lines = _table->linesTable[move_x][move_y][0];
+void PenteGame::updateScore(byte x, byte y, bool stauf_turn) {
+ _table->boardState[x][y] = stauf_turn ? 88 : 79;
+ uint16 lines = _table->linesTable[x][y][0];
for (int i = 1; i <= lines; i++) {
- uint16 lineIndex = _table->linesTable[move_x][move_y][i];
+ uint16 lineIndex = _table->linesTable[x][y][i];
scoreLine(lineIndex, stauf_turn, false);
}
if (_table->calcTouchingPieces != 0) {
- calcTouchingPieces(move_x, move_y, false);
+ calcTouchingPieces(x, y, false);
}
_table->moveCounter++;
}
-void PenteGame::revertScore(byte y, byte x) {
+void PenteGame::revertScore(byte x, byte y) {
bool stauf_turn = _table->boardState[x][y] == 88;
_table->boardState[x][y] = 0;
_table->moveCounter--;
@@ -280,8 +280,8 @@ byte PenteGame::scoreCaptureSingle(byte x, byte y, int slopeX, int slopeY) {
if (boardState[x1][y1] != captive || boardState[x2][y2] != captive)
return 0;
- revertScore(y1, x1);
- revertScore(y2, x2);
+ revertScore(x1, y1);
+ revertScore(x2, y2);
return 1;
}
@@ -298,7 +298,7 @@ Slope slopes[] = {{1, 0},
{0, -1},
{1, -1}};
-uint PenteGame::scoreCapture(byte y, byte x) {
+uint PenteGame::scoreCapture(byte x, byte y) {
byte bitMask = 0;
bool isStauf = _table->boardState[x][y] == 88;
@@ -382,7 +382,7 @@ void PenteGame::animateCapture(short move, byte *bitMaskG, short *outCapture1, s
return;
}
-void PenteGame::revertCapture(byte y, byte x, byte bitMask) {
+void PenteGame::revertCapture(byte x, byte y, byte bitMask) {
bool isPlayer = _table->boardState[x][y] == 79;
for (int i = bitMask; i; i >>= 1) {
if ((i & 1) == 0)
@@ -405,14 +405,14 @@ void PenteGame::revertCapture(byte y, byte x, byte bitMask) {
continue;
Slope &slope = slopes[7 - i];
- updateScore(y + slope.y * 2, x + slope.x * 2, isPlayer);
- updateScore(y + slope.y, x + slope.x, isPlayer);
+ updateScore(x + slope.x * 2, y + slope.y * 2, isPlayer);
+ updateScore(x + slope.x, y + slope.y, isPlayer);
}
}
int PenteGame::scoreMoveAndRevert(byte x, byte y, char depth, int parentScore, bool &gameOver) {
- updateScore(y, x, _table->moveCounter % 2);
- uint score = scoreCapture(y, x);
+ updateScore(x, y, _table->moveCounter % 2);
+ uint score = scoreCapture(x, y);
if (_table->playerScore >= WIN_SCORE || _table->staufScore >= WIN_SCORE)
gameOver = true;
@@ -430,9 +430,9 @@ int PenteGame::scoreMoveAndRevert(byte x, byte y, char depth, int parentScore, b
}
}
if (score != 0) {
- revertCapture(y, x, score);
+ revertCapture(x, y, score);
}
- revertScore(y, x);
+ revertScore(x, y);
return scoreDiff;
}
@@ -468,10 +468,10 @@ int PenteGame::aiRecurseTail(int parentScore) {
return -best_score;
}
-int PenteGame::aiRecurse(char depth, int parent_score) {
+int PenteGame::aiRecurse(char depth, int parentScore) {
if (depth == 1) {
// don't do more recursion
- return aiRecurseTail(parent_score);
+ return aiRecurseTail(parentScore);
}
// do more recursion after finding some good moves
@@ -509,13 +509,13 @@ int PenteGame::aiRecurse(char depth, int parent_score) {
if (scoreDiff < best_score) {
best_score = scoreDiff;
}
- if (-parent_score != best_score && parent_score <= -best_score)
+ if (-parentScore != best_score && parentScore <= -best_score)
break;
}
return -best_score;
}
-uint16 PenteGame::aiGetBestMove(uint param_1, int param_2, int param_3, byte depth) {
+uint16 PenteGame::aiGetBestMove(byte depth) {
for (int x = 0; x < _table->width; x++) {
for (int y = 0; y < _table->height; y++) {
if (_table->boardState[x][y] != 0 || _table->numAdjacentPieces[x][y] == 0)
@@ -648,8 +648,8 @@ void PenteGame::run(byte *vars) {
byte x, y;
_previousMove = varsMoveToXY(vars[0], vars[1], vars[2], x, y);
debugC(kDebugLogic, "player moved to %d, %d", (int)x, (int)y);
- updateScore(y, x, _table->moveCounter % 2);
- _animateCapturesBitMask = scoreCapture(y, x);
+ updateScore(x, y, _table->moveCounter % 2);
+ _animateCapturesBitMask = scoreCapture(x, y);
return;
case 2:
case 4:
@@ -663,25 +663,25 @@ void PenteGame::run(byte *vars) {
return;
}
- byte ai_depth = vars[6];
- if (ai_depth == 0) {
- ai_depth = 3;
- } else if (ai_depth == 1) {
- ai_depth = 4;
+ byte aiDepth = vars[6];
+ if (aiDepth == 0) {
+ aiDepth = 3;
+ } else if (aiDepth == 1) {
+ aiDepth = 4;
} else {
- ai_depth = 5;
+ aiDepth = 5;
}
- if (ai_depth != 2)
- _previousMove = aiGetBestMove(0, 0, 0, ai_depth);
+ if (aiDepth != 2)
+ _previousMove = aiGetBestMove(aiDepth);
else
warning("pente unknown else");
byte x, y;
aiMoveToXY(_previousMove, x, y);
debugC(kDebugLogic, "Stauf moved to %d, %d", (int)x, (int)y);
- updateScore(y, x, _table->moveCounter % 2);
- _animateCapturesBitMask = scoreCapture(y, x);
+ updateScore(x, y, _table->moveCounter % 2);
+ _animateCapturesBitMask = scoreCapture(x, y);
_previousMove = ((uint16)x * 0xf - (uint16)y) + 0xe;
moveXYToVars(x, y, vars[0], vars[1], vars[2]);
}
diff --git a/engines/groovie/logic/pente.h b/engines/groovie/logic/pente.h
index 26d505ffc9..4fd2feffbe 100644
--- a/engines/groovie/logic/pente.h
+++ b/engines/groovie/logic/pente.h
@@ -49,19 +49,19 @@ private:
void penteDeInit();
void penteInit(uint width, uint height, uint length);
uint &getPlayerTable(bool staufTurn, pentePlayerTable *&pt);
- void scoreLine(uint16 lineIndex, bool stauf_turn, bool revert);
+ void scoreLine(uint16 lineIndex, bool isStaufTurn, bool revert);
void calcTouchingPieces(byte moveX, byte moveY, bool revert);
- void updateScore(byte move_y, byte move_x, bool whose_turn);
- void revertScore(byte y, byte x);
+ void updateScore(byte x, byte y, bool whose_turn);
+ void revertScore(byte x, byte y);
byte scoreCaptureSingle(byte x, byte y, int slopeX, int slopeY);
- uint scoreCapture(byte y, byte x);
- void animateCapture(short param_1, byte *param_2, short * outMove, short *param_4);
- void revertCapture(byte y, byte x, byte y2);
+ uint scoreCapture(byte x, byte y);
+ void animateCapture(short move, byte *bitMaskG, short *outCapture1, short *outCapture2);
+ void revertCapture(byte x, byte y, byte y2);
int scoreMoveAndRevert(byte x, byte y, char depth, int parentScore, bool &gameOver);
- int scoreMoveAndRevert(byte x, byte y, char depth, int parent_score);
- int aiRecurseTail(int parent_score);
- int aiRecurse(char depth, int parent_score);
- uint16 aiGetBestMove(uint y_1, int param_2, int param_3, byte depth);
+ int scoreMoveAndRevert(byte x, byte y, char depth, int parentScore);
+ int aiRecurseTail(int parentScore);
+ int aiRecurse(char depth, int parentScore);
+ uint16 aiGetBestMove(byte depth);
void test();
void testGame(uint32 seed, Common::Array<int> moves, bool playerWin);
More information about the Scummvm-git-logs
mailing list