Although it is just a small program, huh, it will be made by the original traversal search to the original traversal search to save improvements, and there is a lot of time, um, hashKey has two kinds, one uses a long long Come, yeah, just have a lot of two, otherwise Int is enough, the other is using a string String, here is String, such search template is more complete :) / * Cody by me BLOG AT 2004.10.9 Independent Diamond Chess, Depth Priority Search, Try to Clear Dupid 2004.10.18 Using HashMap to improve the Closed set, use Stack to improve the Openset.
Chessboard number layout is as follows: 01 02 03 04 05 0607 08 09 10 11 12 13 14 15 16 17 18 19 27 28 29 30 31 32 33 * / # include
#include "node.h" Using namespace std; using namespace stdex);
Stack
/ / Judgment if the NEXT node has expanded, returning True, otherwise falseBool Extended (Node & next); // Search Void search ();
INT main (void) {search (); system ("pause"); return 0;}
Void search () {// Initialization Node first; for (int i = 1; i <= 33; i ) {first.c [i] = 1;} first.c [17] = 0; first.key = 0 Open.push (first);
// Start loop while (! Open.empty ()) {// cout << "is searching ... The expanded point:" << closed.size () << "/ n"; Node TMP = Open.top (); open.pop ();
/ / Look at whether the node is the target node if (tmp.moveid [0]> = 31 && tmp.c [17] == 1) {tmp.output (cout); // output and return to Ofstream OUT (" Out.txt "); tmp.output (out); return;} // If you do not generate all sub-status node next; bool hadit; for (int i = 1; i <= 33; i ) {ix (TMP .C [i]! = 0) {if (tmp.down (i, next)) {if (extended (next) == false {// Open.push (NEXT) is not expanded;}} f Tmp.Up (i, next)) {if (extended == false) {// has not expanded Open.push (NEXT);}}}}}}}} (Tmp.Left (i, next)) {IF Extended (Next) == false) {// has not expanded Open.push (Next);}}}}}}}} f (tmp.right (i, next)) {if (extended == false) {// Did not extend Open.push (next);}}}} // put the open point that I just taken into the Closed Table Closed.insert (pair (tmp.gethashkey (), tmp);}}
Bool Extended (Node & Next) {// If Next is in the closed, that is, it has expanded, returns true rciter = closed.Find (Next.getHashKey ()); if (rciter == closed.end ()) {Return False } Else {return true;}}