[Scummvm-cvs-logs] SF.net SVN: scummvm:[35164] scummvm/trunk/engines/groovie

spookypeanut at users.sourceforge.net spookypeanut at users.sourceforge.net
Mon Nov 24 22:22:25 CET 2008


Revision: 35164
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35164&view=rev
Author:   spookypeanut
Date:     2008-11-24 21:22:24 +0000 (Mon, 24 Nov 2008)

Log Message:
-----------
T7G: AI in microscope puzzle is "complete" (ie good enough for now)

Modified Paths:
--------------
    scummvm/trunk/engines/groovie/cell.cpp
    scummvm/trunk/engines/groovie/cell.h
    scummvm/trunk/engines/groovie/debug.cpp
    scummvm/trunk/engines/groovie/groovie.cpp
    scummvm/trunk/engines/groovie/groovie.h

Modified: scummvm/trunk/engines/groovie/cell.cpp
===================================================================
--- scummvm/trunk/engines/groovie/cell.cpp	2008-11-24 00:36:07 UTC (rev 35163)
+++ scummvm/trunk/engines/groovie/cell.cpp	2008-11-24 21:22:24 UTC (rev 35164)
@@ -29,17 +29,21 @@
 
 CellGame::CellGame(byte *board) :
 	_board(board) {
-
 	_startX = _startY = _endX = _endY = 255;
 }
 
 int8 CellGame::calcMove(byte *origboard, uint8 color, uint8 depth) {
 	uint8 i, j;
 	int8 di, dj;
+	uint8 bestStartX, bestStartY, bestEndX, bestEndY;
+	int8 bestDiff = -100;
+	int8 origBoardCount = countBoard(origboard, color);
+	int8 currDiff = -100;
 	byte *newboard;
 	uint8 boardmemsize = sizeof(byte) * BOARDSIZE * BOARDSIZE;
-	int8 maxdiff = -100;
+	uint8 oppColor = 3 - color;
 
+	bestStartX = bestStartY = bestEndX = bestEndY = 255;
 	newboard = (byte*) malloc(boardmemsize);
 	memcpy(newboard, origboard, boardmemsize);
 
@@ -47,17 +51,32 @@
 		return 0;
 	}
 	
