Thread: Loop seg error

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    37

    Loop seg error

    I posted earlier and i dint get a reply, i think because of the amount of code i put up, im getting a seg error after the first loop runs for the fifth time, if anyone could help it would be great. Also im trying to find borland turbo debugger (td32.exe) and i cant find nowhere to download it from, if anyone knows that would help too. Thanks

    Code:
    for(int i=0; i<player1->getNDraughts(); i++){
    				std::cout << "loop"<<endl;
    
    				Draught * d1 = player1->getDraught(i);
    				Square * d1s = d1->getSquare();
    				
    					for(int j=0; j<player2->getNDraughts(); j++){
    				
    					Draught * d2 = player2->getDraught(j);
    					
    					if(d1s->getY() == 0 || d1s->getY() == 1){
    					
    					Square * s = board->getSquare(d1s->getX()+1, d1s->getY() +1); 			// getting squares for top right
    					Square * o = board->getSquare(d1s->getX()+2, d1s->getY() +2);
    				
    					Square * s1 = board->getSquare(d1s->getX()-1, d1s->getY() +1);			// getting squares for bottom right
    					Square * o1 = board->getSquare(d1s->getX()-2, d1s->getY() +2);
    					
    						if ((d2->getSquare() == s) && !o->isOccupied()){					// checking if top right square is occupied
    
    						fm = true;											
    						}
    				
    						if ((d2->getSquare() == s1) && !o1->isOccupied()){					// checking if bottom right square is occupied
    				
    						fm = true;
    						}
    					}
    					
    						else if (sq1->getY() == 6 || sq1->getY() == 7){
    				
    							Square * s = board->getSquare(d1s->getX()+1, d1s->getY()-1); 	// getting squares for top left focred move
    							Square * o = board->getSquare(d1s->getX()+2, d1s->getY()-2);
    					
    							Square * s1 = board->getSquare(d1s->getX()-1, d1s->getY() -1);	// getting squares for bottom left
    							Square * o1 = board->getSquare(d1s->getX()-2, d1s->getY() -2);
    					
    								if ((d2->getSquare() == s) && !o->isOccupied()){			// checking if top right square is occupied
    
    								fm = true;											
    			
    								}
    				
    								if ((d2->getSquare() == s1) && !o1->isOccupied()){			// checking if bottom right square is occupied
    				
    								fm = true;
    								
    								}
    					
    						}
    						
    							else {  //rest of squares on the row
    			
    								Square * s = board->getSquare(d1s->getX()+1, d1s->getY()-1);  // getting squares for top left focred move
    								Square * o = board->getSquare(d1s->getX()+2, d1s->getY()-2);
    
    								Square * s1 = board->getSquare(d1s->getX()+1, d1s->getY() +1); // getting squares for top right
    								Square * o1 = board->getSquare(d1s->getX()+2, d1s->getY() +2);
    
    								Square * s2 = board->getSquare(d1s->getX()-1, d1s->getY() -1);	// getting squares for bottom left
    								Square * o2 = board->getSquare(d1s->getX()-2, d1s->getY() -2);
    
    								Square * s3 = board->getSquare(d1s->getX()-1, d1s->getY() +1);	// getting squares for bottom right
    								Square * o3 = board->getSquare(d1s->getX()-2, d1s->getY() +2);
    
    									if ((d2->getSquare() == s) && !o->isOccupied()){			// checking if top left square is occupied
    
    									fm = true;											
    									}
    
    									if ((d2->getSquare() == s1) && !o1->isOccupied()){			// checking if top right square is occupied
    				
    									fm = true;
    									}
    		
    									if (current->isKing()){
    										if ((d2->getSquare() == s2) && !o2->isOccupied()){		// checking if bottom left square is occupied
    										fm = true;
    										}
    			
    									}
    			
    									if (current->isKing()){
    										if ((d2->getSquare() == s3) && !o3->isOccupied()){		// checking if bottom right square is occupied
    										fm = true;
    										}
    									}
    									
    									
    								}
    					}	
    			if (fm) {		
    			
    					forcedMovesp1.push_back(i);
    			}
    			}

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Perhaps less indentation would help....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    37
    sorry

    Code:
    if (cp==1){
    
    	for(int i=0; i<player1->getNDraughts(); i++){
    	std::cout << "loop"<<endl;
    
    	Draught * d1 = player1->getDraught(i);
    	Square * d1s = d1->getSquare();
    				
    	for(int j=0; j<player2->getNDraughts(); j++){
    		
    	Draught * d2 = player2->getDraught(j);
    				
    	if(d1s->getY() == 0 || d1s->getY() == 1){
    				
    	Square * s = board->getSquare(d1s->getX()+1, d1s->getY() +1); 			// getting squares for top right
    	Square * o = board->getSquare(d1s->getX()+2, d1s->getY() +2);
    				
    	Square * s1 = board->getSquare(d1s->getX()-1, d1s->getY() +1);			// getting squares for bottom right
    	Square * o1 = board->getSquare(d1s->getX()-2, d1s->getY() +2);
    					
    	if ((d2->getSquare() == s) && !o->isOccupied()){					// checking if top right square is occupied
    
    		fm = true;											
    	}
    				
    	if ((d2->getSquare() == s1) && !o1->isOccupied()){					// checking if bottom right square is occupied
    				
    		fm = true;
    	}
    }
    					
    	else if (sq1->getY() == 6 || sq1->getY() == 7){
    				
    	Square * s = board->getSquare(d1s->getX()+1, d1s->getY()-1); 	// getting squares for top left focred move
    	Square * o = board->getSquare(d1s->getX()+2, d1s->getY()-2);
    					
    	Square * s1 = board->getSquare(d1s->getX()-1, d1s->getY() -1);	// getting squares for bottom left
    	Square * o1 = board->getSquare(d1s->getX()-2, d1s->getY() -2);
    					
    	if ((d2->getSquare() == s) && !o->isOccupied()){			// checking if top right square is occupied
    
    	fm = true;											
    			
    	}
    				
    	if ((d2->getSquare() == s1) && !o1->isOccupied()){			// checking if bottom right square is occupied
    				
    	fm = true;
    								
    	}
    					
    }
    						
    	else {  //rest of squares on the row
    			
    	Square * s = board->getSquare(d1s->getX()+1, d1s->getY()-1);  // getting squares for top left focred move
    	Square * o = board->getSquare(d1s->getX()+2, d1s->getY()-2);
    
    	Square * s1 = board->getSquare(d1s->getX()+1, d1s->getY() +1); // getting squares for top right
    	Square * o1 = board->getSquare(d1s->getX()+2, d1s->getY() +2);
    
    	Square * s2 = board->getSquare(d1s->getX()-1, d1s->getY() -1);	// getting squares for bottom left
    	Square * o2 = board->getSquare(d1s->getX()-2, d1s->getY() -2);
    
    	Square * s3 = board->getSquare(d1s->getX()-1, d1s->getY() +1);	// getting squares for bottom right
    	Square * o3 = board->getSquare(d1s->getX()-2, d1s->getY() +2);
    
    	if ((d2->getSquare() == s) && !o->isOccupied()){			// checking if top left square is occupied
    
    	fm = true;											
    	}
    
    	if ((d2->getSquare() == s1) && !o1->isOccupied()){			// checking if top right square is occupied
    				
    	fm = true;
    	}
    		
    	if (current->isKing()){
    	if ((d2->getSquare() == s2) && !o2->isOccupied()){		// checking if bottom left square is occupied
    	fm = true;
    	}
    			
    	}
    			
    	if (current->isKing()){
    	if ((d2->getSquare() == s3) && !o3->isOccupied()){		// checking if bottom right square is occupied
    	fm = true;
    	}
    }
    									
    									
    }
    }	
    	if (fm) {		
    			
    	forcedMovesp1.push_back(i);
    			
    	}
    	}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM