public void OrderCorners()
        {
            Corner        CurrentCorner = Corners.First();
            List <Corner> Ordered       = new List <Corner>();
            Corner        newdot;
            Edge          ed;

            Ordered.Add(CurrentCorner);
            do
            {
                ed = CurrentCorner.Protrudes.FirstOrDefault(x => Borders.Contains(x) && !(Ordered.Contains(x.VoronoiStart) && (Ordered.Contains(x.VoronoiEnd))));

                if (ed != null)
                {
                    newdot = ed.Corners.FirstOrDefault(x => !Ordered.Contains(x));
                    Ordered.Add(newdot);
                    CurrentCorner = newdot;
                }
            } while (ed != null);

            Corners.Clear();

            foreach (var corner in Ordered)
            {
                Corners.Add(corner);
            }
        }
示例#2
0
文件: Center.cs 项目: Gevil/Projects
 public void AddBorder(Edge edge)
 {
     if (!Borders.Contains(edge))
     {
         Borders.Add(edge);
     }
 }
示例#3
0
        public override IMove GetNextMove(IBoard board)
        {
            var moves    = board.GetPlausibleMoves(this);
            var moveList = moves as List <IMove> ?? moves.ToList();

            Thread.Sleep(500);
            if (moves == null || !moveList.Any())
            {
                return(new Move(true));
            }

            var corners = new List <MyTuple <int, int> > ();

            for (int i = 0; i < 4; i++)
            {
                corners.Add(Corners[i, 0]);
            }

            var cornersMoves = (from k in moveList where corners.Contains(k.MovePosition) select k).ToList();

            if (cornersMoves.Count > 0)
            {
                var crnIndex = (new Random()).Next(moveList.Count());
                return(cornersMoves[crnIndex]);
            }

            var bordersMoves = (from k in moveList where Borders.Contains(k.MovePosition) select k).ToList();

            if (bordersMoves.Count > 0)
            {
                var crnIndex = (new Random()).Next(bordersMoves.Count());
                return(bordersMoves[crnIndex]);
            }

            var rndIndex = (new Random()).Next(moveList.Count());

            return(moveList[rndIndex]);
        }