예제 #1
0
            private bool ForceBridgeOn(Branch b)
            {
                Point p = b.Last();

                foreach (Point d in Grid.Directions)
                {
                    Point onceOver  = Grid.NeigbourCoordinates(p, d);
                    Point twiceOver = Grid.NeigbourCoordinates(onceOver, d);
                    if (IsBridge(p, d) && !b.Contains(twiceOver))
                    {
                        b.Add(onceOver);
                        //Pokud jde o horizontální směr, zapamatuj si která barva je nahoře
                        if (d.Y == 0)
                        {
                            Cells[onceOver.X, onceOver.Y] = Cells[p.X, p.Y];
                        }
                        b.Add(twiceOver);
                        if (Cells[twiceOver.X, twiceOver.Y] == Cells[p.X, p.Y])
                        {
                            b.Solved = b.Other.Solved = true;
                        }
                        else
                        {
                            Cells[twiceOver.X, twiceOver.Y] = Cells[p.X, p.Y];
                        }
                        return(true);
                    }
                }
                return(false);
            }
예제 #2
0
            //Provede na větvi vynucený pohyb, pokud existuje
            private bool ForcedMove(Branch b)
            {
                Point p = b.Last();

                //Spojí dvě větve stejné barvy, pokud sousedí
                foreach (Point d in Grid.Directions)
                {
                    Point onceOver = Grid.NeigbourCoordinates(p, d);
                    if (Cells[onceOver.X, onceOver.Y] == Cells[p.X, p.Y] && !b.Contains(onceOver) && !IsWall(p, d))
                    {
                        if (b.Other.Last() == onceOver)
                        {
                            b.Add(onceOver);
                            b.Solved = b.Other.Solved = true;
                            return(true);
                        }
                    }
                }
                //Provede pohyb, pokud je z daného místa jediný možný
                List <Point> possibleDirs = Grid.Directions.Where(d => IsEmpty(p, d) && !IsBridge(p, d) && !IsWall(p, d)).ToList();

                if (possibleDirs.Count == 1)
                {
                    Point d  = possibleDirs[0];
                    Point p1 = Grid.NeigbourCoordinates(p, d);
                    Cells[p1.X, p1.Y] = Cells[p.X, p.Y];
                    b.Add(p1);
                    ForceBridgeOn(b);
                    return(true);
                }
                return(false);
            }
예제 #3
0
            private bool IsEndOfDifferentColor(Point p, Point d, int color)
            {
                return(false);

                Point p2 = Grid.NeigbourCoordinates(p, d);

                return(Branches.Any(b => b.Color != color && b.Last() == p2));
            }
예제 #4
0
            private IEnumerable <GridState> BranchNextStates(int i) //Musí se chodit přes index
            {
                Point be         = Branches[i].Last();
                var   directions = Grid.Directions.Where(d => CanGoTo(Branches[i], d)).OrderBy(d => RateDirection(Branches[i], d)).ToList();

                foreach (Point d in directions)
                {
                    Point     np       = Grid.NeigbourCoordinates(be, d);
                    GridState newState = new GridState(this);
                    newState.Branches[i].Add(np);
                    newState.Cells[np.X, np.Y] = Cells[be.X, be.Y];
                    newState.MakeForcedMoves();
                    yield return(newState);
                }
            }
예제 #5
0
            //Zkontroluje jestli některá branch není zakroucená tak, že by do stejného místa mohla dojít jednodušeji

            private bool IsBranchTooComplicated(Branch br)
            {
                Point be = br.Last();

                foreach (Point d in Grid.Directions)
                {
                    if (!IsWall(be, d) && CellTo(be, d) == br.Color)
                    {
                        Point meetingPoint  = Grid.NeigbourCoordinates(be, d);
                        var   pointsBetween = br.SkipWhile(p => p != meetingPoint);
                        if (pointsBetween.Count() > 2 && pointsBetween.All(p => !Grid.Bridges[p.X, p.Y]))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
예제 #6
0
 //Označí pole a všechna sousedící stejným id
 private bool MarkCellArea(Point p, int id)
 {
     if (Areas[p.X, p.Y] == -1 && Cells[p.X, p.Y] == -1 && !Grid.Bridges[p.X, p.Y])
     {
         Areas[p.X, p.Y] = id;
         foreach (Point d in Grid.Directions)
         {
             if (CanGoTo(p, d))
             {
                 Point neigbour = Grid.NeigbourCoordinates(p, d);
                 if (Grid.Bridges[neigbour.X, neigbour.Y])
                 {
                     neigbour = Grid.NeigbourCoordinates(neigbour, d);
                 }
                 MarkCellArea(neigbour, id);
             }
         }
         return(true);
     }
     return(false);
 }
예제 #7
0
 private bool CanGoTo(Point p, Branch br, Point dir)
 {
     return((IsEmpty(p, dir) || br.Other.Last() == Grid.NeigbourCoordinates(p, dir)) && !IsWall(p, dir));
 }
예제 #8
0
            private int RateDirection(Branch br, Point dir)
            {
                Point nxt = Grid.NeigbourCoordinates(br.Last(), dir);

                return(10000 * Grid.Directions.Count(d => CanGoTo(nxt, br, d)) + Grid.Distance(nxt, br.Other.Last()));
            }