Exemple #1
0
    public override List <Vector2> ComputeOptions(GameState gs, bool player1Move)
    {
        List <Vector2> options = new List <Vector2>();

        // too less
        if (gs.GetPoints().Count < 2)
        {
            return(alternative.ComputeOptions(gs, player1Move));
        }

        List <Vector2> cHull = CustomConvexHull.QuickHull(gs.GetPoints());

        Vector2 prev = cHull[cHull.Count - 2]; // Never out of range because the hull contains at least 2 points
        Vector2 cur  = cHull.Last();

        foreach (Vector2 next in cHull)
        {
            Vector2 d1   = (prev - cur).normalized;
            Vector2 d2   = (next - cur).normalized;
            Vector2 dout = (d1 + d2).normalized;
            options.Add(cur - distance * dout);
            prev = cur;
            cur  = next;
        }

        return(options);
    }
Exemple #2
0
    public void DebugDraw(float y, bool borders, bool delauney, bool delauneyDebug, bool voronoi, bool voronoiDebug, bool facesDebug, bool hull)
    {
        if (borders)
        {
            Debug.DrawLine(new Vector3(BottomLeft.x, y, BottomLeft.y), new Vector3(BottomLeft.x, y, TopRight.y), Color.white, 0);
            Debug.DrawLine(new Vector3(BottomLeft.x, y, TopRight.y), new Vector3(TopRight.x, y, TopRight.y), Color.white, 0);
            Debug.DrawLine(new Vector3(TopRight.x, y, TopRight.y), new Vector3(TopRight.x, y, BottomLeft.y), Color.white, 0);
            Debug.DrawLine(new Vector3(TopRight.x, y, BottomLeft.y), new Vector3(BottomLeft.x, y, BottomLeft.y), Color.white, 0);
        }


        if (delauney)
        {
            Delauney.DebugDraw(y);
        }

        if (delauneyDebug)
        {
            foreach (Triangle t in newTriangles)
            {
                Debug.DrawLine(new Vector3(t.p0.X, y, t.p0.Y), new Vector3(t.p1.X, y, t.p1.Y), Color.red, 0);
                Debug.DrawLine(new Vector3(t.p1.X, y, t.p1.Y), new Vector3(t.p2.X, y, t.p2.Y), Color.red, 0);
                Debug.DrawLine(new Vector3(t.p2.X, y, t.p2.Y), new Vector3(t.p0.X, y, t.p0.Y), Color.red, 0);
            }

            foreach (Edge e in polygon)
            {
                Debug.DrawLine(new Vector3(e.start.X, y, e.start.Y), new Vector3(e.end.X, y, e.end.Y), Color.green, 0);
            }
        }

        if (voronoi)
        {
            Voronoi.DebugDraw(y);
        }

        if (voronoiDebug)
        {
            foreach (Edge e in newVoronoiEdges)
            {
                Debug.DrawLine(new Vector3(e.start.X, y, e.start.Y), new Vector3(e.end.X, y, e.end.Y), Color.cyan, 0);
            }
        }

        //// Draw Lines to Voronoi Points;
        //foreach(Edge e in Voronoi.Edges.Keys) {
        //    var middle = new Vector3((e.start.X + e.end.X) / 2, y, (e.start.Y + e.end.Y) / 2);
        //    var left = new Vector3(e.left.Point.X, y, e.left.Point.Y);
        //    var right = new Vector3(e.right.Point.X, y, e.right.Point.Y);
        //    Debug.DrawLine(middle, left, Color.green, 0);
        //    Debug.DrawLine(middle, right, Color.red, 0);
        //}

        //// Draw Lines to Circumcircle centers
        // foreach(Triangle t in Delauney.triangles) {
        //     if(t.Boundary) continue;
        //     Debug.DrawLine(new Vector3(t.p0.X, y, t.p0.Y), new Vector3(t.Circumcenter.x, y, t.Circumcenter.y), Color.magenta, 0);
        //     Debug.DrawLine(new Vector3(t.p1.X, y, t.p1.Y), new Vector3(t.Circumcenter.x, y, t.Circumcenter.y), Color.magenta, 0);
        //     Debug.DrawLine(new Vector3(t.p2.X, y, t.p2.Y), new Vector3(t.Circumcenter.x, y, t.Circumcenter.y), Color.magenta, 0);
        // }

        ////Draw incomplete Voronoi cells
        //foreach(Face f in Voronoi.Faces.Values) {
        //    if(f.IsComplete) continue;
        //    if(f.Start == f.End) continue;

        //    var middle = new Vector3(f.Point.X, y, f.Point.Y);
        //    var start = f.GetAdjustedStart(f.Start);
        //    var end = f.GetAdjustedEnd(f.End);

        //    Debug.DrawLine(middle, new Vector3(start.X, y, start.Y), Color.magenta, 0);
        //    Debug.DrawLine(middle, new Vector3(end.X, y, end.Y), Color.magenta, 0);
        //}

        if (facesDebug)
        {
            foreach (Face f in Voronoi.Faces.Values)
            {
                if (f.CutPolygon == null)
                {
                    continue;
                }
                if (f.CutPolygon.Count < 2)
                {
                    continue;
                }

                var prev = f.CutPolygon.Values.Last();
                foreach (Vertex v in f.CutPolygon.Keys)
                {
                    Debug.DrawLine(new Vector3(prev.X, y, prev.Y), new Vector3(v.X, y, v.Y), Color.magenta, 0);
                    prev = v;
                    Debug.DrawLine(new Vector3(f.Point.X, y, f.Point.Y), new Vector3(v.X, y, v.Y), Color.green, 0);
                }
            }

            ////Show if face contains corners
            //foreach(Face f in Voronoi.Faces.Values) {
            //    if (f.ContainsPoint(TopRight)) {
            //        Debug.DrawLine(new Vector3(f.Point.X, y, f.Point.Y), new Vector3(TopRight.x, y, TopRight.y), Color.red, 0);
            //    }
            //    if(f.ContainsPoint(BottomLeft)) {
            //        Debug.DrawLine(new Vector3(f.Point.X, y, f.Point.Y), new Vector3(BottomLeft.x, y, BottomLeft.y), Color.red, 0);
            //    }
            //}
        }

        if (hull)
        {
            List <Vector2> cHull = CustomConvexHull.QuickHull(Points);
            if (cHull.Count > 0)
            {
                Vector2 prev = cHull.Last();
                foreach (Vector2 cur in cHull)
                {
                    Debug.DrawLine(new Vector3(prev.x, y, prev.y), new Vector3(cur.x, y, cur.y), Color.yellow, 0);
                    prev = cur;
                }
            }
        }
    }