private void setHistory(ChessBoard.gameState state) // set history variables with values if turn was valid for the undo or redo feature { History currentHistory = new History(turn, sourceY, sourceX, destinationY, destinationX, source, destination, state); History.Next = currentHistory; currentHistory.Prev = History; }
public History(bool turn, int sourceY, int sourceX, int destinationY, int destinationX, PictureBox source, PictureBox destination, ChessBoard.gameState state) { Turn = turn; SourceY = sourceY; SourceX = sourceX; DestinationY = destinationY; DestinationX = destinationX; Source = source; Destination = destination; State = state; }
protected bool GameState(PictureBox[][] board) // determine the game state whether its check, checkmate, stalemate or normal { Check check = new Check(); board[sourceY][sourceX] = null; board[destinationY][destinationX] = source; int[] kingCoord = PieceDetails.FindKing(board, turn); if (check.IsChecked(board, kingCoord[0], kingCoord[1], !turn)) // determine if this is an illegal move by check { board[sourceY][sourceX] = source; board[destinationY][destinationX] = destination; return(false); } else { CurrentStatus status = new CurrentStatus(); ChessBoard.gameState state = status.TurnResult(board, turn); if (state == ChessBoard.gameState.Check) { setHistory(ChessBoard.gameState.Check); } else if (state == ChessBoard.gameState.Checkmate) { setHistory(ChessBoard.gameState.Checkmate); } else if (state == ChessBoard.gameState.Stalemate) { setHistory(ChessBoard.gameState.Stalemate); } else { setHistory(ChessBoard.gameState.Normal); } } return(true); }