public TryMoveReturnObj TryMove(Move move, ChessForm form1) { //ChessForm.MessageShow(move.ToString()); if (!IsLegalMove(move)) { return(new TryMoveReturnObj() { IsSuccesful = false }); } TryMoveReturnObj output = new TryMoveReturnObj(); output.IsSuccesful = true; this.Move(move); this.promoteIfNeeded(); if (currentBoard.isMate()) { output.IsGameOver = true; output.IsMate = true; if (this.currentBoard.IsWhiteTurn) { output.IsMateForBlack = true; } else { output.IsMateForWhite = true; } } if (this.isDraw()) { output.IsGameOver = true; output.IsDraw = true; output.IsStaleMate = this.currentBoard.IsStaleMate(); output.Is3FoldRepetition = this.is3FoldRepetition(); output.Is50MoveRule = this.is50MoveRule(); output.IsInsufficientMaterialForWhite = this.currentBoard.isInsufficientMaterialForWhite(); output.IsInsufficientMaterialForBlack = this.currentBoard.isInsufficientMaterialForBlack(); } return(output); }
//once a move is tried: private void Square_DragDrop(object sender, DragEventArgs e) { PictureBox target = (PictureBox)sender; if (e.Data.GetDataPresent(typeof(PictureBox))) { PictureBox source = (PictureBox)e.Data.GetData(typeof(PictureBox)); if (source != target) { try { TryMoveReturnObj output = this.game.TryMove(new Move() { SourceCollumn = this.getSquarePoint(source).X, SourceRow = this.getSquarePoint(source).Y, TargetCollumn = this.getSquarePoint(target).X, TargetRow = this.getSquarePoint(target).Y } , this ); if (output.IsSuccesful) { //if succesful this.UpdateScreenBoard(); if (this.game.currentBoard.IsWhiteTurn) { this.blackTime += timeControlIncrement; } else { this.whiteTime += timeControlIncrement; } this.textBoxIsWhiteTurn.Visible = this.game.currentBoard.IsWhiteTurn; this.textBoxIsBlackTurn.Visible = !this.game.currentBoard.IsWhiteTurn; this.buttonAgreeToDraw.Enabled = true; this.buttonResignBlack.Enabled = true; this.buttonResignWhite.Enabled = true; } else { MessageBox.Show("not succesful"); } if (output.IsGameOver) { this.EndTheGame(); if (output.IsDraw) { if (output.IsStaleMate) { MessageBox.Show("draw by stalemate!"); } if (output.Is3FoldRepetition) { MessageBox.Show("draw 3 fold repetition!"); } if (output.Is50MoveRule) { MessageBox.Show("draw by 50 move rule!"); } if (output.IsInsufficientMaterialForWhite && output.IsInsufficientMaterialForBlack) { MessageBox.Show("draw by insufficient material!"); } } else if (output.IsMate) { if (output.IsMateForWhite) { MessageBox.Show("white won by check mate!"); } else { MessageBox.Show("black won by check mate!"); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }