Changeset 28 for trunk


Ignore:
Timestamp:
Jan 5, 2006, 11:12:44 AM (14 years ago)
Author:
jtv
Message:

More work on intelligence level 3. DOESN'T WORK YET.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gamelogic.cxx

    r27 r28  
    219219  static bool is_candidate(const Patch &p) throw ()
    220220  {
    221     return p.revealed() && p.near_unknown() && p.near_unknown() < 5;
     221    return p.revealed() && p.near_unknown();
    222222  }
    223223
    224224  void operator()(Coords c, const Patch &p)
    225225  {
    226     assert(are_neighbours(c,m_rc));
    227     if (is_candidate(p))
     226    if (&p != &m_revealed &&
     227    is_candidate(p) &&
     228        abs(c.row-m_rc.row) <= 2 && abs(c.col-m_rc.col) <= 2 &&
     229        min(abs(c.row-m_rc.row),abs(c.col-m_rc.col)) < 2)
    228230    {
    229       assert(&p != &m_revealed);
    230231      const int areadiff = p.near_unknown() - m_revealed.near_unknown();
    231232      if (areadiff > 0)
     
    241242  Coords m_rc;
    242243
    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.row||a.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.row-b.row),
     249          coldiff = abs(a.col-b.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);
    251259  }
    252260
     
    255263      int areadiff)
    256264  {
     265    assert(&subp != &supp);
    257266    assert(areadiff > 0);
    258     if (subp.near_unknown() <= common_neighbours(subc,supc) &&
     267    if (subp.near_unknown() <= overlap(subc,supc) &&
    259268    (supp.near_hiddenmines() == subp.near_hiddenmines() ||
    260269     supp.near_hiddenmines() == areadiff))
     
    262271  }
    263272};
    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.col-b.col)==1);
    272     output.insert(Coords(a.row-1,a.col));
    273     output.insert(Coords(a.row-1,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.row-b.row)==1);
    280     output.insert(Coords(a.row,a.col-1));
    281     output.insert(Coords(a.row,a.col+1));
    282     output.insert(Coords(b.row,a.col-1));
    283     output.insert(Coords(b.row,a.col+1));
    284   }
    285   else
    286   {
    287     assert(abs(a.row-b.row)==1);
    288     assert(abs(a.col-b.col)==1);
    289     output.insert(Coords(a.row,b.col));
    290     output.insert(Coords(b.row,a.col));
    291   }
    292 }
    293273
    294274
     
    576556       ++i)
    577557      {
    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
    582561    int subset_togo = at(i->first.row,i->first.col).near_unknown();
     562    assert(subset_togo);
     563
    583564    // Verify that the number of unrevealed patches among the pair's set of
    584565    // common neighbours accounts for all of the unrevealed neighbours of
    585566    // 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
    594576    assert(subset_togo >= 0);
    595577
Note: See TracChangeset for help on using the changeset viewer.