1 / 13

SLU CHESS

SLU CHESS. By: James Cofield Dustin Dotson Travis Larkins Forest Marie Accidental Productions 2002. Introduction. Who are we? About our chess program. Documentation. --Presented by James Cofield. Graphics—A Larkian approach. Please wait while processing…. Chess logic and math.

Download Presentation

SLU CHESS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SLU CHESS By: James Cofield Dustin Dotson Travis Larkins Forest Marie Accidental Productions 2002

  2. Introduction • Who are we? • About our chess program.

  3. Documentation --Presented by James Cofield

  4. Graphics—A Larkian approach Please wait while processing….

  5. Chess logic and math

  6. Setting up the board char pieceIdentifiers[ 66 ]; strcpy( pieceIdentifiers, “_rnbqkbnrpppppppp ……. PPPPPPPPRNBKQBNR”); for ( int walker = 1; walker <= 64; i++ ) DrawPieceToBoard( walker, pieceIdentifiers[ walker ] );

  7. X-Y Position struct Square { int squarePosition; }; int xPosition ( Square & square ) { return ( 1 + ( ( square – 1 ) % 8 ); } Why not square % 8? Consider the positions of 8n, where 1 <= n <= 8. int yPosition( Square & square ) { return 8 – (( square – 1 ) / 8 ); }

  8. Legal Move—Pawns int moveDifference = abs(xPosition( prevSquarePosition ) ) - abs(xPosition(currSquarePosition)); LegalPawnMove() { if ( yPosition( prevSquarePosition ) == yPosition( currSquarePosition )+ 1 ) { if ( !moveDifference ) // if not zero { if ( pieceIdentifiers[ currSquarePosition ] == ‘ ‘ ) return true; } else if ( moveDifference == 1 ) //Possible capture! if ( ( PieceColor( currSquare ) == Black ) return true; } else if ( ( yPosition( prevSquare == 2 ) && ( yPosition( currSquare == 4 ) ) if ( !moveDifference && pieceIdentifer[ currSquarePosition ] == ‘ ‘ && pieceIdentifier[ prevSquarePosition +currSquarePosition / 2 ] == ‘ ‘ ) return true; else return false; }

  9. Legal Move—Knights int moveDifferenceX = abs(( xPosition( prevSquarePosition ) – xPosition( currSquarePosition ) ); int moveDifferenceY = abs(( yPosition( prevSquarePosition ) – yPosition( currSquarePosition ); if ( moveDifferenceX == 2 && moveDifferenceY == 1 ) if ( PieceColor( currSquarePosition ) == White || pieceIdentifier[ currSquarePosition ] == ‘ ‘ ) return true; else if ( moveDifferenceX == 1 && moveDifferenceY == 2 ) if( PieceColor( currSquarePosition ) == White || pieceIdentifier[ currSquarePosition ] == ‘ ‘ ) return true; else return false;

  10. Legal Move—Bishops int xCoordinate = xPosition( prevSquare ); int yCoordinate = yPosition( prevSquare ); Square boardRunner; int pieceColor = PieceColor( prevSquare ); for ( int x = -1; x <= 1; x+= 2 ) for ( int y = -1; y <= 1; y+= 2 ) for ( int z = 1; z <= 7; z++ ) { boardRunner = MouseToSquare( xCoordinate + x * z, yCoordinate + y * z ); //if the next squre is blank or the opposit= color of *this, test to see if the //drop location equals boardRunner if ( PieceColor( boardRunner ) == BLANK || ( PieceColor( boardRunner ) != pieceColor ) if ( boardRunner == currSquare ) //the location tested equals the dropped location. return true; else if ( PieceColor( boardRunner ) != ‘ ‘ ) break; } return false; //FALSE OTHERWISE

  11. Legal Move—Rook int xCoordinate = xPosition( prevSquare ); int yCoordinate = yPosition( currSquare ); Square boardRunner; int pieceColor = PieceColor( prevSquare ); //Run up X side. for ( int x = -1; x <=1; x+= 2 ) for ( int r = -1; r <= 7; r++ ) { boardRunner = MouseToSquare( xCoordinate + x * r, yCoordinate ); if ( PieceColor( boardRunner ) == BLANK || PieceColor( boardRunner ) != pieceColor ) if ( v == currSquare ) return true; else if ( PieceColor( boardRunner ) != ‘ ‘ ) break; } //Run up Y side. for ( int y = -1; y <=1; y+= 2 ) for ( int r = 1; r <=7; r++ ) …….

  12. Legal Move—Queens bool legalQueenMove = legalBishopMove( prevSquarePosition, currSquarePosition ); return ( legalQueenMove == true ) ? legalQueenMove : legalRookMove( prevSquarePosition, currSquarePosition );

  13. Legal Move—Kings int xCoordinate = xPosition( currSquarePosition ); int yCoordinate = yPosition( currSquarePosition ); int xDifference = abs( ( xPosition( prevSquarePosition ) – xPosition( currSquarePosition ) ); int yDifference = abs( ( yPosition( prevSquarePosition ) – yPosition( currSquarePosition ) ); if ( xDifference <=1 && yDifference <=1 && !whiteInCheck( currSquarePosition ) return true; if( SquarePositionLiteral(oldSquarePosition ) == E1&& SquarePositionLiteral( currSquarePosition ) == G1&& CastlingAllowed( WhiteKingSide ) && !whiteInCheck( currSquarePosition ) ) return true; else if ( SquarePositionLiteral( oldSquarePosition ) == E1 && SquarePositionLiteral( currSquarePosition ) == C1 && CastlingAllowed( WhiteQueenSide ) && !whiteInCheck( currSquarePosition ) ) return true;

More Related