Exemple #1
0
    // Analysis of chip for combination
    public SessionAssistant.Solution MatchAnaliz()
    {
        if (!GetChip()) return null;
        if (!GetChip().IsMatcheble()) return null;

        //    T
        //    T
        //    T
        // LLLXRRR	X - current chip
        //    B
        //    B
        //    B

        int t = 0; // number of chips with same color on top
        int r = 0; // number of chips with same color on right
        int b = 0; // number of chips with same color on bottom
        int l = 0; // number of chips with same color on left

        int potencialV = 0; // vertical solution potential
        int potencialH = 0; // horizontal solution potential

        // coordinats of current chip/slot
        int x = slot.x;
        int y = slot.y;

        // playing field size
        int width = FieldAssistant.main.field.width;
        int height = FieldAssistant.main.field.height;

        Slot s;
        GameObject o;

        // searching right chips
        for (x = slot.x + 1; x < width; x++) {
            o = GameObject.Find("Slot_" + x + "x" + slot.y);
            if (!o) break;
            s = o.GetComponent<Slot>();
            if (!s) break;
            if (!s.GetChip()) break;
            if (s.GetChip().id != chip.id) break;
            if (!s.GetChip().IsMatcheble()) break;
            potencialH += s.GetChip().GetPotencial();
            r++;
        }

        // searching left chips
        for (x = slot.x - 1; x >= 0; x--) {
            o = GameObject.Find("Slot_" + x + "x" + slot.y);
            if (!o) break;
            s = o.GetComponent<Slot>();
            if (!s) break;
            if (!s.GetChip()) break;
            if (s.GetChip().id != chip.id) break;
            if (!s.GetChip().IsMatcheble()) break;
            potencialH += s.GetChip().GetPotencial();
            l++;
        }

        // searching top chips
        for (y = slot.y + 1; y < height; y++) {
            o = GameObject.Find("Slot_" + slot.x + "x" + y);
            if (!o) break;
            s = o.GetComponent<Slot>();
            if (!s) break;
            if (!s.GetChip()) break;
            if (s.GetChip().id != chip.id) break;
            if (!s.GetChip().IsMatcheble()) break;
            potencialV += s.GetChip().GetPotencial();
            t++;
        }

        // searching bottom chips
        for (y = slot.y - 1; y >= 0; y--) {
            o = GameObject.Find("Slot_" + slot.x + "x" + y);
            if (!o) break;
            s = o.GetComponent<Slot>();
            if (!s) break;
            if (!s.GetChip()) break;
            if (s.GetChip().id != chip.id) break;
            if (!s.GetChip().IsMatcheble()) break;
            potencialV += s.GetChip().GetPotencial();
            b++;
        }

        // Formation of solution if it is there
        if (r + l >= 2 || t + b >= 2) {
            SessionAssistant.Solution solution = new SessionAssistant.Solution();
            solution.h = r + l >= 2;
            solution.v = t + b >= 2;
            solution.x = slot.x;
            solution.y = slot.y;
            solution.count = 1;
            solution.count += solution.v ? t + b : 0;
            solution.count += solution.h ? r + l : 0;
            solution.id = chip.id;
            solution.posH = r;
            solution.negH = l;
            solution.posV = t;
            solution.negV = b;
            if (solution.v) solution.potencial += potencialV;
            if (solution.h) solution.potencial += potencialH;
            solution.potencial += chip.GetPotencial();
            return solution;
        }
        return null;
    }
Exemple #2
0
    public SessionAssistant.Solution MatchAnaliz()
    {
        if (!GetChip())
        {
            return(null);
        }
        if (!GetChip().IsMatcheble())
        {
            return(null);
        }


        int t          = 0;
        int r          = 0;
        int b          = 0;
        int l          = 0;
        int potencialV = 0;
        int potencialH = 0;

        int x = slot.x;
        int y = slot.y;

        int width  = FieldAssistant.main.field.width;
        int height = FieldAssistant.main.field.height;

        Slot       s;
        GameObject o;

        for (x = slot.x + 1; x < width; x++)
        {
            o = GameObject.Find("Slot_" + x + "x" + slot.y);
            if (!o)
            {
                break;
            }
            s = o.GetComponent <Slot>();
            if (!s)
            {
                break;
            }
            if (!s.GetChip())
            {
                break;
            }
            if (s.GetChip().id != chip.id)
            {
                break;
            }
            if (!s.GetChip().IsMatcheble())
            {
                break;
            }
            potencialH += s.GetChip().GetPotencial();
            r++;
        }

        for (x = slot.x - 1; x >= 0; x--)
        {
            o = GameObject.Find("Slot_" + x + "x" + slot.y);
            if (!o)
            {
                break;
            }
            s = o.GetComponent <Slot>();
            if (!s)
            {
                break;
            }
            if (!s.GetChip())
            {
                break;
            }
            if (s.GetChip().id != chip.id)
            {
                break;
            }
            if (!s.GetChip().IsMatcheble())
            {
                break;
            }
            potencialH += s.GetChip().GetPotencial();
            l++;
        }

        for (y = slot.y + 1; y < height; y++)
        {
            o = GameObject.Find("Slot_" + slot.x + "x" + y);
            if (!o)
            {
                break;
            }
            s = o.GetComponent <Slot>();
            if (!s)
            {
                break;
            }
            if (!s.GetChip())
            {
                break;
            }
            if (s.GetChip().id != chip.id)
            {
                break;
            }
            if (!s.GetChip().IsMatcheble())
            {
                break;
            }
            potencialV += s.GetChip().GetPotencial();
            t++;
        }

        for (y = slot.y - 1; y >= 0; y--)
        {
            o = GameObject.Find("Slot_" + slot.x + "x" + y);
            if (!o)
            {
                break;
            }
            s = o.GetComponent <Slot>();
            if (!s)
            {
                break;
            }
            if (!s.GetChip())
            {
                break;
            }
            if (s.GetChip().id != chip.id)
            {
                break;
            }
            if (!s.GetChip().IsMatcheble())
            {
                break;
            }
            potencialV += s.GetChip().GetPotencial();
            b++;
        }

        if (r + l >= 2 || t + b >= 2)
        {
            SessionAssistant.Solution solution = new SessionAssistant.Solution();
            solution.h      = r + l >= 2;
            solution.v      = t + b >= 2;
            solution.x      = slot.x;
            solution.y      = slot.y;
            solution.count  = 1;
            solution.count += solution.v ? t + b : 0;
            solution.count += solution.h ? r + l : 0;
            solution.id     = chip.id;
            solution.posH   = r;
            solution.negH   = l;
            solution.posV   = t;
            solution.negV   = b;
            if (solution.v)
            {
                solution.potencial += potencialV;
            }
            if (solution.h)
            {
                solution.potencial += potencialH;
            }
            solution.potencial += chip.GetPotencial();
//			if (solution.v && !solution.h && solution.count == 5) solution.potencial += Chip.GetPotencial(3);
//			if (!solution.v && solution.h && solution.count == 5) solution.potencial += Chip.GetPotencial(3);
//			if (solution.v && solution.h && solution.count >= 5) solution.potencial += Chip.GetPotencial(2);
//			if (solution.v && !solution.h && solution.count == 4) solution.potencial += Chip.GetPotencial(1);
//			if (!solution.v && solution.h && solution.count == 4) solution.potencial += Chip.GetPotencial(1);
            return(solution);
        }
        return(null);
    }
    public SessionAssistant.Solution MatchSquareAnaliz()
    {
        if (!SessionAssistant.main.squareCombination)
            return null;
        if (!GetChip())
            return null;
        if (!GetChip().IsMatcheble())
            return null;
        if (GetChip().id < 0)
            return null;

        if (GetChip().id == 10) { // multicolor
            List<SessionAssistant.Solution> solutions = new List<SessionAssistant.Solution>();
            SessionAssistant.Solution z;
            Chip multicolorChip = GetChip();
            for (int i = 0; i < 6; i++) {
                multicolorChip.id = i;
                z = MatchSquareAnaliz();
                if (z != null)
                    solutions.Add(z);
            }
            multicolorChip.id = 10;
            z = null;
            foreach (SessionAssistant.Solution sol in solutions)
                if (z == null || z.potential < sol.potential)
                    z = sol;
            return z;
        }

        List<Chip> square = new List<Chip>();
        List<Chip> buffer = new List<Chip>();
        Side sideR;
        string key;
        Slot s;

        buffer.Clear();
        foreach (Side side in Utils.straightSides) {
            for (int r = 0; r <= 2; r++) {
                sideR = Utils.RotateSide(side, r);
                key = (slot.x + Utils.SideOffsetX(sideR)).ToString() + "_" + (slot.y + Utils.SideOffsetY(sideR)).ToString();
                if (Slot.all.ContainsKey(key)) {
                    s = Slot.all[key];
                    if (s.GetChip() && (s.GetChip().id == chip.id || s.GetChip().id == 10) && s.GetChip().IsMatcheble())
                        buffer.Add(s.GetChip());
                    else
                        break;
                } else
                    break;
            }
            if (buffer.Count == 3) {
                foreach (Chip chip_b in buffer)
                    if (!square.Contains(chip_b))
                        square.Add(chip_b);
            }
            buffer.Clear();
        }

        bool q = square.Count >= 3;

        if (q) {
            SessionAssistant.Solution solution = new SessionAssistant.Solution();

            solution.q = q;

            solution.chips = new List<Chip>();
            solution.chips.Add(GetChip());

            solution.chips.AddRange(square);

            solution.count = solution.chips.Count;

            solution.x = slot.x;
            solution.y = slot.y;
            solution.id = chip.id;

            foreach (Chip c in solution.chips)
                solution.potential += c.GetPotencial();

            return solution;
        }
        return null;
    }
    // Analysis of chip for combination
    public SessionAssistant.Solution MatchAnaliz()
    {
        if (!GetChip()) return null;
        if (!GetChip().IsMatcheble()) return null;
        if (GetChip().id < 0) return null;

        if (GetChip().id == 10) { // multicolor
            List<SessionAssistant.Solution> solutions = new List<SessionAssistant.Solution>();
            SessionAssistant.Solution z;
            Chip multicolorChip = GetChip();
            for (int i = 0; i < 6; i++) {
                multicolorChip.id = i;
                z = MatchAnaliz();
                if (z != null)
                    solutions.Add(z);
                z = MatchSquareAnaliz();
                if (z != null)
                    solutions.Add(z);
            }
            multicolorChip.id = 10;
            z = null;
            foreach (SessionAssistant.Solution sol in solutions)
                if (z == null || z.potential < sol.potential)
                    z = sol;
            return z;
        }

        Slot s;
        Dictionary<Side, List<Chip>> sides = new Dictionary<Side, List<Chip>>();
        int count;
        string key;
        foreach (Side side in Utils.straightSides) {
            count = 1;
            sides.Add(side, new List<Chip>());
            while (true) {
                key = (slot.x + Utils.SideOffsetX(side) * count).ToString() + "_" + (slot.y + Utils.SideOffsetY(side) * count).ToString();
                if (!Slot.all.ContainsKey(key))
                    break;
                s = Slot.all[key];
                if (!s.GetChip())
                    break;
                if (s.GetChip().id != chip.id && s.GetChip().id != 10)
                    break;
                if (!s.GetChip().IsMatcheble())
                    break;
                sides[side].Add(s.GetChip());
                count++;
            }
        }

        bool h = sides[Side.Right].Count + sides[Side.Left].Count >= 2;
        bool v = sides[Side.Top].Count + sides[Side.Bottom].Count >= 2;

        if (h || v) {
            SessionAssistant.Solution solution = new SessionAssistant.Solution();

            solution.h = h;
            solution.v = v;

            solution.chips = new List<Chip>();
            solution.chips.Add(GetChip());

            if (h) {
                solution.chips.AddRange(sides[Side.Right]);
                solution.chips.AddRange(sides[Side.Left]);
            }
            if (v) {
                solution.chips.AddRange(sides[Side.Top]);
                solution.chips.AddRange(sides[Side.Bottom]);
            }

            solution.count = solution.chips.Count;

            solution.x = slot.x;
            solution.y = slot.y;
            solution.id = chip.id;

            foreach (Chip c in solution.chips)
                solution.potential += c.GetPotencial();

            return solution;
        }
        return null;
    }
Exemple #5
0
    // Analysis of chip for combination
    public SessionAssistant.Solution MatchAnaliz()
    {
        if (!GetChip())
        {
            return(null);
        }
        if (!GetChip().IsMatcheble())
        {
            return(null);
        }

        //    T
        //    T
        //    T
        // LLLXRRR	X - current chip
        //    B
        //    B
        //    B

        int t = 0;          // number of chips with same color on top
        int r = 0;          // number of chips with same color on right
        int b = 0;          // number of chips with same color on bottom
        int l = 0;          // number of chips with same color on left

        int potencialV = 0; // vertical solution potential
        int potencialH = 0; // horizontal solution potential

        // coordinats of current chip/slot
        int x = slot.x;
        int y = slot.y;

        // playing field size
        int width  = FieldAssistant.main.field.width;
        int height = FieldAssistant.main.field.height;

        Slot       s;
        GameObject o;

        // searching right chips
        for (x = slot.x + 1; x < width; x++)
        {
            o = GameObject.Find("Slot_" + x + "x" + slot.y);
            if (!o)
            {
                break;
            }
            s = o.GetComponent <Slot>();
            if (!s)
            {
                break;
            }
            if (!s.GetChip())
            {
                break;
            }
            if (s.GetChip().id != chip.id)
            {
                break;
            }
            if (!s.GetChip().IsMatcheble())
            {
                break;
            }
            potencialH += s.GetChip().GetPotencial();
            r++;
        }

        // searching left chips
        for (x = slot.x - 1; x >= 0; x--)
        {
            o = GameObject.Find("Slot_" + x + "x" + slot.y);
            if (!o)
            {
                break;
            }
            s = o.GetComponent <Slot>();
            if (!s)
            {
                break;
            }
            if (!s.GetChip())
            {
                break;
            }
            if (s.GetChip().id != chip.id)
            {
                break;
            }
            if (!s.GetChip().IsMatcheble())
            {
                break;
            }
            potencialH += s.GetChip().GetPotencial();
            l++;
        }

        // searching top chips
        for (y = slot.y + 1; y < height; y++)
        {
            o = GameObject.Find("Slot_" + slot.x + "x" + y);
            if (!o)
            {
                break;
            }
            s = o.GetComponent <Slot>();
            if (!s)
            {
                break;
            }
            if (!s.GetChip())
            {
                break;
            }
            if (s.GetChip().id != chip.id)
            {
                break;
            }
            if (!s.GetChip().IsMatcheble())
            {
                break;
            }
            potencialV += s.GetChip().GetPotencial();
            t++;
        }

        // searching bottom chips
        for (y = slot.y - 1; y >= 0; y--)
        {
            o = GameObject.Find("Slot_" + slot.x + "x" + y);
            if (!o)
            {
                break;
            }
            s = o.GetComponent <Slot>();
            if (!s)
            {
                break;
            }
            if (!s.GetChip())
            {
                break;
            }
            if (s.GetChip().id != chip.id)
            {
                break;
            }
            if (!s.GetChip().IsMatcheble())
            {
                break;
            }
            potencialV += s.GetChip().GetPotencial();
            b++;
        }

        // Formation of solution if it is there
        if (r + l >= 2 || t + b >= 2)
        {
            SessionAssistant.Solution solution = new SessionAssistant.Solution();
            solution.h      = r + l >= 2;
            solution.v      = t + b >= 2;
            solution.x      = slot.x;
            solution.y      = slot.y;
            solution.count  = 1;
            solution.count += solution.v ? t + b : 0;
            solution.count += solution.h ? r + l : 0;
            solution.id     = chip.id;
            solution.posH   = r;
            solution.negH   = l;
            solution.posV   = t;
            solution.negV   = b;
            if (solution.v)
            {
                solution.potencial += potencialV;
            }
            if (solution.h)
            {
                solution.potencial += potencialH;
            }
            solution.potencial += chip.GetPotencial();
            return(solution);
        }
        return(null);
    }