/*Return Location of King with given Color*/ Location *kingLocation(char board[BOARD_SIZE][BOARD_SIZE], Color col){ int i, j; for (i = 0; i < BOARD_SIZE; i++){ for (j = 0; j < BOARD_SIZE; j++){ if (getTypeFromChar(board[i][j]) == KING&&getColFromChar(board[i][j]) == col){ return setLocation(i, j); } } } return setLocation(0, 0); }
/*Determine whether a specific Move from Source to Destination can be performed*/ int legalMoveToKing(Game *game, Location *source, Location *dest){ Type type = getTypeFromChar(game->board[source->column][source->row]); switch (type){ case PAWN:return legalPawnMove(game, source, dest); case BISHOP: return legalBishopMove(game, source, dest); case ROOK: return legalRookMove(game, source, dest); case KNIGHT: return legalKnightMove(game, source, dest); case KING: return legalKingMove(game, source, dest); case QUEEN:return legalQueenMove(game, source, dest); case NONETYPE:return 0; } return 0; }
/*Not implemented - update Game Settings after movement to disqualify Castling*/ void updateCastling(Game *game, Move *move){ //Type type = getTypeFromLoc(game->board, move->source); Type type = getTypeFromChar(game->board[move->source->column][move->source->row]); Color col = getColFromLoc(game->board, move->source); int res = 0; switch (type){ case ROOK:res = (col == WHITE) ? 1 : 2; break; case KING:res = (col == WHITE) ? 3 : 4; break; default: break; } switch (res){ case 1: game->settings = (move->source->column == 0) ? setRookBit(game->settings, WHITE, 0) : setRookBit(game->settings, WHITE, BOARD_SIZE - 1); break; case 2: game->settings = (move->source->column == 0) ? setRookBit(game->settings, BLACK, 0) : setRookBit(game->settings, BLACK, BOARD_SIZE - 1); break; case 3: game->settings = setRookBit(game->settings, WHITE, -1); break; case 4: game->settings = setRookBit(game->settings, BLACK, -1); break; } }
void LevelLoader::loadLine(QDomElement lineNode, QList< Brick* >& bricks) { // Reading the line number QDomAttr attribute = lineNode.attributeNode("Number"); QDomElement attributeNode = lineNode.firstChildElement("Number"); if( !attribute.isNull() ){ m_lineNumber = attribute.value().toInt(); } else if( !attributeNode.isNull() ) { m_lineNumber = attributeNode.text().toInt(); } else { // Standard line numbering: load next line m_lineNumber++; } // Reading the brick information attribute = lineNode.attributeNode("Bricks"); attributeNode = lineNode.firstChildElement("Bricks"); QString line; if( !attribute.isNull() ){ line = attribute.value(); } else if( !attributeNode.isNull() ) { line = attributeNode.text(); } else { line = lineNode.text(); } if( line.size() > WIDTH ){ qDebug() << "Invalid levelset " << m_levelname << ": too many bricks in line " << m_lineNumber << endl; } // Convert line information to bricks for( int x = 0; x < line.size(); x++ ){ char charType = line[x].toLatin1(); if (charType != '-') { bricks.append( new Brick(m_game, getTypeFromChar(charType), x+1, m_lineNumber) ); } } }
/*Return Piece Type in given Location*/ Type getTypFromLoc(char board[BOARD_SIZE][BOARD_SIZE], Location *loc){ char c = getCharFromLoc(board, loc); return getTypeFromChar(c); }