diff options
author | Henry Bush | 2008-11-22 23:07:05 +0000 |
---|---|---|
committer | Henry Bush | 2008-11-22 23:07:05 +0000 |
commit | d41ebfae814d6a687ba213a8da97c8c675b4a275 (patch) | |
tree | 72f43f9638bb5fd8b4bbcb8d4a3d225fa9a607bb /engines/groovie/cell.cpp | |
parent | 056e6bcc9c80d9451f90239a2aef854368e1c4d2 (diff) | |
download | scummvm-rg350-d41ebfae814d6a687ba213a8da97c8c675b4a275.tar.gz scummvm-rg350-d41ebfae814d6a687ba213a8da97c8c675b4a275.tar.bz2 scummvm-rg350-d41ebfae814d6a687ba213a8da97c8c675b4a275.zip |
T7G Microscope: Stauf now makes legal moves (though not good ones)
svn-id: r35154
Diffstat (limited to 'engines/groovie/cell.cpp')
-rw-r--r-- | engines/groovie/cell.cpp | 89 |
1 files changed, 84 insertions, 5 deletions
diff --git a/engines/groovie/cell.cpp b/engines/groovie/cell.cpp index 5ec060c2d9..0babbce40c 100644 --- a/engines/groovie/cell.cpp +++ b/engines/groovie/cell.cpp @@ -30,23 +30,102 @@ namespace Groovie { 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() { |