/[projectaxis]/projectaxis/projectAxis/src/blotchmaker/blotchmaker.cpp
ViewVC logotype

Diff of /projectaxis/projectAxis/src/blotchmaker/blotchmaker.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by vovansim, Sat May 17 19:52:29 2003 UTC revision 1.4 by leiavoia, Sun May 25 03:15:31 2003 UTC
# Line 104  hbsize = 2; // makes a 5x5 map Line 104  hbsize = 2; // makes a 5x5 map
104  hbplacement = 0;  hbplacement = 0;
105  num_players = 0;  num_players = 0;
106  // need at least two to play:  // need at least two to play:
107  SetAxisPalette(6,7,8,9);  SetAxisPalette(6,7);
108    
109  map_init = EMPTY;  map_init = EMPTY;
110    
# Line 130  for (short int x = 0; x < num_blotch_typ Line 130  for (short int x = 0; x < num_blotch_typ
130    
131    
132  short int attempts = 0; // number of times we've tried to make a good map with these settings.  short int attempts = 0; // number of times we've tried to make a good map with these settings.
133    bool good = 0; // whether or not the map was a "good", verifiable map.
134    
135  do {  do {
136    
# Line 169  do { Line 170  do {
170          blotch_count = 0;          blotch_count = 0;
171    
172          attempts++;          attempts++;
173            good = VerifyMap();
174          }          }
175    
176  while( (VerifyMap() == 0) && (attempts < 5) ); // timeout after 10 tries  while( (good == 0) && (attempts < 3) ); // timeout after so many tries
177    
178  // if we tried the best we could and still couldn't make a decent map:  // if we tried the best we could and still couldn't make a decent map:
179  // NOTE: in the future if path-cutting is implemented, this is where you would plug it in  // NOTE: in the future if path-cutting is implemented, this is where you would plug it in
180  if(attempts >= 5) {  
181    return good;
182    
183    /*
184    if(good == 0) {
185          cout << "Bad Map - Try Again - Attempts: " << attempts << "\n" ;          cout << "Bad Map - Try Again - Attempts: " << attempts << "\n" ;
186          return 0;          return 0;
187          }          }
# Line 183  else { Line 189  else {
189          cout << "Yeah! Good Map!- Attempts: " << attempts << "\n" ;          cout << "Yeah! Good Map!- Attempts: " << attempts << "\n" ;
190          return 1; // produced a good map          return 1; // produced a good map
191          }          }
192    */
193    
194  }  }
195  ///////////////////////////////////////////////////////////////////////////////////////////////////////////  ///////////////////////////////////////////////////////////////////////////////////////////////////////////
# Line 760  void Blotchmaker::CreateHBs(){ Line 766  void Blotchmaker::CreateHBs(){
766  // in the future, we'll think of a more clever way to randomly  // in the future, we'll think of a more clever way to randomly
767  // place these guys, but for now, just put them in pre-arranged configurations  // place these guys, but for now, just put them in pre-arranged configurations
768    
769    // REMEMBER: we are zero indexed so minus one!
   
 // map border offset from hb center point  
 int offset = hbsize + 1;  
