bool CEdge::NextNodeIsTerminal() { return IsTerminalCategory( GetPiece( m_DotLocation ) ); }
//--------------------------------------------------------------------------- void __fastcall TFormClientRep::ProcHistory(bool All) { AnsiString Title = "ѕросмотр истории изменени¤"; AnsiString FldKey = WrkGData->FieldKey; AnsiString TableName = GetPiece(FldKey,"_ID",1).UpperCase(); int ID = WrkGData->WrkDSet->FieldByName(FldKey)->AsInteger; AnsiString FieldNames; AnsiString TitleNames; AnsiString SS; TDBGridEh* Grid = WrkGData->WrkGrid; TStringList* FieldNamesList = new TStringList(); TStringList* TitleNamesList = new TStringList(); AnsiString AllFieldNames; if (All) { TDBGridColumnsEh* Columns = Grid->Columns; int Cnt = Columns->Count; AnsiString S; bool KeyIncduded = true; for (int i = 0; i < Cnt; i++) { TColumnEh* Column = Columns->Items[i]; if (Column->Visible) { AnsiString X = ","+TranslateName(Column->FieldName); if (!AllFieldNames.Pos(X)) { AllFieldNames += X; FieldNames += X ; SS = Column->Title->Caption; TitleNames += "," + GetPiece(SS, "|",1); SS = GetPiece(SS, "|",2); if (SS != "") TitleNames += "-> " + SS; if (FieldNames.Length() > 230 || TitleNames.Length() > 200) { KeyIncduded = KeyIncduded || FieldNames.Pos("," + FldKey); FieldNames = FieldNames.SubString(2,1000); TitleNames = TitleNames.SubString(2,1000); FieldNames = FieldNames.UpperCase(); FieldNamesList->Add(FieldNames); TitleNamesList->Add(TitleNames); FieldNames = ""; TitleNames = ""; } } } } if (!KeyIncduded) { FieldNames = "," +FldKey + FieldNames + ",STATUS"; TitleNames = ",N записи" + TitleNames + ",—осто¤ние"; } else { FieldNames = FieldNames + ",STATUS"; TitleNames = TitleNames + ",—осто¤ние"; } FieldNames = FieldNames.SubString(2,1000); TitleNames = TitleNames.SubString(2,1000); FieldNames = FieldNames.UpperCase(); FieldNamesList->Add(FieldNames); TitleNamesList->Add(TitleNames); FieldNames = ""; TitleNames = ""; Title = Title + " всех видимых полей"; } else { TColumnEh* Column = Grid->Columns->Items[Grid->Col - 1]; FieldNames = TranslateName(Column->FieldName); SS = Column->Title->Caption; TitleNames = GetPiece(SS, "|",1); SS = GetPiece(SS, "|",2); if (SS != "") TitleNames += "-> " + SS; Title = Title + " пол¤ > "+ TitleNames + " <"; FieldNames = FieldNames.UpperCase(); FieldNamesList->Add(FieldNames); TitleNamesList->Add(TitleNames); } RestValue RestData; if (SimpleSelHistoryID(this, 0,Title,TableName,ID,FieldNamesList,TitleNamesList,RestData)) { // RestoreValue(RestData,!All); } }
CStringSurrogate CEdge::GetLHS() { return GetPiece(1); }
bool CEdge::NextNodeIsNonterminal() { CSS ssPiece = GetPiece( m_DotLocation ); return !IsTerminalCategory( ssPiece ); }
CSS CEdge::GetNextNode() { return GetPiece( m_DotLocation ); }
QString CEdge::LHS() { return GetPiece(1).Display(); }
void ChessBoard::PromotePawn(Pawn* pawn, const ChessSquare* MoveTo, char PromotionPiece) { ChessSquare pieceLoc; pawn->GetLocation(pieceLoc); ChessMove* newMove = NULL; if ((MoveTo->row) != (pawn->GetLocation().row )) { if (!GetPiece(MoveTo->row, MoveTo->col)) ChessAssert(); bWhiteMove ? _BlackPlayer->RemovePiece(GetPiece(MoveTo->row, MoveTo->col)) : _WhitePlayer->RemovePiece(GetPiece(MoveTo->row, MoveTo->col)); //NEED TO CHANGE THIS newMove = new ChessMove(pawn, pieceLoc.row, pieceLoc.col,MoveTo->row, MoveTo->col, true, this); #ifdef PRINT_MEMORY_MOVES printf("Created move at: %i\n", newMove); fflush(stdout); #endif Board[MoveTo->row][MoveTo->col] = NULL; } else { newMove = new ChessMove(pawn, pieceLoc.row, pieceLoc.col,MoveTo->row, MoveTo->col, false, this); #ifdef PRINT_MEMORY_MOVES printf("Created move at: %i\n", newMove); fflush(stdout); #endif } newMove->SetPromotion(true); Board[pieceLoc.row][pieceLoc.col] = NULL; if(pieceToText(pawn) != 'P') ChessAssert(); ChessPiece* newPiece; Player* currPlayer; ChessSquare currLoc = pawn->GetLocation(); if ( pawn->isWhite() ) { if(pawn->GetLocation().col != 6) ChessAssert(); currPlayer = _WhitePlayer; } else { if(pawn->GetLocation().col != 1) ChessAssert(); currPlayer = _BlackPlayer; } //char* c = new char; //bool bValidChar; //bValidChar = false; // //printf("What piece would you like to turn the pawn into? Type N, R, B, or Q"); //while (! (bValidChar) ) { //std::cin >> c; switch(PromotionPiece) { case 'N': newPiece = new Knight(MoveTo->row, MoveTo->col, pawn->isWhite(), this); newPiece->SetIsInKingArray(false); break; case 'n': newPiece = new Knight(MoveTo->row, MoveTo->col, pawn->isWhite(), this); newPiece->SetIsInKingArray(false); break; case 'R': newPiece = new Rook(MoveTo->row, MoveTo->col, pawn->isWhite(), this); newPiece->SetIsInKingArray(false); break; case 'r': newPiece = new Rook(MoveTo->row, MoveTo->col, pawn->isWhite(), this); newPiece->SetIsInKingArray(false); break; case 'B': newPiece = new Bishop(MoveTo->row, MoveTo->col, pawn->isWhite(), this); newPiece->SetIsInKingArray(false); break; case 'b': newPiece = new Bishop(MoveTo->row, MoveTo->col, pawn->isWhite(), this); newPiece->SetIsInKingArray(false); break; case 'Q': newPiece = new Queen(MoveTo->row, MoveTo->col, pawn->isWhite(), this); newPiece->SetIsInKingArray(false); break; case 'q': newPiece = new Queen(MoveTo->row, MoveTo->col, pawn->isWhite(), this); newPiece->SetIsInKingArray(false); //bValidChar = true; break; default: ChessAssert(); printf("Please enter in N, R, B, or Q"); break; } } newMove->makeMove(); newMove->SetPromotionChar(PromotionPiece); if (bWhiteMove) { if (_WhitePlayer->IsInCheck() ) _WhitePlayer->ClearCheckState(); } else { if (_BlackPlayer->IsInCheck() ) _BlackPlayer->ClearCheckState(); } ResolveCheck(bWhiteMove); if (bWhiteMove) { if (_BlackPlayer->IsInCheck() ) newMove->SetCheckMove(true); else { newMove->SetCheckMove(false); } } else { if (_WhitePlayer->IsInCheck() ) newMove->SetCheckMove(true); else { newMove->SetCheckMove(false); } } currPlayer->PawnPromotion(pawn, newPiece); bWhiteMove = !bWhiteMove; bBlackMove = !bBlackMove; #ifndef SUPPRESS_OUTPUT _ChessLogInstance->printLog(); PrintBoard(); #endif ResolveLineOfSight(newPiece); //printf("Promotion Below: \n"); //ChessBoard::GetInstance()->PrintBoard(); }
void ChessBoard::EnPassantCapture(ChessPiece* piece, const ChessSquare& MoveTo, const ChessSquare& CaptPieceLoc) { ChessPiece* captPiece = GetPiece(CaptPieceLoc.row, CaptPieceLoc.col); if(!captPiece) ChessAssert(); ChessSquare pieceLoc; piece->GetLocation(pieceLoc); bool bOpponentInCheck = false; if (bWhiteMove) { if (_BlackPlayer->IsInCheck() ) bOpponentInCheck = true; } else { if (_WhitePlayer->IsInCheck() ) bOpponentInCheck = true; } ChessMove* newMove = new ChessMove(piece, pieceLoc.row, pieceLoc.col, MoveTo.row, MoveTo.col, true, bOpponentInCheck, this); #ifdef PRINT_MEMORY_MOVES printf("Created move at: %i\n", newMove); fflush(stdout); #endif bWhiteMove ? _BlackPlayer->RemovePiece(GetPiece(CaptPieceLoc.row, CaptPieceLoc.col)) : _WhitePlayer->RemovePiece(GetPiece(CaptPieceLoc.row, CaptPieceLoc.col)); Board[MoveTo.row][MoveTo.col] = NULL; Board[MoveTo.row][MoveTo.col] = piece; Board[pieceLoc.row][pieceLoc.col] = NULL; Board[CaptPieceLoc.row][CaptPieceLoc.col] = NULL; piece->SetCol(MoveTo.col); piece->SetRow(MoveTo.row); newMove->makeMove(); #ifdef SUPPRESS_OUTPUT _ChessLogInstance->printLog(); PrintBoard(); #endif ResolveCheck(bWhiteMove); if (bWhiteMove) { if (_BlackPlayer->IsInCheck() ) newMove->SetCheckMove(true); else { newMove->SetCheckMove(false); } } else { if (_WhitePlayer->IsInCheck() ) newMove->SetCheckMove(true); else { newMove->SetCheckMove(false); } } bWhiteMove = !bWhiteMove; bBlackMove = !bBlackMove; }
void ChessBoard::MakeCapture(ChessPiece* piece, const ChessSquare& MoveTo) { ChessPiece* captPiece = GetPiece(MoveTo.row, MoveTo.col); if (!captPiece) ChessAssert(); if (pieceToText(piece) == 'K') (dynamic_cast<King*>(piece))->SetHasMoved(true); else if (pieceToText(piece) == 'R') (dynamic_cast<Rook*>(piece))->SetHasMoved(true); ChessSquare pieceLoc; piece->GetLocation(pieceLoc); ChessMove* newMove = new ChessMove(piece, pieceLoc.row, pieceLoc.col, MoveTo.row, MoveTo.col, true, this); #ifdef PRINT_MEMORY_MOVES printf("Created move at: %i\n", newMove); fflush(stdout); #endif bWhiteMove ? _BlackPlayer->RemovePiece(captPiece) : _WhitePlayer->RemovePiece(captPiece); Board[MoveTo.row][MoveTo.col] = NULL; Board[MoveTo.row][MoveTo.col] = piece; Board[pieceLoc.row][pieceLoc.col] = NULL; piece->SetCol(MoveTo.col); piece->SetRow(MoveTo.row); newMove->makeMove(); #ifndef SUPPRESS_OUTPUT _ChessLogInstance->printLog(); PrintBoard(); #endif ResolveCheck(bWhiteMove); if (bWhiteMove) { if (_BlackPlayer->IsInCheck() ) newMove->SetCheckMove(true); else { newMove->SetCheckMove(false); } } else { if (_WhitePlayer->IsInCheck() ) newMove->SetCheckMove(true); else newMove->SetCheckMove(false); } bWhiteMove = !bWhiteMove; bBlackMove = !bBlackMove; }
void ChessBoard::UndoMove() { Player* currPlayer; Player* opponentPlayer; bool bKingMoved = false; int col; if (bWhiteMove) { currPlayer = _BlackPlayer; opponentPlayer = _WhitePlayer; col = 7; } else { currPlayer = _WhitePlayer; opponentPlayer = _BlackPlayer; col = 0; } ChessMove* moveToUndo = _ChessLogInstance->getLastMove(); if ( moveToUndo->isCastle() ) { if (moveToUndo->isKingSideCastle()) { ChessPiece* king = GetPiece(6, col); if(pieceToText(king) != 'K') ChessAssert(); ChessPiece* rook = GetPiece(5, col); if(pieceToText(rook) != 'R') ChessAssert(); rook->SetRow(7); king->SetRow(4); Board[4][col] = king; Board[6][col] = NULL; Board[5][col] = NULL; Board[7][col] = rook; (dynamic_cast<King*>(king))->SetHasMoved(false); (dynamic_cast<King*>(king))->SetHasCastled(false); (dynamic_cast<Rook*>(rook))->SetHasMoved(false); ResolveLineOfSight(rook); } else { ChessPiece* king = GetPiece(2, col); if(pieceToText(king) != 'K') ChessAssert(); ChessPiece* rook = GetPiece(3, col); if(pieceToText(rook) != 'R') ChessAssert(); rook->SetRow(0); king->SetRow(4); Board[4][col] = king; Board[3][col] = NULL; Board[2][col] = NULL; Board[0][col] = rook; (dynamic_cast<King*>(king))->SetHasMoved(false); (dynamic_cast<King*>(king))->SetHasCastled(false); (dynamic_cast<Rook*>(rook))->SetHasMoved(false); ResolveLineOfSight(rook); } bKingMoved = true; } //NEED TO CHECK FOR PAWN PROMOTION HERE else if ( moveToUndo->isPromotion() ) { ChessPiece* newPromoPiece = GetPiece(moveToUndo->getRow(), moveToUndo->getCol()); ChessSquare PromotionSquare = ChessSquare(moveToUndo->getRow(), moveToUndo->getCol()); currPlayer->UndoPawnPromotion(moveToUndo->getStartingRow(), PromotionSquare, newPromoPiece); Board[moveToUndo->getRow()][moveToUndo->getCol()] = NULL; if (PromotionSquare.row != moveToUndo->getStartingRow()) { ChessPiece* capturedPiece = opponentPlayer->FindCapturedPiece(moveToUndo->getRow(), moveToUndo->getCol(), moveToUndo->getCapturedPiece()); if(!capturedPiece) ChessAssert(); ChessSquare capturedPieceLoc = capturedPiece->GetLocation(); if (Board[capturedPieceLoc.row][capturedPieceLoc.col] != NULL ) ChessAssert(); opponentPlayer->RebirthCapturedPiece(capturedPiece); AddPiece(capturedPiece); } //printf("Undid pawn promotion below: \n"); //ChessBoard::GetInstance()->PrintBoard(); } else if ( moveToUndo->IsEnPassant() ) { ChessPiece* capturedPiece = opponentPlayer->FindCapturedPiece(moveToUndo->getRow(), moveToUndo->getStartingCol(), moveToUndo->getCapturedPiece()); if(!capturedPiece) ChessAssert(); ChessPiece* movedPiece = GetPiece(moveToUndo->getRow(), moveToUndo->getCol() ); Board[moveToUndo->getRow()][moveToUndo->getCol()] = NULL; Board[moveToUndo->getRow()][moveToUndo->getStartingCol()] = capturedPiece; Board[moveToUndo->getStartingRow()][moveToUndo->getStartingCol()] = movedPiece; movedPiece->SetRow(moveToUndo->getStartingRow()); movedPiece->SetCol(moveToUndo->getStartingCol()); //AddPiece(capturedPiece); ResolveLineOfSight(capturedPiece); opponentPlayer->RebirthCapturedPiece(capturedPiece); ResolveLineOfSight(movedPiece); } else if ( moveToUndo->isCapture() ) { ChessPiece* capturedPiece = moveToUndo->getCapturedPiece(); if (!capturedPiece) ChessAssert(); ChessPiece* movedPiece = GetPiece(moveToUndo->getRow(), moveToUndo->getCol() ); Board[moveToUndo->getRow()][moveToUndo->getCol()] = capturedPiece; Board[moveToUndo->getStartingRow()][moveToUndo->getStartingCol()] = movedPiece; movedPiece->SetRow(moveToUndo->getStartingRow()); movedPiece->SetCol(moveToUndo->getStartingCol()); if (pieceToText(movedPiece) == 'K') { (dynamic_cast<King*>(movedPiece))->SetHasMoved(false); bKingMoved = true; } else if (pieceToText(movedPiece) == 'R') (dynamic_cast<Rook*>(movedPiece))->SetHasMoved(false); ResolveLineOfSight(capturedPiece); opponentPlayer->RebirthCapturedPiece(capturedPiece); ResolveLineOfSight(movedPiece); } else { ChessPiece* movedPiece = GetPiece(moveToUndo->getRow(), moveToUndo->getCol() ); Board[moveToUndo->getRow()][moveToUndo->getCol()] = NULL; Board[moveToUndo->getStartingRow()][moveToUndo->getStartingCol()] = movedPiece; movedPiece->SetRow(moveToUndo->getStartingRow()); movedPiece->SetCol(moveToUndo->getStartingCol()); if (pieceToText(movedPiece) == 'K') { (dynamic_cast<King*>(movedPiece))->SetHasMoved(false); bKingMoved = true; } else if (pieceToText(movedPiece) == 'R') (dynamic_cast<Rook*>(movedPiece))->SetHasMoved(false); ResolveLineOfSight(movedPiece); } if (bKingMoved) { currPlayer->ClearCheckState(); opponentPlayer->ClearAttackingKingPieces(); ChessSquare kingLoc = currPlayer->GetKingLocation(); for (int i = 0; i < opponentPlayer->GetNumPiecesLeft(); i++) { if (CheckForCheck(opponentPlayer->GetPiece(i)) ) { currPlayer->EnterCheckState(); //printf("Checking Piece: %c", pieceToText(currPlayer->GetAttackingKingPiece(i))); //fflush(stdout); opponentPlayer->AddToKingAttacking(opponentPlayer->GetPiece(i)); } else if (opponentPlayer->GetPiece(i)->HasLineToKing(kingLoc)) opponentPlayer->AddToKingAttacking(opponentPlayer->GetPiece(i)); } } else { for (int i = 0; i < opponentPlayer->GetNumAttackingKingPieces(); i++) { if (CheckForCheck(opponentPlayer->GetAttackingKingPiece(i)) ) { currPlayer->EnterCheckState(); //printf("Checking Piece: %c", pieceToText(opponentPlayer->GetAttackingKingPiece(i))); //fflush(stdout); break; } if (i == (opponentPlayer->GetNumAttackingKingPieces() - 1)) currPlayer->ClearCheckState(); } } for (int i = 0; i < currPlayer->GetNumAttackingKingPieces(); i++) { if (CheckForCheck(currPlayer->GetAttackingKingPiece(i)) ) { opponentPlayer->EnterCheckState(); //printf("Checking Piece: %c", pieceToText(currPlayer->GetAttackingKingPiece(i))); //fflush(stdout); break; } if (i == (currPlayer->GetNumAttackingKingPieces() - 1)) opponentPlayer->ClearCheckState(); } _ChessLogInstance->removeLastItemFromLog(); bWhiteMove = !bWhiteMove; bBlackMove = !bBlackMove; //REMOVE BELOW WHEN WORKING ChessSquare currPlayerKing = currPlayer->GetKingLocation(); /*for (int i = 0; i < opponentPlayer->GetNumPiecesLeft(); i++) { if (opponentPlayer->GetPiece(i)->HasLineToKing(currPlayerKing) ) { if (!(opponentPlayer->GetPiece(i)->IsInKingArray())) { ChessPiece* forTestPiece = opponentPlayer->GetPiece(i); forTestPiece->HasLineToKing(currPlayerKing); ChessAssert(); } } else { if (opponentPlayer->GetPiece(i)->IsInKingArray()) ChessAssert(); } } ChessSquare opponentPlayerKing = opponentPlayer->GetKingLocation(); for (int i = 0; i < currPlayer->GetNumPiecesLeft(); i++) { if (currPlayer->GetPiece(i)->HasLineToKing(opponentPlayerKing) ) { if (!(currPlayer->GetPiece(i)->IsInKingArray())) ChessAssert(); } else { if (currPlayer->GetPiece(i)->IsInKingArray()) ChessAssert(); } }*/ }
int ChessBoard::MakeMove(const ChessMove& move) { if (move.isCastle() ) { ChessPiece* _king; ChessPiece* _rook; if (bWhiteMove) _king = GetPiece(_WhitePlayer->GetKingLocation()); else { _king = GetPiece(_BlackPlayer->GetKingLocation()); } int col; if (bWhiteMove) col = 0; else { col = 7; } if (move.isKingSideCastle() ) { _rook = GetPiece(7, col); Castle(_king, _rook, true, col); } else { _rook = GetPiece(0, col); Castle(_king, _rook, false, col); } } else if (move.isPromotion() ) { ChessPiece* _pawn = GetPiece(move.getStartingRow(), move.getStartingCol()); ChessSquare* newMove = new ChessSquare(move.getRow(), move.getCol() ); PromotePawn(dynamic_cast<Pawn*>(_pawn), newMove , move.GetPromotionChar() ); //ChessBoard::GetInstance()->PrintBoard(); delete newMove; } else if (move.IsEnPassant()) { EnPassantCapture(move.getPiece(), ChessSquare(move.getRow(), move.getCol()), move.getCapturedPiece()->GetLocation()); // to code this later } else if (move.isCapture()) { MakeCapture(move.getPiece(), ChessSquare(move.getRow(), move.getCol())); } else MovePiece(move.getPiece(), move.getRow(), move.getCol()); if (move.isPromotion()) { ResolveLineOfSight(Board[move.getRow()][move.getCol()]); } else if (!move.isCastle()) { ResolveLineOfSight(move.getPiece()); } else { ResolveCastleLineOfSight(!bWhiteMove); } //move->Delete(); //delete(move); return 0; }