Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com help in rook movement in chess

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 12-04-2011, 08:10 AM PM User | #1 learner guy New Coder   Join Date: Jul 2011 Posts: 19 Thanks: 6 Thanked 0 Times in 0 Posts help in rook movement in chess hi i am making my rook move with the help of validRook() and rookMove() functions.. i have placed validRook inside rookMove so that it is only executed when validRook return s true.. plz see if my validRook algorithm is correct(Note: this is phase 1 of my game and i just wand the rook to move if and only if all vertical path is clear (no killing yet and no horizontal movement yet )) plz ask questions to clarify yourself and also ignore the other functions for movement of other pieces ,they are commented Code: ```#include #include #include #include using namespace std; void printBoard(char board[8][8],int a[],int i,int j); bool getMove(int arr[],char sr,int sc,char dr,int dc); bool emptySource(char a[][8],int arr[],int & i,int & j); bool emptyDestiny(char a[][8],int arr[],int & i,int & j); //movements void rookMove(char board[8][8],int a[],bool rook); void nightMove(char board[8][8],int a[]); void bishopMove(char board[8][8],int a[]); void kingMove(char board[8][8],int a[]); void queenMove(char board[8][8],int a[]); void pawnMove(char board[8][8],int a[]); //cheks on movements bool validRook(char board[][8],int a[],int i); void main (){ char sr='0',dr='0'; int sc=0,dc=0; int n=4; char again; int move[4]={sr,sc,dr,dc}; bool ok =false; int row=0;int col=0; char board[8][8]={ {'R','N','B','Q','K','B','N','R' }, {'P','P','P','P','R','P','P','R' }, {' ','R',' ',' ',' ',' ',' ',' ' }, {' ',' ',' ',' ',' ',' ',' ',' ' }, {' ',' ',' ',' ',' ',' ',' ',' ' }, {' ','R',' ',' ',' ',' ',' ',' ' }, {'p','p','p','p','p','p','p','p' }, {'r','n','b','q','k','b','n','r' } }; printBoard(board,move,row,col); cout << endl; do{ tryAgain: cout << endl; cout <<"Enter source coordinates :" ; cin >> sr; cout << "& "; cin >> sc; cout <<"Enter destination coordinates :" ; cin >> dr; cout << "& "; cin >> dc; getMove( move, sr, sc, dr, dc); emptySource(board,move,row,col); emptyDestiny(board,move,row,col); bool hi = getMove( move, sr, sc, dr, dc); bool bi = emptySource(board,move,row,col); bool di = emptyDestiny(board,move,row,col); cout << endl; if(hi == true && bi == true && di == true ){ ok = true; }else{ ok=false; } if(ok==true){ int k=move[0]; bool rook = validRook(board,move,k); rookMove(board,move,rook); // nightMove( board,move); //bishopMove(board,move); //kingMove(board,move); //queenMove(board,move); //pawnMove(board,move); cout << "\n\n"; printBoard(board,move,row,col); cout << "\n"; goto tryAgain; }else if(ok==false) { cout << "Oops u messed that up !Input r to retry:"; cin>>again; //system("cls"); } cout << endl; }while(again=='r' || again=='R'); } void printBoard(char board[8][8],int a[],int i,int j){ char l; cout << " "; for(int n=1;n<9;n++){ cout <<" " << n<< " "; } cout << endl;cout << endl; for( i=0,l=65 ;i<8,l<=72;i++,l++){ cout << l << ":" << " "; for( j=0;j<8;j++){ cout << " " << board[i][j] << '|' << " "; } cout << endl ; cout << " _______________________________"; cout << endl ; } } bool getMove(int arr[],char sr,int sc,char dr,int dc){ sr=toupper((unsigned char)sr);//capitalize char coordinates dr=toupper((unsigned char)dr); if ((sr < 'A' || sr > 'H') ||//source is in range (sc < 1 || sc > 8)) { cout << "source out of range\n"; return false; } if((dr < 'A' || dr > 'H') ||//destiny is in range (dc < 1 || dc > 8)){ cout << "destiny out of range\n"; return false; } int x=sr-'A'; int z=dr-'A'; arr[0]=x;//get ascii of rows arr[1]=sc-1;//get index started from 0 arr[2]=z; arr[3]=dc-1; if (arr[0]==arr[2] && arr[1]==arr[3]){//sourcebox and destinationbox are same cout << "source and destiantion are same\n"; return false; } return true; } bool emptySource(char a[][8],int arr[],int & i,int & j){ i=arr[0]; j=arr[1] ; if (a[i][j] != ' ') {//source must be filled return true; }else if (a[i][j] == ' ') { cout << "Source must be filled \n"; return false; }else { return false;} } bool emptyDestiny(char a[][8],int arr[],int & i,int & j){ i=arr[2]; j=arr[3] ; if (a[i][j] == ' ') {//source must be filled return true; }else if (a[i][j] != ' ') { cout << "Destiny must be empty\n"; return false; }else { return false; } } void rookMove(char board[8][8],int a[],bool rook){ if(board[a[0]][a[1]] =='R' && rook == true){ board[a[0]][a[1]] =' '; board[a[2]][a[3]] ='R'; } } void nightMove(char board[8][8],int a[]){ if(board[a[0]][a[1]] =='N'){ board[a[0]][a[1]] =' '; board[a[2]][a[3]] ='N'; } } void bishopMove(char board[8][8],int a[]){ if(board[a[0]][a[1]] =='B'){ board[a[0]][a[1]] =' '; board[a[2]][a[3]] ='B'; } } void kingMove(char board[8][8],int a[]){ if(board[a[0]][a[1]] =='K'){ board[a[0]][a[1]] =' '; board[a[2]][a[3]] ='K'; } } void queenMove(char board[8][8],int a[]){ if(board[a[0]][a[1]] =='Q'){ board[a[0]][a[1]] =' '; board[a[2]][a[3]] ='Q'; } } void pawnMove(char board[8][8],int a[]){ if(board[a[0]][a[1]] =='P'){ board[a[0]][a[1]] =' '; board[a[2]][a[3]] ='P'; } } bool validRook(char board[][8],int a[],int i){ if(a[0]=a[2]){ for( i=a[0];i>a[2]; i--){ if(board[i][a[1]] != ' '){ return false; }else { cout << "destiny is biggerrrrrrrrrrrrrrrrrrrrrr"; return true; } } }else{ cout << "source is biggerrrrrrrrrrrrrrrrrrrrrr"; return false; } }```

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 01:51 PM.