public void PieceMoveEvent(BasePiece piece, Cell currentCell, Cell targetCell) { var toX = (byte)targetCell.boardPosition.x; var toY = (byte)(7 - targetCell.boardPosition.y); var fromX = (byte)currentCell.boardPosition.x; var fromY = (byte)(7 - currentCell.boardPosition.y); if (engine.MovePiece( fromX, fromY, toX, toY)) { var move = new EngineMove { MoveContent = engine.GetMoveHistory().ToArray()[0], Message = "Ход Игрока\n" }; queuedMoves.Enqueue(move); } else { SoundEvents.PlayRejectSound(); StaticEvents.LogMsgEvent("Недопустимый ход!", LogType.Warning); piece.Place(board.AllCells[currentCell.boardPosition.x, currentCell.boardPosition.y]); } }
private void ProceedMove(MoveContent lastMove, string message) { if (lastMove.TakenPiece.PieceType.ToString() != "None") { var takenSrcCell = Extensions.FromPosition(lastMove.TakenPiece.Position); var takenPiece = board.AllCells[takenSrcCell.x, takenSrcCell.y].currentPiece; if (takenPiece != null) { message += Extensions.PieceToStr(takenPiece) + " взятие "; takenPiece.Kill(); } } if (lastMove.MovingPiecePrimary.PieceType.ToString() != "None") { var primarySrcCell = Extensions.FromPosition(lastMove.MovingPiecePrimary.SrcPosition); var primaryDstCell = Extensions.FromPosition(lastMove.MovingPiecePrimary.DstPosition); var piecePrimary = board.AllCells[primarySrcCell.x, primarySrcCell.y].currentPiece; if (piecePrimary != null) { if (lastMove.PawnPromotedTo == ChessPieceType.Queen) { message += " Pawn повышение Queen "; PromotePiece(piecePrimary as Pawn, board.AllCells[primaryDstCell.x, primaryDstCell.y], piecePrimary.mainColor, piecePrimary.mainColor == Color.black ? Colors.BlackPieces : Colors.WhitePieces); } else { piecePrimary.MovePieceToCell(board.AllCells[primaryDstCell.x, primaryDstCell.y]); SoundEvents.PlayMoveSound(); message += Extensions.PieceToStr(piecePrimary); } } else { Debug.Log("Piece not found and not created!"); } } if (lastMove.MovingPieceSecondary.PieceType.ToString() != "None") { var secondarySrcCell = Extensions.FromPosition(lastMove.MovingPieceSecondary.SrcPosition); var secondaryDstCell = Extensions.FromPosition(lastMove.MovingPieceSecondary.DstPosition); var pieceSecondary = board.AllCells[secondarySrcCell.x, secondarySrcCell.y].currentPiece; if (pieceSecondary != null) { message += " рокировка "; pieceSecondary.Place(board.AllCells[secondaryDstCell.x, secondaryDstCell.y]); SoundEvents.PlayMoveSound(); message += Extensions.PieceToStr(pieceSecondary); } else { var msg = "pieceSecondary not found!"; msg += " Src X " + secondarySrcCell.x + " Y " + secondarySrcCell.y; msg += " Dst X " + secondaryDstCell.x + " Y " + secondaryDstCell.y; Debug.LogError(msg); //StaticEvents.LogMsgEvent(msg, LogType.Exception); } } if (lastMove.EnPassantOccured) { message += " взятие на проходе "; } message += "\n" + lastMove.ToString(); StaticEvents.LogMsgEvent(message, LogType.Log); CheckMove(engine); SwitchSides(); }
private static void CheckMove(Engine engine) { string msg; if (engine.GetWhiteCheck()) { msg = "Шах белым"; Debug.Log(msg); StaticEvents.LogMsgEvent(msg, LogType.Warning); SoundEvents.PlayCheckSound(); } if (engine.GetBlackCheck()) { msg = "Шах черным"; Debug.Log(msg); StaticEvents.LogMsgEvent(msg, LogType.Warning); SoundEvents.PlayCheckSound(); } if (!engine.IsGameOver()) { return; } var result = ""; var resultPgn = PGN.Result.Ongoing; var state = EndGamesStates.None; if (engine.StaleMate) { resultPgn = PGN.Result.Tie; if (engine.InsufficientMaterial) { state = EndGamesStates.StaleMateByInsufficientMaterial; result = "Ничья, недостаточно материала для мата"; } else if (engine.RepeatedMove) { state = EndGamesStates.StaleMateByRepeatedMove; result = "Ничья после троекратного повторения"; } else if (engine.FiftyMove) { state = EndGamesStates.StaleMateByFiftyMove; result = "Ничья по правилу 50 ходов"; } else { state = EndGamesStates.StaleMate; result = "Пат"; } Debug.Log(result); StaticEvents.LogMsgEvent(result, LogType.Warning); SoundEvents.PlayCheckSound(); } if (engine.GetWhiteMate()) { resultPgn = PGN.Result.Black; result = "Шах и мат белым"; Debug.Log(result); StaticEvents.LogMsgEvent(result, LogType.Warning); SoundEvents.PlayCheckSound(); state = EndGamesStates.WhiteMate; } if (engine.GetBlackMate()) { resultPgn = PGN.Result.White; result = "Шах и мат черным"; Debug.Log(result); StaticEvents.LogMsgEvent(result, LogType.Warning); SoundEvents.PlayCheckSound(); state = EndGamesStates.BlackMate; } GameStatData.PGN = GeneratePNG(engine, resultPgn); SoundEvents.PlayVictorySound(); msg = "Конец игры"; StaticEvents.LogMsgEvent(msg, LogType.Exception); SoundEvents.PlayCheckSound(); EndGameEvents.EndGameEvent(state, result, engine.GetScore()); }