-	for (i = 0; BOARDSIZE > i; i++) {
-		for (j = 0; BOARDSIZE > j; j++) {					// For every square on the board
+	for (i = 0; BOARDSIZE > i; i++) {						// For every square on the board
+		for (j = 0; BOARDSIZE > j; j++) {					//
 			if (color == *(origboard + i + (BOARDSIZE * j))) {		// If the square is the desired colour
-				for (di = -2; 2 >= di; di++) {
-					for (dj = -2; 2 >= dj; dj++) {
+				for (di = -2; 2 >= di; di++) {				// Check every square two or less in every direction
+					for (dj = -2; 2 >= dj; dj++) {			//
 						if (di != 0 || dj != 0) {		// Don't allow a move onto itself
+							debugC(7, kGroovieDebugCell | kGroovieDebugAll, "Depth: %d: Testing move %d, %d-> %d, %d", depth, i, j, i+di, j+dj);
 							if (validMove(origboard, color, i+di, j+dj)) {
-								_startX = i;
-								_startY = j;
-								_endX = i+di;
-								_endY = j+dj;
+								int8 nextlevel;
+								debugC(5, kGroovieDebugCell | kGroovieDebugAll, "Depth: %d: Valid move %d, %d-> %d, %d", depth, i, j, i+di, j+dj);
+								execMove (newboard, color, i, j, i+di, j+dj);
+								
+								nextlevel = calcMove (newboard, oppColor, depth - 1);
+								debugC(5, kGroovieDebugCell | kGroovieDebugAll, "Depth: %d: Next level down returned %d", depth, nextlevel);
+								currDiff = countBoard(newboard, color) - origBoardCount - nextlevel;
+								if (currDiff > bestDiff) {
+									debugC(4, kGroovieDebugCell | kGroovieDebugAll, "Depth: %d: Found new best move (diff of %d): %d, %d-> %d, %d", depth, currDiff, i, j, i+di, j+dj);
+									bestDiff = currDiff;
+									bestStartX = i;
+									bestStartY = j;
+									bestEndX = i+di;
+									bestEndY = j+dj;
+
+								}
+								// TODO: ideal would be to revert the move, rather than copy the board again. I think.
+								memcpy(newboard, origboard, boardmemsize);
 							}
 						}
 					}
@@ -66,10 +85,39 @@
 		}
 	}
 	
+	_startX = bestStartX;
+	_startY = bestStartY;
+	_endX = bestEndX;
+	_endY = bestEndY;
+
+	debugC(2, kGroovieDebugCell | kGroovieDebugAll, "Depth: %d: Best move is (diff of %d): %d, %d-> %d, %d", depth, bestDiff, _startX, _startY, _endX, _endY);
 	free(newboard);
-	return maxdiff;
+	debugC(5, kGroovieDebugCell | kGroovieDebugAll, "Freed newboard");
+	return bestDiff;
 }
 
+void CellGame::execMove(byte *board, uint8 color, int8 startX, int8 startY, int8 endX, int8 endY) {
+	int8 i, j;
+	uint8 colorToEat = 3 - color;		// The opposite of the colour passed: 2 -> 1, 1 -> 2
+
+	if (abs(endX - startX) == 2 || abs(endY - startY) == 2) {
+		*(board + startX + BOARDSIZE * startY) = 0;
+	}
+
+	*(board + endX + BOARDSIZE * endY) = color;
+
+	for (i = (endX - 1); endX + 1 >= i; i++) {
+		for (j = (endY - 1); endY + 1 >= j; j++) {
+			if (BOARDSIZE > i && BOARDSIZE > j && 0 <= i && 0 <= j) {		// Don't wrap around the board edges!
+				uint8 offset = i + BOARDSIZE * j;
+				if (colorToEat == *(board + offset)) {
+					*(board + offset) = color;
+				}
+			}
+		}
+	}
+}
+
 bool CellGame::validMove(byte *board, uint8 color, int8 endX, int8 endY) {
 	if (0 > endX || 0 > endY || BOARDSIZE <= endX || BOARDSIZE <= endY) {		// Move is out of bounds
 		return false;

Modified: scummvm/trunk/engines/groovie/cell.h
===================================================================
--- scummvm/trunk/engines/groovie/cell.h	2008-11-24 00:36:07 UTC (rev 35163)
+++ scummvm/trunk/engines/groovie/cell.h	2008-11-24 21:22:24 UTC (rev 35164)
@@ -29,6 +29,8 @@
 #include "common/file.h"
 #include "common/util.h"
 
+#include "groovie/groovie.h"
+
 #define BOARDSIZE 7
 #define CELL_CLEAR 0
 #define CELL_BLUE 1
@@ -51,6 +53,7 @@
 
 private:
 	bool validMove(byte *board, uint8 color, int8 endX, int8 endY);
+	void execMove(byte *board, uint8 color, int8 startX, int8 startY, int8 endX, int8 endY);
 	uint8 countBoard(byte* board, uint8 color);
 	byte *_board;
 

Modified: scummvm/trunk/engines/groovie/debug.cpp
===================================================================
--- scummvm/trunk/engines/groovie/debug.cpp	2008-11-24 00:36:07 UTC (rev 35163)
+++ scummvm/trunk/engines/groovie/debug.cpp	2008-11-24 21:22:24 UTC (rev 35164)
@@ -24,8 +24,8 @@
  */
 
 #include "groovie/debug.h"
+#include "groovie/groovie.h"
 #include "groovie/script.h"
-#include "groovie/groovie.h"
 
 namespace Groovie {
 

Modified: scummvm/trunk/engines/groovie/groovie.cpp
===================================================================
--- scummvm/trunk/engines/groovie/groovie.cpp	2008-11-24 00:36:07 UTC (rev 35163)
+++ scummvm/trunk/engines/groovie/groovie.cpp	2008-11-24 21:22:24 UTC (rev 35164)
@@ -54,6 +54,7 @@
 	Common::addSpecialDebugLevel(kGroovieDebugCursor, "Cursor", "Debug cursor decompression / switching");
 	Common::addSpecialDebugLevel(kGroovieDebugMIDI, "MIDI", "Debug MIDI / XMIDI files");
 	Common::addSpecialDebugLevel(kGroovieDebugScriptvars, "Scriptvars", "Print out any change to script variables");
+	Common::addSpecialDebugLevel(kGroovieDebugCell, "Cell", "Debug the cell game (in the microscope)");
 }
 
 GroovieEngine::~GroovieEngine() {

Modified: scummvm/trunk/engines/groovie/groovie.h
===================================================================
--- scummvm/trunk/engines/groovie/groovie.h	2008-11-24 00:36:07 UTC (rev 35163)
+++ scummvm/trunk/engines/groovie/groovie.h	2008-11-24 21:22:24 UTC (rev 35164)
@@ -50,7 +50,8 @@
 	kGroovieDebugHotspots = 1 << 5,
 	kGroovieDebugCursor = 1 << 6,
 	kGroovieDebugMIDI = 1 << 7,
-	kGroovieDebugScriptvars = 1 << 8
+	kGroovieDebugScriptvars = 1 << 8,
+	kGroovieDebugCell = 1 << 9
 		// the current limitation is 32 debug levels (1 << 31 is the last one)
 };
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list