770    
771  // if two players:  // if two players:
772  if (num_players == 2) {  if (num_players == 2) {
773          // lower left          // lower left
774          hb_locs[0].x = 0 + offset;          hb_locs[0].x = 0 + hbsize;
775          hb_locs[0].y = 0 + offset - 1;          hb_locs[0].y = 0 + hbsize;
776          // upper right          // upper right
777          hb_locs[1].x = map_cols - offset;          hb_locs[1].x = map_cols - hbsize -1;
778          hb_locs[1].y = map_rows - offset;          hb_locs[1].y = map_rows - hbsize -1;
779          }          }
780  // if 3 players  // if 3 players
781  if (num_players == 3) {  if (num_players == 3) {
782          // upper left          // upper left
783          hb_locs[0].x = 0 + offset;          hb_locs[0].x = 0 + hbsize;
784          hb_locs[0].y = map_rows - offset;          hb_locs[0].y = map_rows - hbsize -1;
785          // upper right          // upper right
786          hb_locs[1].x = map_cols - offset;          hb_locs[1].x = map_cols - hbsize -1;
787          hb_locs[1].y = map_rows - offset;          hb_locs[1].y = map_rows - hbsize -1;
788          // bottom side          // bottom side
789          hb_locs[2].x = int(map_cols / 2);          hb_locs[2].x = int(map_cols / 2)-1;
790          hb_locs[2].y = 0 + offset - 1;          hb_locs[2].y = 0 + hbsize ;
791          }          }
792  // if 4 players  // if 4 players
793  if (num_players == 4) {  if (num_players == 4) {
794          // lower left          // lower left
795          hb_locs[0].x = 0 + offset;          hb_locs[0].x = 0 + hbsize;
796          hb_locs[0].y = 0 + offset - 1;          hb_locs[0].y = 0 + hbsize;
797          // upper right          // upper right
798          hb_locs[1].x = map_cols - offset;          hb_locs[1].x = map_cols - hbsize -1;
799          hb_locs[1].y = map_rows - offset;          hb_locs[1].y = map_rows - hbsize -1;
800          // lower right          // lower right
801          hb_locs[2].x = map_cols - offset;          hb_locs[2].x = map_cols - hbsize -1;
802          hb_locs[2].y = 0 + offset - 1;          hb_locs[2].y = 0 + hbsize;
803          // upper left          // upper left
804          hb_locs[3].x = 0 + offset;          hb_locs[3].x = 0 + hbsize;
805          hb_locs[3].y = map_rows - offset;          hb_locs[3].y = map_rows - hbsize -1;
806          }          }
807    
808  // now fill them in  // now fill them in
# Line 820  bool Blotchmaker::VerifyMap(){ Line 823  bool Blotchmaker::VerifyMap(){
823  // Checks to make sure HBs are accessable by eachother. no blocking obstacles.  // Checks to make sure HBs are accessable by eachother. no blocking obstacles.
824  // returns 1 if success, zero if failed  // returns 1 if success, zero if failed
825    
 // ***FIXME***  
 // checks for each corner position at present.  
 // if you are playing a 2player game, it will still check all four corners!  
   
   
826  //pointer to the search  //pointer to the search
827  AStarSearch<MapSearchNode>* astarsearch;  AStarSearch<MapSearchNode>* astarsearch;
828    
829  //cout << "Begin Map Verification:\n";  //cout << "Begin Map Verification:\n";
830    
831    int timeout = ((map_cols * map_rows) / 8);
832    
833  // foreach corner position  // foreach corner position
 int no_dbl_offset = 1; // so we don't check the same routes twice in the loops  
834  for (short int here = 0; here < num_players; here++) {  for (short int here = 0; here < num_players; here++) {
835          for (short int there = no_dbl_offset; there < num_players; there++) {          for (short int there = here+1; there < num_players; there++) {
836    
837                  if (here == there) {continue;} //skip if finding path to self                  if (here == there) {continue;} //skip if finding path to self
838    
# Line 860  for (short int here = 0; here < num_play Line 859  for (short int here = 0; here < num_play
859                          //cout << "*";                          //cout << "*";
860                          }                          }
861                  while( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING &&                  while( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING &&
862                          SearchSteps < ((map_cols + map_rows) * 2));                          //SearchSteps < ((map_cols + map_rows) * 2)  );
863                            SearchSteps < timeout );
864    
865                  // if solution found, display:                  // if solution found, display:
866                  if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED ) {                  if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED ) {
867                          // Once you're done with the solution you can free the nodes up                          // Once you're done with the solution you can free the nodes up
868                          astarsearch->FreeSolutionNodes();                          astarsearch->FreeSolutionNodes();
869                          //cout << "Succeeded\n";                          //cout << "             Succeeded. " << SearchSteps << " steps searched\n";
870                          }                          }
871                  // otherwise, kill and return 0                  // otherwise, kill and return 0
872                  else if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_FAILED ) {                  else { //if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_FAILED ) {
873                          //cout << "Failed. " << SearchSteps << " steps searched on this route\n";                          //cout << "             Failed. " << SearchSteps << " steps searched on this route\n";
874                          delete astarsearch;                          delete astarsearch;
875                          return 0;                          return 0;
876                          }                          }
877    
878                  delete astarsearch;                  delete astarsearch;
879                  }                  }
         no_dbl_offset++;  
880          }          }
881    
882  //cout << "End Map Verification:\n";  //cout << "End Map Verification:\n";

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26