public Result <T> Move(HistoryMove info) { if (list.Count < 1) { return(new Result <T>(new IndexOutOfRangeException("История пуста."))); } switch (info) { case HistoryMove.UP: indexCurrent -= indexCurrent > 0 ? 1 : 0; break; case HistoryMove.DOWN: indexCurrent += indexCurrent < list.Count ? 1 : 0; break; } if (indexCurrent < list.Count) { return(new Result <T>(list[indexCurrent])); } else { return(new Result <T>(default(T))); } }
public bool Check(BoardCoordinator board) { if (player != 0) { HistoryMove lastMove = board.GetLastMoveFromPlayer(player); if (lastMove == null) { return(false); } bool result = true; if (from.Length == lastMove.from.Length && to.Length == lastMove.to.Length) { for (int i = 0; i < from.Length && result; i++) { if (from[i] != lastMove.from[i]) { result = false; } if (to[i] != lastMove.to[i]) { result = false; } } return(result); } else { return(false); } } else { List <HistoryMove> lastMoves = board.GetLastMoves(); foreach (HistoryMove lastMove in lastMoves) { if (lastMove == null) { continue; } bool result = true; if (from.Length == lastMove.from.Length && to.Length == lastMove.to.Length) { for (int i = 0; i < from.Length && result; i++) { if (from[i] != lastMove.from[i]) { result = false; } if (to[i] != lastMove.to[i]) { result = false; } } } if (result) { return(true); } } return(false); } }