C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-28-2007, 01:15 PM   #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);
			}
			}
Zishaan is offline   Reply With Quote
Old 03-28-2007, 01:22 PM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
Perhaps less indentation would help....
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 03-28-2007, 01:27 PM   #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);
			
	}
	}
Zishaan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner Needs help in Dev-C++ Korrupt Lawz C++ Programming 18 05-02-2009 12:27 PM
how do you resolve this error? -EquinoX- C Programming 32 11-05-2008 04:35 PM
load gif into program willc0de4food Windows Programming 14 01-11-2006 10:43 AM
using c++ in c code hannibar C Programming 17 10-28-2005 09:09 PM
Post... maxorator C++ Programming 12 10-11-2005 08:39 AM


All times are GMT -6. The time now is 06:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22