Beispiel #1
0
        public BoardMove Clone()
        {
            var clone = new BoardMove();

            clone.AddRange(this);
            return(clone);
        }
Beispiel #2
0
        public override bool Equals(object obj)
        {
            BoardMove other = obj as BoardMove;

            if (other == null)
            {
                return(false);
            }
            return(Equals(other));
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
 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);
 }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 public bool Equals(BoardMove other)
 {
     Sort();
     other.Sort();
     return(this.SequenceEqual(other));
 }