void AddMove(Pieces from, GridIndex to) { var seq = from.QueryMovable(MoveType.StandardMove); seq.Build(board, MoveType.StandardMove); if (seq.ContainsMove(to)) { var fromIndex = from.CellIndex; var action = from.MoveTo(to); undoStack.Push(ActionCommand.SimpleMove(action)); redoStack.Clear(); GenericAction(); board.Turnover(); } else if (from is King king) { AddCastling(king, to); } else if (from is Pawn pawn) { AddEnpassant(pawn, to); } }
void BuildCriticalMove(ChessBoard board) { var tempBuild = new BuildedData(); for (int i = 0; i < SequenceCount; ++i) { var single = this[i]; for (int j = 0; j < single.Count; ++j) { var action = owner.MoveTo(single[j]); tempBuild.Rebuild(board); if (tempBuild.IsChecked(owner.Team)) { single.RemoveAt(j); j -= 1; } action.Undo(); } } }
void AddAttack(Pieces from, Pieces to) { if (from.Team == to.Team) { if (from == to) { selection = null; } else { selection = to.CellIndex; } } else { var seq = from.QueryMovable(MoveType.Attack); seq.Build(board, MoveType.Attack); if (seq.ContainsMove(to.CellIndex)) { var fromIndex = from.CellIndex; var action = from.MoveTo(to.CellIndex); undoStack.Push(ActionCommand.SimpleMove(action)); redoStack.Clear(); GenericAction(); board.Turnover(); } } }
public override void Undo() { actor.MoveTo(from); actor.board[to] = killActor; killActor?.gameObject.SetActive(true); }