That's a lot to cover. I suggest you ditch the clock idea for now, and focus on working out the simulation of a chess game, probably with a 2D view so you can see what's going on. I started one myself a while ago...
Maybe it'll help (if not, oh well), but here's as far as I got (keep in mind this is some of my older code; it's not up to my current standards!):
Quote:static int squareSize = 40;
ChessSet MySet = new ChessSet(squareSize);
void setup(){
size( (8*squareSize)+1, (8*squareSize)+1 );
}
void draw(){
MySet.draw();
}
class ChessSet {
int isquareSize;
ChessPiece[] pieces;
ChessSet(int squareSize) {
isquareSize = ( squareSize > 0 ) ? squareSize : 20;
pieces = new ChessPiece[32];
pieces[0] = new ChessPiece( 0, 6, 1, true );
pieces[1] = new ChessPiece( 1, 6, 1, true );
pieces[2] = new ChessPiece( 2, 6, 1, true );
pieces[3] = new ChessPiece( 3, 6, 1, true );
pieces[4] = new ChessPiece( 4, 6, 1, true );
pieces[5] = new ChessPiece( 5, 6, 1, true );
pieces[6] = new ChessPiece( 6, 6, 1, true );
pieces[7] = new ChessPiece( 7, 6, 1, true );
pieces[8] = new ChessPiece( 0, 1, 1, false );
pieces[9] = new ChessPiece( 1, 1, 1, false );
pieces[10] = new ChessPiece( 2, 1, 1, false );
pieces[11] = new ChessPiece( 3, 1, 1, false );
pieces[12] = new ChessPiece( 4, 1, 1, false );
pieces[13] = new ChessPiece( 5, 1, 1, false );
pieces[14] = new ChessPiece( 6, 1, 1, false );
pieces[15] = new ChessPiece( 7, 1, 1, false );
pieces[16] = new ChessPiece( 0, 7, 2, true );
pieces[17] = new ChessPiece( 1, 7, 3, true );
pieces[18] = new ChessPiece( 2, 7, 4, true );
pieces[19] = new ChessPiece( 3, 7, 6, true );
pieces[20] = new ChessPiece( 4, 7, 5, true );
pieces[21] = new ChessPiece( 5, 7, 4, true );
pieces[22] = new ChessPiece( 6, 7, 3, true );
pieces[23] = new ChessPiece( 7, 7, 2, true );
pieces[24] = new ChessPiece( 0, 0, 2, false );
pieces[25] = new ChessPiece( 1, 0, 3, false );
pieces[26] = new ChessPiece( 2, 0, 4, false );
pieces[27] = new ChessPiece( 3, 0, 6, false );
pieces[28] = new ChessPiece( 4, 0, 5, false );
pieces[29] = new ChessPiece( 5, 0, 4, false );
pieces[30] = new ChessPiece( 6, 0, 3, false );
pieces[31] = new ChessPiece( 7, 0, 2, false );
}
int pieceAt(int column, int row ){
for( int i = 0; i< pieces.length; i++) {
if ( ( pieces[i].getColumn() == column ) && ( pieces[i].getRow() == row ) ) {
return( pieces[i].getType() );
}
}
return(0);
}
boolean whoOwns(int column, int row ){
if( !isEmpty( column, row ) ) {
for( int i = 0; i< pieces.length; i++) {
if ( ( pieces[i].getColumn() == column ) && ( pieces[i].getRow() == row ) ) {
return( pieces[i].getIsWhite() );
}
}
}
return(false);
}
boolean isEmpty(int column, int row ){
return( pieceAt(column, row) == 0 );
}
void draw(){
stroke(color(128));
for ( int i=0; i<8; i++ ) {
for ( int j=0; j<8; j++ ) {
fill(color(0));
if( ((i+j) % 2) == 1){
fill(color(255));
}
rect( (i*isquareSize), (j*isquareSize), isquareSize, isquareSize); // Draw a background square
// Draw a piece if there is one there.
if( !isEmpty(i, j) ){
fill(color(0,0,128));
if( whoOwns( i, j ) ) {
fill(color(128,0,0));
}
int temp = pieceAt( i, j );
rect( (i*isquareSize)+5, (j*isquareSize)+5, isquareSize-29+(3*temp), isquareSize-29+(3*temp) );
}
}
}
} // End ChessSet.draw()
}
class ChessPiece {
int icolumn;
int irow;
int itype;
boolean iisLive = true;
boolean iisWhite;
ChessPiece( int column, int row, int type, boolean isWhite ) {
icolumn = column;
irow = row;
itype = type;
iisWhite = isWhite;
}
int getRow(){
return(irow);
}
int getColumn(){
return(icolumn);
}
int getType(){
return(itype);
}
boolean getIsWhite(){
return(iisWhite);
}
void setColumn(int column){
if( iisLive ){
icolumn = column;
}
}
void setRow(int row){
if( iisLive ){
irow = row;
}
}
void setType(int type){
if( iisLive ){
itype = type;
}
}
void kill(){
iisLive = false;
irow = -1;
icolumn = -1;
itype = 0;
}
}