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

spookypeanut at users.sourceforge.net spookypeanut at users.sourceforge.net
Sun Nov 23 00:07:06 CET 2008


Revision: 35154
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35154&view=rev
Author:   spookypeanut
Date:     2008-11-22 23:07:05 +0000 (Sat, 22 Nov 2008)

Log Message:
-----------
T7G Microscope: Stauf now makes legal moves (though not good ones)

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

Modified: scummvm/trunk/engines/groovie/cell.cpp
===================================================================
--- scummvm/trunk/engines/groovie/cell.cpp	2008-11-22 19:44:18 UTC (rev 35153)
+++ scummvm/trunk/engines/groovie/cell.cpp	2008-11-22 23:07:05 UTC (rev 35154)
@@ -30,23 +30,102 @@
 CellGame::CellGame(byte *board) :
 	_board(board) {
 
-	//printf ("*** In cellgame constructor ***");
+	_startX = _startY = _endX = _endY = 255;
 }
 
+int8 CellGame::calcMove(byte *origboard, uint8 color, uint8 depth) {
+	uint8 i, j;
+	int8 di, dj;
+	byte *newboard;
+	uint8 boardmemsize = sizeof(byte) * BOARDSIZE * BOARDSIZE;
+	int8 maxdiff = -100;
+
+	newboard = (byte*) malloc(boardmemsize);
+	memcpy(newboard, origboard, boardmemsize);
+
+	if (0 == depth) {
+		return 0;
+	}
+	
+	for (i = 0; BOARDSIZE > i; i++) {
+		for (j = 0; BOARDSIZE > j; j++) {					// For every square on the board
+			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++) {
+						if (di != 0 || dj != 0) {		// Don't allow a move onto itself
+							if (validMove(origboard, color, i+di, j+dj)) {
+								_startX = i;
+								_startY = j;
+								_endX = i+di;
+								_endY = j+dj;
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+	
+	free(newboard);
+	return maxdiff;
+}
+
+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;
+	}
+	if (0 == *(board + endX + (BOARDSIZE * endY))) {
+		return true;
+	}
+	return false;
+}
+
+uint8 CellGame::countBoard(byte *board, uint8 color) {
+	uint8 total = 0;
+	for (uint8 i = 0; BOARDSIZE > i; i++) {
+		for (uint8 j = 0; BOARDSIZE > j; j++) {
+			if (color == *(board + i + (BOARDSIZE * j))) {
+				total++;
+			}
+		}
+	}
+	return total;
+}
+
 byte CellGame::getStartX() {
-	return 0;	// TODO: implement something here
+	if (_startX > BOARDSIZE) {
+		warning ("CellGame::getStartX: not calculated yet!");
+		return 0;
+	} else {
+		return _startX;
+	}
 }
 
 byte CellGame::getStartY() {
-	return 6;	// TODO: implement something here
+	if (_startY > BOARDSIZE) {
+		warning ("CellGame::getStartY: not calculated yet!");
+		return 6;
+	} else {
+		return _startY;
+	}
 }
 
 byte CellGame::getEndX() {
-	return 1;	// TODO: implement something here
+	if (_endX > BOARDSIZE) {
+		warning ("CellGame::getEndX: not calculated yet!");
+		return 1;	
+	} else {
+		return _endX;
+	}
 }
 
 byte CellGame::getEndY() {
-	return 6;	// TODO: implement something here
+	if (_endY > BOARDSIZE) {
+		warning ("CellGame::getEndY: not calculated yet!");
+		return 6;
+	} else {
+		return _endY;
+	}
 }
 
 CellGame::~CellGame() {

Modified: scummvm/trunk/engines/groovie/cell.h
===================================================================
--- scummvm/trunk/engines/groovie/cell.h	2008-11-22 19:44:18 UTC (rev 35153)
+++ scummvm/trunk/engines/groovie/cell.h	2008-11-22 23:07:05 UTC (rev 35154)
@@ -27,7 +27,13 @@
 #define GROOVIE_CELL_H
 
 #include "common/file.h"
+#include "common/util.h"
 
+#define BOARDSIZE 7
+#define CELL_CLEAR 0
+#define CELL_BLUE 1
+#define CELL_GREEN 2
+
 namespace Groovie {
 
 class GroovieEngine;
@@ -37,13 +43,21 @@
 public:
 	CellGame(byte *board);
 	~CellGame();
+	int8 calcMove(byte *origboard, uint8 color, uint8 depth);
 	byte getStartX();
 	byte getStartY();
 	byte getEndX();
 	byte getEndY();
 
 private:
+	bool validMove(byte *board, uint8 color, int8 endX, int8 endY);
+	uint8 countBoard(byte* board, uint8 color);
 	byte *_board;
+
+	byte _startX;
+	byte _startY;
+	byte _endX;
+	byte _endY;
 };
 
 } // End of Groovie namespace

Modified: scummvm/trunk/engines/groovie/script.cpp
===================================================================
--- scummvm/trunk/engines/groovie/script.cpp	2008-11-22 19:44:18 UTC (rev 35153)
+++ scummvm/trunk/engines/groovie/script.cpp	2008-11-22 23:07:05 UTC (rev 35154)
@@ -1315,7 +1315,7 @@
 void Script::o_cellmove() {
 	uint16 arg = readScript8bits();
 	byte *scriptBoard = &_variables[0x19];
-	byte board[7][7];
+	byte *board = (byte*) malloc (BOARDSIZE * BOARDSIZE * sizeof(byte));
 	byte startX, startY, endX, endY;
 
 	debugScript(1, true, "CELL MOVE var[0x%02X]", arg);
@@ -1323,22 +1323,23 @@
 	// Arguments used by the original implementation: (2, arg, scriptBoard)
 	for (int y = 0; y < 7; y++) {
 		for (int x = 0; x < 7; x++) {
-			board[x][y] = 0;
-			if (*scriptBoard == 0x32) board[x][y] = 1;
-			if (*scriptBoard == 0x42) board[x][y] = 2;
+			uint8 offset = x + BOARDSIZE * y;
+			*(board + offset) = 0;
+			if (*scriptBoard == 0x32) *(board + offset) = CELL_BLUE;
+			if (*scriptBoard == 0x42) *(board + offset) = CELL_GREEN;
 			scriptBoard++;
-			debugScript(1, false, "%d", board[x][y]);
+			debugScript(1, false, "%d", *(board + offset));
 		}
 		debugScript(1, false, "\n");
 	}
 
 	CellGame staufsMove((byte*) board);
+	staufsMove.calcMove((byte*) board, CELL_GREEN, 2);
 	startX = staufsMove.getStartX();
 	startY = staufsMove.getStartY();
 	endX = staufsMove.getEndX();
 	endY = staufsMove.getEndY();
 	
-	//printf("Moving from %d,%d to %d,%d\n", startX, startY, endX, endY);
 	
 	// Set the movement origin
 	setVariable(0, startY); // y
@@ -1346,6 +1347,8 @@
 	// Set the movement destination
 	setVariable(2, endY);
 	setVariable(3, endX);
+
+	free (board);
 }
 
 void Script::o_returnscript() {


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