Beispiel #1
0
    // public void follow_until(Func<Vector2, Vector2?, T> F, Vector2 k) {
    //     if(this.M.ContainsKey(v.x) && this.M[v.x].ContainsKey(v.y)) {
    //         Vector2 maybe_vec2 = F(this.M[v.x][v.y]);
    //         if(maybe_T != null) {
    //             this.follow_until(F, maybe_vec2);
    //         }
    //     }
    // }
    public Point2DCollection <T> intersect_to_new(Point2DCollection <T> incoming)
    {
        Point2DCollection <T> ret = new Point2DCollection <T>();

        foreach (KeyValuePair <float, Dictionary <float, T> > x_y_T in this.M)
        {
            foreach (KeyValuePair <float, T> y_T in x_y_T.Value)
            {
                Vector2 pt = new Vector2(x_y_T.Key, y_T.Key);
                if (incoming.has(pt))
                {
                    ret.put(pt, incoming.get(pt));
                }
            }
        }
        return(ret);
    }
Beispiel #2
0
    void Start()
    {
        Point2DCollection <Boolean> candidates = new Point2DCollection <Boolean>();
        int readjusted_x = Mathf.RoundToInt(Constants.EXTENT.x / Constants.BALL_DIAMETER), readjusted_y = Mathf.RoundToInt(Constants.EXTENT.y / Constants.BALL_DIAMETER);

        for (int i = 0; i < readjusted_x; i++)
        {
            for (int j = 0; j < readjusted_y; j++)
            {
                candidates.put(new Vector2(i, j), true);
            }
        }
        points_per_level.Add(candidates);
        SemiSigmoid weighter = new SemiSigmoid();
        int         level = 0;
        Vector2     up = new Vector2(0, 1), across = new Vector2(1, 1), right = new Vector2(1, 0);
        float       y_sep = Mathf.Pow(2.0f, -0.5f);

        while (candidates.count > 0)
        {
            float thresh = weighter.eval(UnityEngine.Random.value);
            // stability conditions
            candidates = candidates.filter_to_new_by_point((Vector2 v) => (System.Convert.ToInt32(candidates.has(v + up)) + System.Convert.ToInt32(candidates.has(v + across)) + System.Convert.ToInt32(candidates.has(v + right)) >= 2) && UnityEngine.Random.value < thresh && v.x < readjusted_x && v.y < readjusted_y);
            Debug.Log(candidates);
            Debug.Log(candidates.count);
            points_per_level.Add(candidates);
        }
        for (int i = 0; i < points_per_level.Count; i++)
        {
            points_per_level[i].pointed_iterate((Vector2 vec, Boolean v) =>
                                                Instantiate(this.ball, (new Vector3(vec.x + 0.5f * i, vec.y + 0.5f * i, Constants.BALL_Z_OFFSET - i * y_sep)) * Constants.BALL_DIAMETER, Quaternion.identity));
        }
    }