![]() |
| | #1 |
| Registered User Join Date: Mar 2007
Posts: 37
| Loop seg error 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 | |
| | #2 |
| and the hat of vanishing 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 | |
| | #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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |