Changeset 307 for trunk/monsterz/board.cpp
 Timestamp:
 Jan 29, 2011, 1:03:27 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/monsterz/board.cpp
r306 r307 43 43 } 44 44 pairs[8][8], grabbed; 45 int nmoves; 45 46 46 47 Mash *mashes; … … 88 89 for (int i = 0; i < 8; i++) 89 90 data>pairs[i][j].id = 1 + rand() % 7; 90 } while (ListMashes(list) );91 } while (ListMashes(list)  !(data>nmoves = ListMoves(list))); 91 92 92 93 /* Spawn pieces */ … … 345 346 } 346 347 while(ListMashes(list)); 348 349 data>nmoves = ListMoves(list); 347 350 } 348 351 … … 399 402 for (int i = 0; i < 8; i++) 400 403 { 401 if (i + 1 < 8) 402 { 403 /* Try moving right */ 404 int i1 = data>pairs[i][j].id; 405 int i2 = data>pairs[i + 1][j].id; 406 407 if ((i + 3 < 8 && data>pairs[i + 2][j].id == i1 408 && data>pairs[i + 3][j].id == i1)  409 (j + 2 < 8 && data>pairs[i + 1][j + 2].id == i1 410 && data>pairs[i + 1][j + 1].id == i1)  411 (j + 1 < 8 && j  1 > 0 412 && data>pairs[i + 1][j + 1].id == i1 413 && data>pairs[i + 1][j  1].id == i1)  414 (j  2 > 0 && data>pairs[i + 1][j  1].id == i1 415 && data>pairs[i + 1][j  2].id == i1)  416 417 (i  2 > 0 && data>pairs[i  2][j].id == i2 418 && data>pairs[i  1][j].id == i2)  419 (j + 2 < 8 &&data>pairs[i][j + 2].id == i2 420 && data>pairs[i][j + 1].id == i2)  421 (j + 1 < 8 && j  1 > 0 422 && data>pairs[i][j + 1].id == i2 423 && data>pairs[i][j  1].id == i2)  424 (j  2 > 0 && data>pairs[i][j  1].id == i2 425 && data>pairs[i][j  2].id == i2)) 426 { 427 moves[i][j] = 1; 428 ret++; 429 } 430 } 431 432 if (j + 1 < 8) 433 { 434 /* Try moving up */ 435 int i1 = data>pairs[i][j].id; 436 int i2 = data>pairs[i][j + 1].id; 437 438 if ((j + 3 < 8 && data>pairs[i][j + 2].id == i1 439 && data>pairs[i][j + 3].id == i1)  440 (i + 2 < 8 && data>pairs[i + 2][j + 1].id == i1 441 && data>pairs[i + 1][j + 1].id == i1)  442 (i + 1 < 8 && i  1 > 0 443 && data>pairs[i + 1][j + 1].id == i1 444 && data>pairs[i  1][j + 1].id == i1)  445 (i  2 > 0 && data>pairs[i  1][j + 1].id == i1 446 && data>pairs[i  2][j + 1].id == i1)  447 448 (j  2 > 0 && data>pairs[i][j  2].id == i2 449 && data>pairs[i][j  1].id == i2)  450 (i + 2 < 8 &&data>pairs[i + 2][j].id == i2 451 && data>pairs[i + 1][j].id == i2)  452 (i + 1 < 8 && i  1 > 0 453 && data>pairs[i + 1][j].id == i2 454 && data>pairs[i  1][j].id == i2)  455 (i  2 > 0 && data>pairs[i  1][j].id == i2 456 && data>pairs[i  2][j].id == i2)) 457 { 458 moves[i][j] = 2; 459 ret++; 460 } 404 /* Copy neighbourhood to a local buffer */ 405 int tmp[6][6]; 406 407 for (int dj = 2; dj <= 3; dj++) 408 for (int di = 2; di <= 3; di++) 409 if (j + dj >= 0 && j + dj < 8 410 && i + di >= 0 && i + di < 8) 411 tmp[2 + di][2 + dj] = data>pairs[i + di][j + dj].id; 412 else 413 tmp[2 + di][2 + dj] = 0; 414 415 /* +++++++ 416 *   25    417 * +++++++ 418 *   2434   419 * +++++++ 420 * 0313c 3343  421 * +++++++ 422 * 0212a b 4252 423 * +++++++ 424 *  112131   425 * +++++++ 426 *   2030   427 * +++++++ */ 428 int a = tmp[2][2]; 429 int b = tmp[3][2] ? tmp[3][2] : 1; 430 int c = tmp[2][3] ? tmp[2][3] : 1; 431 432 /* Try moving right */ 433 if ((a == tmp[3][0] && a == tmp[3][1])  434 (a == tmp[3][1] && a == tmp[3][3])  435 (a == tmp[3][3] && a == tmp[3][4])  436 (a == tmp[4][2] && a == tmp[5][2])  437 (b == tmp[2][0] && b == tmp[2][1])  438 (b == tmp[2][1] && b == tmp[2][3])  439 (b == tmp[2][3] && b == tmp[2][4])  440 (b == tmp[0][2] && b == tmp[1][2])) 441 { 442 moves[i][j] = 1; 443 ret++; 444 } 445 446 /* Try moving up */ 447 if ((a == tmp[0][3] && a == tmp[1][3])  448 (a == tmp[1][3] && a == tmp[3][3])  449 (a == tmp[3][3] && a == tmp[4][3])  450 (a == tmp[2][4] && a == tmp[2][5])  451 (c == tmp[0][2] && c == tmp[1][2])  452 (c == tmp[1][2] && c == tmp[3][2])  453 (c == tmp[3][2] && c == tmp[4][2])  454 (c == tmp[2][0] && c == tmp[2][1])) 455 { 456 moves[i][j] = 2; 457 ret++; 461 458 } 462 459 }
Note: See TracChangeset
for help on using the changeset viewer.