public void Move(Board board, string position) { var move = new ChessDotNet.Move(board.SelectedCell.Position, position, board.Side, 'Q'); foreach (var item in board.Cells) { item.ValidCell = "Hidden"; } if (board.ChessLogic.IsValidMove(move)) { var moveType = board.ChessLogic.MakeMove(move, true); board.UpdateSourceIfPromotion(moveType, position, board.Side); board.SelectedCell.Source = null; board.State = new PieceDroped(); board.UpdateSourceIfEnPassant(moveType, position, board.Side); board.UpdateSourceIfCastling(moveType, position); TcpChessClient.getInstance().Move(move.OriginalPosition.ToString(), move.NewPosition.ToString()); } else { board.State = new PieceDroped(); board.State.Move(board, position); } }
public OperationResult Move(GameSession game, Player player, string originalPosition, string newPosition) { var move = new ChessDotNet.Move(originalPosition, newPosition, ChessDotNet.Player.Black, 'Q'); if (game.Description.BlackPlayer == player && game.ChessLogicCore.IsValidMove(move)) { try { game.Description.WhitePlayer.Callback.OnMoved(originalPosition, newPosition); } catch (Exception) { } game.Turn = new WhiteTurn(game); game.ChessLogicCore.MakeMove(move, true); if (game.ChessLogicCore.IsWinner(ChessDotNet.Player.Black)) { game.SetBlackWin(); NotifyPlayersAboutEndGame(game.Description); } if (game.ChessLogicCore.IsDraw()) { game.SetDraw(); NotifyPlayersAboutEndGame(game.Description); } return(new OperationResult(true, "")); } return(new OperationResult(false, "")); }
public void EnemyMoved(string originalPosition, string newPosition) { ChessDotNet.Player enemySide = Side == ChessDotNet.Player.White ? ChessDotNet.Player.Black : ChessDotNet.Player.White; SelectedCell = Cells.Single(item => item.Position == originalPosition); var move = new ChessDotNet.Move(originalPosition, newPosition, enemySide, 'Q'); var moveType = ChessLogic.MakeMove(move, true); UpdateSourceIfPromotion(moveType, newPosition, enemySide); SelectedCell.Source = null; UpdateSourceIfEnPassant(moveType, newPosition, enemySide); UpdateSourceIfCastling(moveType, newPosition); }