public BoardMove Clone() { var clone = new BoardMove(); clone.AddRange(this); return(clone); }
public override bool Equals(object obj) { BoardMove other = obj as BoardMove; if (other == null) { return(false); } return(Equals(other)); }
public void ApplyMoves(BoardMove boardMove, bool validate = false) { if (validate) { foreach (UnitMove move in boardMove) { if (move.IsDisband || move.IsHold) { continue; } if (move.IsBuild) { if (OccupiedMapNodes.ContainsKey(move.Edge.Target)) { throw new Exception($"Cannot build {move.Unit} at {move.Edge.Target} because a unit is already there"); } if (move.Edge.Target.Territory.HomeSupplyPower != move.Unit.Power) { throw new Exception($"Cannot build {move.Unit} at {move.Edge.Target} because it is not a home supply for {move.Unit.Power}"); } } else { if (OccupiedMapNodes[move.Edge.Source] != move.Unit) { throw new Exception($"{move.Unit} is not in {move.Edge.Source}"); } if (move.ConvoyRoute == null && !move.Unit.MyMap.AdjacentOutEdges(move.Edge.Source).Contains(move.Edge)) { throw new Exception($"{move.Edge} is not a valid edge for {move.Unit}"); } // todo add convoy check here } } } OccupiedMapNodes.Clear(); OccupiedTerritories.Clear(); foreach (UnitMove move in boardMove) { if (move.IsDisband) { continue; } if (validate && IsOccupied(move.Edge.Target.Territory)) { throw new Exception($"Territory {move.Edge.Target} has already been moved into during this BoardMove"); } OccupiedMapNodes.Add(move.Edge.Target, move.Unit); OccupiedTerritories.Add(move.Edge.Target.Territory, move.Unit); } }
public static bool TryCombineFallSpring(BoardMove first, BoardMove second, out BoardMove result) { foreach (UnitMove move in first) { if (!second.CurrentlyAllowsFallSpring(move)) { result = null; return(false); } } result = new BoardMove(); result.AddRange(first); result.AddRange(second); return(true); }
private static List <BoardMove> CombineFallSpringMoveListsRecursive(BoardMove boardMove, IEnumerable <BoardMove> boardList) { var result = new List <BoardMove>(); bool empty = true; foreach (BoardMove move in boardList) { empty = false; BoardMove combinedBoardMove; if (TryCombineFallSpring(boardMove, move, out combinedBoardMove)) { result.Add(combinedBoardMove); } } if (!empty) { result.AddRange(CombineFallSpringMoveListsRecursive(boardList.First(), boardList.Skip(1))); } return(result); }
public bool Equals(BoardMove other) { Sort(); other.Sort(); return(this.SequenceEqual(other)); }