protected override void OnBoardChange(Board NewBoard) { if (this._Game.Player == NewBoard.PlayerToMove) { this._Moves = new List<KeyValuePair<Move, Board>>(NewBoard.Moves); } else { this._Moves = new List<KeyValuePair<Move, Board>>(); } this._Selection = null; if (this._ScoreSample != null) { this._ScoreSample.Dispose(); this._ScoreSample = null; } }
protected override void OnSquareClick(Square Square, bool Primary) { if (Primary) { // Selection Piece piece = this.Board.GetPiece(Square); if (piece != null) { _SelectionInfo si = new _SelectionInfo(); si.Selected = Square; var acts = si.Actions = new Dictionary<Square, _SelectionInfo.SelectAction>(); foreach (KeyValuePair<Move, Board> m in this._Moves) { PieceMove pm = m.Key as PieceMove; if (pm != null && pm.Source == Square) { int type = 0; if (this.Board.GetPiece(pm.Destination) != null || pm is EnPassantMove) { type = 1; } // Check if there is already a move to this spot. _SelectionInfo.SelectAction sa; if (acts.TryGetValue(pm.Destination, out sa)) { _SelectionInfo.MultiSelectAction mtsa = sa as _SelectionInfo.MultiSelectAction; if (mtsa == null) { _SelectionInfo.MoveSelectAction msa = sa as _SelectionInfo.MoveSelectAction; acts[pm.Destination] = mtsa = new _SelectionInfo.MultiSelectAction(); mtsa.Add(msa.Move as PieceMove, msa.Board); mtsa.Type = 2; } mtsa.Add(pm, m.Value); } else { acts.Add(pm.Destination, new _SelectionInfo.MoveSelectAction() { Type = type, Move = pm, Board = m.Value }); } } CastleMove cm = m.Key as CastleMove; if (cm != null && cm.KingSource == Square) { acts.Add(cm.KingDestination, new _SelectionInfo.MoveSelectAction() { Type = 2, Move = cm, Board = m.Value }); } } this._Selection = si; } } else { // Move if (this._Selection != null) { _SelectionInfo.SelectAction sa; if (this._Selection.Actions.TryGetValue(Square, out sa)) { var msa = sa as _SelectionInfo.MoveSelectAction; if (msa != null) { this.MakeMove(msa.Move, msa.Board); } var mtsa = sa as _SelectionInfo.MultiSelectAction; if (mtsa != null) { this._UpdateAction = mtsa.Display(this); } } } } }