public void UpdateGameForOpponent(GameInfoWithMoves gameInfo) { ChessMove move = AlgebraicNotation.ToChessMove(gameInfo.moves[gameInfo.moves.Count - 1], moveManager, GetOpponentColor()); moveManager.DoMove(move, false, false); UpdatePlayerInfo(gameInfo); }
public void AddMove(string algebraicMove, PieceColor player) { ChessMove move = AlgebraicNotation.ToChessMove(algebraicMove, moveManager, player); moveManager.DoMove(move, false, false); }
public ChessMove DoMove(ChessMove move, bool simulate = false, bool newMove = true) { string algebraicMove = ""; if (!simulate && !CanPieceMove(move.activePiece.GetColor(), newMove)) { return(move); } if (!simulate) { move.checksOpponent = IsOpponentKingInCheckSimulate(move.activePiece.GetColor(), move); } bool moveCanBeMade = true; if (move.isPromotionMove) { if (!move.isCompletePromotionMove) { if (!simulate) { waitingForPawnPromotion = true; incompletePromotionMove = move; moveCanBeMade = false; if (onPawnPromotionStarted != null) { onPawnPromotionStarted(move.activePiece.GetColor()); } } } else { move.promotedPiece = gameManager.CreateNewPiece(move.promotionType, move.activePiece.GetColor(), move.toTile.row, move.toTile.col); move.activePiece.DisablePiece(); move.promotedPiece.SetTile(move.toTile, !simulate); } } if (moveCanBeMade) { if (!simulate) { moveHistory.Add(move); allMoveHistory.Add(move); algebraicMove = AlgebraicNotation.ToAlgebraic(move, this); if (beforeMovePlayed != null) { beforeMovePlayed(move, algebraicMove, newMove); } } if (!move.isPromotionMove) { move.activePiece.SetTile(move.toTile, !simulate); } if (move.isCastleMove) { move.castlePair.SetTile(move.castlePairTo, !simulate); } else if (move.passivePiece != null) { move.passivePiece.Capture(!simulate); } if (!simulate) { afterMovePlayed?.Invoke(move, algebraicMove, newMove); } ChangeThreatenedSpaces(); } return(move); }