chess program for movement of queens and pawns...

This is a discussion on chess program for movement of queens and pawns... within the C Programming forums, part of the General Programming Boards category; i am a student working on this and i am looking for some help... if you want a copy of ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    16

    Exclamation chess program for movement of queens and pawns...

    i am a student working on this and i am looking for some help... if you want a copy of what i have leave me an email address

  2. #2
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    or anyone with msn add <<deleted>>
    Last edited by Salem; 02-28-2006 at 01:17 AM. Reason: Remove email address

  3. #3
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    What are you struggling with? We also have an AI board if the trouble is in that sector

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    not AI... there is no Ai in this one... its supposed to be simple... i can not seem to get my queens to move as they should

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    if i can send you the file would u be able to help me?

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    anyone?

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    Why don't you post some code.
    Sent from my iPadŽ

  8. #8
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    id rather send it... i tried posting code but it didnt work

  9. #9
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    ill send you the text file

  10. #10
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    ?????

  11. #11
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    The only reason I can think of that posting didn't code work is the tags
    << !! Posting Code? Read this First !! >>

    From what I've seen, people don't really do 1-1 things like aim, so for best chance of help...find some way to express the question here

  12. #12
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    ok...

    Code:
    int move_queen (Colour colour, int from_col, int from_row,
    	   int to_col, int to_row)
    {
        if((from_row-to_row==0)&&(from_col-to_col==0))//check if same square
             {printf("e1");
    
             return 2;//return error
             }
    
        if((board[to_row][to_col].colour==colour)&&
                                               (board[to_row][to_col].piece!=empty))
                      //check if destination has piece of same colour
              {printf("e2");
               return 2;//return error
               }
         int i;//initialization
         int j;//initialization
        if((to_col==from_col)&&(to_row!=from_row))//if vertical move
        {
          if((to_row-from_row)>0) //if upwards
              for(i=1;i<(to_row-from_row);i++)//count in between spaces up
                 if (board[from_row+i][from_col].piece==empty||board[from_row+i][from_col].colour!=colour)
                   {
                     board[to_row][to_col].piece=queen;
                     board[to_row][to_col].colour=colour;
                     board[from_row][from_col].piece=empty;
                     board[from_row][from_col].colour=white;
                     return 0; //return success value
                    }
                    else
                     {printf("e3");
                     return 2;  //return error value
                      }
          }
            else //if downwards
    
               for(i=0;i<(from_row-to_row);i++)//count in between spaces down
                {  if (board[from_row-i][from_col].piece!=empty)//if not a clear path
                    {printf("e4");
                    return 2;  //return error value
                    }
                   else  //move piece
                   {
                     board[to_row][to_col].piece=queen;
                     board[to_row][to_col].colour=colour;
                     board[from_row][from_col].piece=empty;
                     board[from_row][from_col].colour=white;
                     return 0;   //return success value
                    }
    
                }//end for
    
           // }//end verticle move
    
    
    
       if((to_row==from_row)&&(to_col!=from_col))//if horizontal move
            {
              if(to_col-from_col>=0)//if move right
                 for(i=1;i<(to_col-from_col);i++)//count in between spaces left
                     if(board[from_row][from_col+i].piece==empty)
                        { printf("got here");
                          board[to_row][to_col].piece=queen;
                          board[to_row][to_col].colour=colour;
                          board[from_row][from_col].piece=empty;
                          board[from_row][from_col].colour=white;
                          printf("Here too");
                          return 0;   //return success value
                         }
                        else
                        {printf("e5");
                        return 2;//return error value
                        }
    
              else //if move left
               {
                 for(i=1;i<(from_col-to_col);i++)
                   if(board[from_row][from_col-i].piece==empty)
                    {
                      board[to_row][to_col].piece=queen;
                      board[to_row][to_col].colour=colour;
                      board[from_row][from_col].piece=empty;
                      board[from_row][from_col].colour=white;
                      return 0;   //return success value
                     }
                    else
                     {printf("e6");
                     return 2; //return an error value
                      }
                 } //end move left
              }//end horizontal
    
    
          if((abs(to_col-from_col))==(abs(to_row-from_row)))//if diagonal
             { printf("%d %d diagonal",(to_col-from_col),(to_row-from_row));
    
               if((to_col-from_col)>0&&(to_row-from_row)>0)   //*up and right
                  for(i=1;i<(to_col-from_col);i++)  //count column
                    for(j=1;j<(to_row-from_row);j++) //count row
                     if(board[from_row+j][from_col+i].piece==empty)//if empty
                        {
                          printf("got here");
                          board[to_row][to_col].piece=queen;
                          board[to_row][to_col].colour=colour;
                          board[from_row][from_col].piece=empty;
                          board[from_row][from_col].colour=white;
                          printf("got here 2\n");
                          return 0;   //return success value
                        }
                        else {printf("e8");
                          return 2;//return an error value
                             }
             if(((to_col-from_col)>0)&&(to_row-from_row)<0) //down and right
                {printf("........ this!");
                  for(i=1;i>(from_col-to_col);i++)    //count column
                    {printf("past here");
                     for(j=1;j>(to_row-from_row);j++) //count row
                     { printf("%d",(board[from_row-j][from_col+i].piece==empty));
                       if(board[from_row-j][from_col+i].piece==empty) //if empty
                           {
                             printf("down and Right");
                             board[to_row][to_col].piece=queen;
                             board[to_row][to_col].colour=colour;
                             board[from_row][from_col].piece=empty;
                             board[from_row][from_col].colour=white;
                             return 0;   //return success value
                          }
                        else {printf("e9");
                             return 2;//return an error value
                              }
               }      }            }
               if((to_col-from_col)<0&&(to_row-from_row)>0)  //*up and left
                  for(i=1;i,(to_col-from_col);i++)//count column
                     for(j=1;j<(to_row-from_row);j++) //count row
                        if(board[from_row+j][from_col-i].piece==empty)//if empty
                            {
                              printf("down and right repair");
                              board[to_row][to_col].piece=queen;
                              board[to_row][to_col].colour=colour;
                              board[from_row][from_col].piece=empty;
                              board[from_row][from_col].colour=white;
                              return 0;   //return success value
                             }
                         else  {printf("e10");
                            return 2;//return an error value
                                }
               if((to_col-from_col)<0&&(to_row-from_row)<0) //*down and left
                       for(i=1;i<(from_col-to_col);i++) //count the column
                         for(j=1; j<(from_row-to_row);j++)//count the row
                           if(board[from_row-j][from_col-i].piece==empty)//if empty
                                { printf("down and left");
                                  board[to_row][to_col].piece=queen;
                                  board[to_row][to_col].colour=colour;
                                  board[from_row][from_col].piece=empty;
                                  board[from_row][from_col].colour=white;
                                  return 0;   //return success value
                                }
                            else
                              {printf("error");
                              return 2; //return an error value
                              }
             }//end if diagonal
     } //end queens move

  13. #13
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    thats the problem area... all variables are declared before and stuff like that... disregard the comments.... shows frustration.... any help would be great

  14. #14
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    anyone???

  15. #15
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Sometimes it is useful to take out a piece of paper, and right down an algorithm in pseudocode (or draw a diagram, or something).

    If you can't do this, then you won't be able to code a solution and will instead wind up with a mess.

    Another suggestion, look up how to properly format your code.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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