slu chess
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
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
1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32
33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64
A B C D E F G H
Setting up the board
char pieceIdentifiers[ 66 ];
strcpy( pieceIdentifiers, “_rnbqkbnrpppppppp ……. PPPPPPPPRNBKQBNR”);
for ( int walker = 1; walker <= 64; i++ )
DrawPieceToBoard( walker, pieceIdentifiers[ walker ] );
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 ); }
Legal Move—Pawnsint 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; }
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;
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
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++ )
…….
Legal Move—Queens
bool legalQueenMove = legalBishopMove( prevSquarePosition, currSquarePosition );
return ( legalQueenMove == true ) ? legalQueenMove : legalRookMove( prevSquarePosition,
currSquarePosition );
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;