c# - Match the pairs search algorithm? -
i found interesting pairs matching game @ http://xepthu.uhm.vn. rule simple, have find , connect 2 identical pokemon path between them not blocked , direction can't not changed 3 times. let's see example:
alt text http://img14.imageshack.us/img14/382/16170399.png
i've think alot algorithm check if path between 2 selected pokemon valid because i'm newbie can't find solution. can suggest me 1 in c#? you.
this path finding problem graph theory. fields in grid nodes, , adjacent fields connected edge.
path finding well-known problem, , there many algorithms solve this. since graph quite small, best solution here brute force algorithm. popular path finding algorithm dijkstra's algorithm.
brute force: start @ pokemon , explore possible ways see if 1 leads identical pokemon. can stop exploring way if way blocked or has more 2 turns.
you'll need "pointer" pointing field in grid. pointer can move left, right, or down, provided field in direction not blocked. move pointer adjacent field. remember came , how many turns made. repeat until you've reached destination. backtrack if number of turns reaches 3. make sure don't run in circles.
Comments
Post a Comment