HTML-Tree

 view release on metacpan or  search on metacpan

lib/HTML/Tree/AboutTrees.pod  view on Meta::CPAN

   moving 5 to 3 gives xxxx__oo_oo
   moving 4 to 6 gives xx__xxoo_oo
   moving 5 to 6 gives xx_x_xoo_oo

For the computer to decide which of these is the best move to make, it
needs to quantify the benefit of these moves as a number -- call that
the "payoff".  The payoff of a move can be figured as just the number
of x pieces removed by the most recent move, minus the number of o
pieces removed by the most recent move.  (It so happens that the rules
of the game mean that no move can delete both o's and x's, but the
formula still applies.)  Since none of these moves removed any pieces,
all these moves have the same immediate payoff: 0.

Now, we could race ahead and write an Alak-playing program that could
use the immediate payoff to decide which is the best move to make.
And when there's more than one best move (as here, where all the moves
are equally good), it could choose randomly between the good
alternatives.  This strategy is simple to implement; but it makes for a
very dumb program.  Consider what O's response to each of the potential
moves (above) could be.  Nothing immediately suggests itself for the
first four possibilities (X having moved something to position 3), but

lib/HTML/Tree/Scanning.pod  view on Meta::CPAN

      return 1 unless $img;
        # no image means it's fine
      return 1 if $img->attr('src') =~ m{/photos/};
        # good if a photo
      return 0; # otherwise bad
    }
  );

Recall that this use of C<look_down> in a scalar context means to return
the first element at or under C<$tree> that matches all the criteria.
But if you notice that you can formulate criteria that'll match several
possible "h1" elements, some of which may be bogus but the I<last> one
of which is always the one you want, then you can use C<look_down> in a
list context, and just use the last element of that list:

  my @h1s = $tree->look_down(
    '_tag', 'h1',
    ...maybe more criteria...
  );
  die "What, no h1s here?" unless @h1s;
  my $real_h1 = $h1s[-1]; # last or only



( run in 0.490 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )