 Timestamp:
 Jan 5, 2006, 11:12:44 AM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/gamelogic.cxx
r27 r28 219 219 static bool is_candidate(const Patch &p) throw () 220 220 { 221 return p.revealed() && p.near_unknown() && p.near_unknown() < 5;221 return p.revealed() && p.near_unknown(); 222 222 } 223 223 224 224 void operator()(Coords c, const Patch &p) 225 225 { 226 assert(are_neighbours(c,m_rc)); 227 if (is_candidate(p)) 226 if (&p != &m_revealed && 227 is_candidate(p) && 228 abs(c.rowm_rc.row) <= 2 && abs(c.colm_rc.col) <= 2 && 229 min(abs(c.rowm_rc.row),abs(c.colm_rc.col)) < 2) 228 230 { 229 assert(&p != &m_revealed);230 231 const int areadiff = p.near_unknown()  m_revealed.near_unknown(); 231 232 if (areadiff > 0) … … 241 242 Coords m_rc; 242 243 243 /// How many neighbours do two neighbours a and b have in common? 244 static int common_neighbours(Coords a, Coords b) throw () 245 { 246 // Assuming that a and b are neighbours, there are only two cases: either 247 // they lie on the same row or column, in which case they share 4 common 248 // neighbours; or they touch diagonally, in which they have only two 249 // neighbours in common. 250 return (a.row==b.rowa.col==b.col) ? 4 : 2; 244 /// How many neighbours do two patches a and b have in common? 245 static int overlap(Coords a, Coords b) throw () 246 { 247 assert(a < b  b < a); 248 const int rowdiff = abs(a.rowb.row), 249 coldiff = abs(a.colb.col); 250 const int bigdiff = max(rowdiff,coldiff), 251 smalldiff = min(rowdiff,coldiff); 252 assert(bigdiff > 0); 253 assert(bigdiff <= 2); 254 assert(smalldiff >= 0); 255 assert(smalldiff < 2); 256 assert(smalldiff <= bigdiff); 257 258 return (smalldiff == 1) ? 2 : ((bigdiff == 2) ? 3 : 4); 251 259 } 252 260 … … 255 263 int areadiff) 256 264 { 265 assert(&subp != &supp); 257 266 assert(areadiff > 0); 258 if (subp.near_unknown() <= common_neighbours(subc,supc) &&267 if (subp.near_unknown() <= overlap(subc,supc) && 259 268 (supp.near_hiddenmines() == subp.near_hiddenmines()  260 269 supp.near_hiddenmines() == areadiff)) … … 262 271 } 263 272 }; 264 265 266 void common_neighbours(Coords a, Coords b, set<Coords> &output)267 {268 assert(a < b  b < a);269 if (a.row == b.row)270 {271 assert(abs(a.colb.col)==1);272 output.insert(Coords(a.row1,a.col));273 output.insert(Coords(a.row1,b.col));274 output.insert(Coords(a.row+1,a.col));275 output.insert(Coords(a.row+1,b.col));276 }277 else if (a.col == b.col)278 {279 assert(abs(a.rowb.row)==1);280 output.insert(Coords(a.row,a.col1));281 output.insert(Coords(a.row,a.col+1));282 output.insert(Coords(b.row,a.col1));283 output.insert(Coords(b.row,a.col+1));284 }285 else286 {287 assert(abs(a.rowb.row)==1);288 assert(abs(a.colb.col)==1);289 output.insert(Coords(a.row,b.col));290 output.insert(Coords(b.row,a.col));291 }292 }293 273 294 274 … … 576 556 ++i) 577 557 { 578 assert(are_neighbours(i>first,i>second)); 579 580 set<Coords> overlap; 581 common_neighbours(i>first,i>second, overlap); 558 assert(at(i>first.row,i>first.col).revealed()); 559 assert(at(i>second.row,i>second.col).revealed()); 560 582 561 int subset_togo = at(i>first.row,i>first.col).near_unknown(); 562 assert(subset_togo); 563 583 564 // Verify that the number of unrevealed patches among the pair's set of 584 565 // common neighbours accounts for all of the unrevealed neighbours of 585 566 // the first ("subset") of the two 586 for (set<Coords>::const_iterator j = overlap.begin(); 587 j != overlap.end(); 588 ++j) 589 { 590 assert(are_neighbours(i>first,*j)); 591 assert(are_neighbours(i>second,*j)); 592 subset_togo = !at(j>row,j>col).revealed(); 593 } 567 for (int r = min(0, max(i>first.row,i>second.row)1); 568 r <= max(m_rows, min(i>first.row,i>second.row)+1); 569 ++r) 570 for (int c = min(0, max(i>first.col,i>second.col)1); 571 c <= max(m_cols, min(i>first.col,i>second.col)+1); 572 ++c) 573 if (!at(r,c).revealed()) 574 subset_togo; 575 594 576 assert(subset_togo >= 0); 595 577
Note: See TracChangeset
for help on using the changeset viewer.