/// <summary>
        /// Determine the move based on user input
        /// </summary>
        /// <param name="inputKey"></param>
        /// <returns> Move as a string </returns>
        public static string DetermineMove(CellSide sideToCross)
        {
            var move = string.Empty;

            switch (sideToCross)
            {
            case CellSide.North:
                move = "north";
                break;

            case CellSide.West:
                move = "west";
                break;

            case CellSide.South:
                move = "south";
                break;

            case CellSide.East:
                move = "east";
                break;

            default:
                throw new ArgumentException("Side of the cell to cross is invalid.");
            }

            return(move);
        }
Beispiel #2
0
    public LineTransform GetLineTransform(CellSide side)
    {
        LineTransform line = new LineTransform();

        switch (side)
        {
        case CellSide.Left:
            line.Position = this.left;
            line.Rotation = this.verticalRotation;
            break;

        case CellSide.Right:
            line.Position = this.right;
            line.Rotation = this.verticalRotation;
            break;

        case CellSide.Bottom:
            line.Position = this.bottom;
            line.Rotation = Quaternion.identity;
            break;

        default:
            line.Position = this.top;
            line.Rotation = Quaternion.identity;
            break;
        }

        return(line);
    }
Beispiel #3
0
        private void SwapNeighbors(CellSide a, CellSide b)
        {
            var buffer = GetNeighbor(a);

            SetNeighbor(a, GetNeighbor(b));
            SetNeighbor(b, buffer);
        }
 public Side(int _x, int _y, int _z, CellSide _side)
 {
     x    = _x;
     y    = _y;
     z    = _z;
     side = _side;
 }
Beispiel #5
0
    public bool IsUpdatedNeighbourClosed(CellSide side, GameObject line)
    {
        switch (side)
        {
        case CellSide.Left:
            this.rightLine = line;
            break;

        case CellSide.Right:
            this.leftLine = line;
            break;

        case CellSide.Bottom:
            this.topLine = line;
            break;

        default:
            this.bottomLine = line;
            break;
        }

        if (this.IsClosed())
        {
            this.SetOwner();
            return(true);
        }

        return(false);
    }
        //public static Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone GetZone(Index3 cellIndex, List<Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone> Zones)//List<Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone> TopZone)
        //{
        //    foreach (Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone zone in Zones)
        //    {
        //        if (cellIndex.K > zone.BaseK && cellIndex.K)
        //       {
        //       }
        //    }
        //}
        public static Point3[] GetCornerSet(CellSide SideOfCell, Grid gridInContext, Index3 CellIndex)
        {
            CellCorner[] CellCorners = new CellCorner[4];
            Point3[] CellCornerPoints = new Point3[4];

            switch (SideOfCell)
            {
                case CellSide.Up:
                    CellCorners[0] = CellCorner.TopNorthWest; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.TopSouthWest;
                    CellCorners[3] = CellCorner.TopSouthEast;
                    CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners);

                    break;

                case CellSide.East:
                    CellCorners[0] = CellCorner.TopSouthEast; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.BaseSouthEast;
                    CellCorners[3] = CellCorner.BaseNorthEast;
                    CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners);

                    break;

                case CellSide.West:

                    CellCorners[0] = CellCorner.TopSouthWest; CellCorners[1] = CellCorner.TopNorthWest; CellCorners[2] = CellCorner.BaseSouthWest;
                    CellCorners[3] = CellCorner.BaseNorthWest;
                    CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners);

                    break;

                case CellSide.South:
                    CellCorners[0] = CellCorner.TopSouthWest; CellCorners[1] = CellCorner.TopSouthEast; CellCorners[2] = CellCorner.BaseSouthWest;
                    CellCorners[3] = CellCorner.BaseSouthEast;
                    CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners);

                    break;

                case CellSide.North:

                    CellCorners[0] = CellCorner.TopNorthWest; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.BaseNorthWest;
                    CellCorners[3] = CellCorner.BaseNorthEast;
                    CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners);

                    break;

                case CellSide.Down:

                    CellCorners[0] = CellCorner.BaseNorthWest; CellCorners[1] = CellCorner.BaseNorthEast; CellCorners[2] = CellCorner.BaseSouthWest;
                    CellCorners[3] = CellCorner.BaseSouthEast;
                    CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners);

                    break;
                default:

                    CellCornerPoints = null;
                    break;
            }

            return CellCornerPoints;
        }
Beispiel #7
0
    IEnumerator MakeSelection(Cell cell, CellSide side)
    {
        yield return(new WaitForSeconds(this.selectionWaitTime));

        cell.DestroyHighlight();
        cell.SelectSide(this.lineSelectionPrefab, side);

        this.isThinking = false;
    }
    public static Side GetSide(Vector3 vec, CellSide cellside)
    {
        Vector3 edgeOffset = (cellside == CellSide.West) ?
                             new Vector3(HORIZONTAL_CELL_UNIT / 2f, 0, 0) :
                             new Vector3(0, 0, HORIZONTAL_CELL_UNIT / 2f);

        vec = vec - CELL_OFFSET + edgeOffset;

        return(new Side(Mathf.RoundToInt(vec.x / HORIZONTAL_CELL_UNIT), Mathf.RoundToInt(vec.y / VERTICAL_CELL_UNIT), Mathf.RoundToInt(vec.z / HORIZONTAL_CELL_UNIT), cellside));
    }
Beispiel #9
0
    private void OnMouseOver()
    {
        if (!this.gameMaster.IsPlayerTurn)
        {
            return;
        }

        CellSide side = this.GetMouseOverSide();

        if (this.IsSideOccupied(side))
        {
            this.DestroyHighlight();
            return;
        }

        this.HighlightSide(this.playerHighlightPrefab, this.GetLineTransform(side));
    }
Beispiel #10
0
    private void OnMouseDown()
    {
        if (!this.gameMaster.IsPlayerTurn)
        {
            return;
        }

        CellSide side = this.GetMouseOverSide();

        if (this.IsSideOccupied(side))
        {
            return;
        }

        this.DestroyHighlight();

        this.SelectSide(this.playerSelectionPrefab, side);
    }
Beispiel #11
0
    private bool IsSideOccupied(CellSide side)
    {
        switch (side)
        {
        case CellSide.Left:
            if (this.leftLine != null)
            {
                return(true);
            }

            break;

        case CellSide.Right:
            if (this.rightLine != null)
            {
                return(true);
            }

            break;

        case CellSide.Bottom:
            if (this.bottomLine != null)
            {
                return(true);
            }

            break;

        case CellSide.Top:
            if (this.topLine != null)
            {
                return(true);
            }

            break;
        }

        return(false);
    }
        /// <summary>
        /// Find the id of the adjacent cell when crossing the specified side of the current cell
        /// </summary>
        /// <param name="cellId">Id of the current cell</param>
        /// <param name="side">Side of the current cell to cross</param>
        /// <returns>Id of the adjacent cell</returns>
        public int IdentifyAdjacentCell(int cellId, CellSide side)
        {
            if (cellId < 0 || cellId > Width * Height)
            {
                throw new ArgumentException("Wrong current cell id. It does not correspond to a cell of the maze.");
            }

            int adjacentCellId;

            switch (side)
            {
            case CellSide.North:
                adjacentCellId = cellId - Width;
                break;

            case CellSide.West:
                adjacentCellId = cellId - 1;
                break;

            case CellSide.South:
                adjacentCellId = cellId + Width;
                break;

            case CellSide.East:
                adjacentCellId = cellId + 1;
                break;

            default:
                throw new ArgumentException("The side identifier passed does not exist.");
            }

            if (adjacentCellId < 0 || adjacentCellId >= Width * Height)
            {
                throw new ArgumentException("The side specified is not valid because it is part of the boundary of the maze.");
            }

            return(adjacentCellId);
        }
        /// <summary>
        /// When entering for the first time in a cell, mark the entry side as such to make sure it will be the last option for the next moves
        /// </summary>
        /// <param name="currentPosition"></param>
        /// <param name="sideToCross"></param>
        public void SetFirstEnteredSideStatus(int currentPosition, CellSide sideToCross)
        {
            switch (sideToCross)
            {
            case CellSide.North:
                if (Cells[currentPosition - Width].FirstEnteredSide == null)
                {
                    Cells[currentPosition - Width].FirstEnteredSide = CellSide.South;
                }
                break;

            case CellSide.West:
                if (Cells[currentPosition - 1].FirstEnteredSide == null)
                {
                    Cells[currentPosition - 1].FirstEnteredSide = CellSide.East;
                }
                break;

            case CellSide.South:
                if (Cells[currentPosition + Width].FirstEnteredSide == null)
                {
                    Cells[currentPosition + Width].FirstEnteredSide = CellSide.North;
                }
                break;

            case CellSide.East:
                if (Cells[currentPosition + 1].FirstEnteredSide == null)
                {
                    Cells[currentPosition + 1].FirstEnteredSide = CellSide.West;
                }
                break;

            default:
                break;
            }
        }
Beispiel #14
0
 private void SwapNeighbors(CellSide a, CellSide b)
 {
     var buffer = GetNeighbor(a);
     SetNeighbor(a, GetNeighbor(b));
     SetNeighbor(b, buffer);
 }
Beispiel #15
0
    private IEnumerator DetermineSelection()
    {
        yield return(new WaitForSeconds(0.1f));

        Dictionary <string, List <AICell> > cellsByPriority = new Dictionary <string, List <AICell> > {
            { AI.bestIndex, new List <AICell>() },
            { AI.goodIndex, new List <AICell>() },
            { AI.badIndex, new List <AICell>() }
        };

        for (int i = 0; i < this.gameMaster.Cells.Count; i++)
        {
            for (int j = 0; j < this.gameMaster.Cells.Count; j++)
            {
                if (this.gameMaster.Cells[i][j].IsClosed())
                {
                    continue;
                }

                List <CellSide> freeSides = this.gameMaster.Cells[i][j].GetFreeSides();
                switch (freeSides.Count)
                {
                case 1:
                    cellsByPriority[AI.bestIndex].Add(new AICell(this.gameMaster.Cells[i][j], freeSides));
                    break;

                case 3:
                case 4:
                    if (this.difficulty == Difficulty.Easy)
                    {
                        cellsByPriority[AI.goodIndex].Add(new AICell(this.gameMaster.Cells[i][j], freeSides));
                        break;
                    }

                    List <CellSide> validNeighbourSides = this.gameMaster.Cells[i][j].GetValidNeighbourSides();
                    if (validNeighbourSides.Count == 0)
                    {
                        cellsByPriority[AI.badIndex].Add(new AICell(this.gameMaster.Cells[i][j], freeSides));
                        break;
                    }

                    cellsByPriority[AI.goodIndex].Add(new AICell(this.gameMaster.Cells[i][j], validNeighbourSides));
                    break;

                case 2:
                    cellsByPriority[AI.badIndex].Add(new AICell(this.gameMaster.Cells[i][j], freeSides));
                    break;
                }
            }
        }

        string selectedKey;

        if (cellsByPriority[AI.bestIndex].Count > 0)
        {
            selectedKey = AI.bestIndex;

            if (this.difficulty == Difficulty.Insane && cellsByPriority[AI.goodIndex].Count == 0)
            {
                List <AICell> board = new List <AICell>();
                board.AddRange(cellsByPriority[AI.bestIndex]);
                board.AddRange(cellsByPriority[AI.badIndex]);

                this.FilterBadCells(board);

                AICell crossCell = this.ChainDoubleCross();
                if (crossCell.Cell != null)
                {
                    cellsByPriority[AI.bestIndex] = new List <AICell> {
                        crossCell
                    };
                }
            }
        }
        else if (cellsByPriority[AI.goodIndex].Count > 0)
        {
            selectedKey = AI.goodIndex;
        }
        else
        {
            selectedKey = AI.badIndex;

            if (this.difficulty == Difficulty.Hard || this.difficulty == Difficulty.Insane)
            {
                cellsByPriority[AI.badIndex] = new List <AICell> {
                    this.FilterBadCells(cellsByPriority[AI.badIndex])
                };
            }

            if (this.difficulty == Difficulty.Insane)
            {
                cellsByPriority[AI.badIndex] = new List <AICell> {
                    this.DoubleCross(cellsByPriority[AI.badIndex][0])
                };
            }
        }

        int  selectionIndex = (int)Random.Range(0, cellsByPriority[selectedKey].Count);
        Cell selection      = cellsByPriority[selectedKey][selectionIndex].Cell;

        int      sideIndex = (int)Random.Range(0, cellsByPriority[selectedKey][selectionIndex].Sides.Count);
        CellSide side      = cellsByPriority[selectedKey][selectionIndex].Sides[sideIndex];

        selection.HighlightSide(this.lineHighlightPrefab, selection.GetLineTransform(side));
        StartCoroutine(MakeSelection(selection, side));
    }
Beispiel #16
0
        static async Task RunAsync()
        {
            try
            {
                string mazeId = await InitializeMaze().ConfigureAwait(false);

                Console.WriteLine(mazeId);
                await _gameService.PrintMazeAsync(mazeId).ConfigureAwait(false);

#if INTERACTIVE
                #region Logic to play the game interactively

                bool active = true;
                while (active)
                {
                    Console.WriteLine($"What is your next move (N, W, S, E)?");
                    var inputKey = Console.ReadKey().Key;

                    if (!ValidKeys.Contains(inputKey))
                    {
                        Console.WriteLine("The input is invalid.");
                        continue;
                    }

                    var statuses = await _gameService.MakeNextMoveAsync(mazeId, DetermineMove(inputKey)).ConfigureAwait(false);

                    await _gameService.PrintMazeAsync(mazeId).ConfigureAwait(false);

                    Console.WriteLine(statuses.MoveStatus);

                    if (!statuses.MazeState.Equals("active"))
                    {
                        active = false;
                        Console.WriteLine(statuses.MazeState);
                    }
                }

                #endregion
#else
                var mazeState = await _gameService.GetMazeCurrentStateAsync(mazeId).ConfigureAwait(false);

                var mazeSolver = new MazeSolver(mazeState);
                mazeSolver.SetDistanceToExit(mazeState.ExitPosition[0]);

                while (mazeState.GameState.MazeState.ToLower() == "active")
                {
                    var ponyPosition = mazeState.PonyPosition[0];

                    CellSide sideToCross = mazeSolver.FindSideToCross(ponyPosition);
                    mazeSolver.Cells[ponyPosition].Sides[sideToCross] = CellSideState.Closed;

                    var statuses = await _gameService.MakeNextMoveAsync(mazeId, DetermineMove(sideToCross)).ConfigureAwait(false);

                    if (statuses.MoveStatus.ToLower().Equals("move accepted"))
                    {
                        mazeSolver.SetFirstEnteredSideStatus(ponyPosition, sideToCross);
                    }

                    await _gameService.PrintMazeAsync(mazeId).ConfigureAwait(false);

                    Console.WriteLine(statuses.MoveStatus);

                    mazeState = await _gameService.GetMazeCurrentStateAsync(mazeId).ConfigureAwait(false);

                    if (mazeState.GameState.MazeState != "active")
                    {
                        Console.WriteLine(statuses.MazeState);
                    }

                    Thread.Sleep(250);
                }
#endif
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message} Line : {ex.StackTrace}");
            }
        }
Beispiel #17
0
    private AICell ChainDoubleCross()
    {
        int chainCount = 0;
        int chainIndex = 0;

        for (int i = 0; i < this.chainCells.Count; i++)
        {
            if (this.chainCells[i].length < 3 && !this.isClosingInChain)
            {
                return(new AICell(null, null));
            }

            if (this.chainCells[i].length < 3 && this.isClosingInChain)
            {
                chainIndex = i;
            }

            if (this.chainCells[i].length > 2)
            {
                chainCount++;
            }
        }

        if (chainCount < 2)
        {
            if (!this.isClosingInChain)
            {
                return(new AICell(null, null));
            }
        }
        else
        {
            if (!this.isClosingInChain)
            {
                this.isClosingInChain = true;
                return(new AICell(null, null));
            }

            if (this.isClosingInChain)
            {
                bool doDoubleCross = false;
                for (int i = 0; i < this.chainCells.Count; i++)
                {
                    if (this.chainCells[i].length == 2)
                    {
                        doDoubleCross = true;
                        break;
                    }
                }

                if (!doDoubleCross)
                {
                    return(new AICell(null, null));
                }
            }
        }

        this.isClosingInChain = false;

        AICell   chainCell = this.chainCells[chainIndex].AICell;
        Cell     neighbour = null;
        CellSide opposite  = CellSide.Left;

        if (chainCell.Sides.Count == 1)
        {
            switch (chainCell.Sides[0])
            {
            case CellSide.Left:
                neighbour = gameMaster.Cells[chainCell.Cell.Row][chainCell.Cell.Column - 1];
                opposite  = CellSide.Right;
                break;

            case CellSide.Right:
                neighbour = gameMaster.Cells[chainCell.Cell.Row][chainCell.Cell.Column + 1];
                opposite  = CellSide.Left;
                break;

            case CellSide.Bottom:
                neighbour = gameMaster.Cells[chainCell.Cell.Row + 1][chainCell.Cell.Column];
                opposite  = CellSide.Top;
                break;

            case CellSide.Top:
                neighbour = gameMaster.Cells[chainCell.Cell.Row - 1][chainCell.Cell.Column];
                opposite  = CellSide.Bottom;
                break;
            }

            List <CellSide> neighbourFreeSides = neighbour.GetFreeSides();
            if (neighbourFreeSides.Count == 1)
            {
                return(new AICell(null, null));
            }

            neighbourFreeSides.Remove(opposite);
            return(new AICell(neighbour, neighbourFreeSides));
        }

        List <CellSide> resultSides = chainCell.Sides;

        switch (chainCell.Sides[0])
        {
        case CellSide.Left:
            if (chainCell.Cell.Column == 0)
            {
                resultSides = new List <CellSide> {
                    CellSide.Left
                }
            }
            ;
            else
            {
                resultSides.Remove(CellSide.Left);
            }
            break;

        case CellSide.Right:
            if (chainCell.Cell.Column == gameMaster.Cells.Count - 1)
            {
                resultSides = new List <CellSide> {
                    CellSide.Right
                }
            }
            ;
            else
            {
                resultSides.Remove(CellSide.Right);
            }
            break;

        case CellSide.Bottom:
            if (chainCell.Cell.Row == gameMaster.Cells.Count - 1)
            {
                resultSides = new List <CellSide> {
                    CellSide.Bottom
                }
            }
            ;
            else
            {
                resultSides.Remove(CellSide.Bottom);
            }
            break;

        case CellSide.Top:
            if (chainCell.Cell.Row == 0)
            {
                resultSides = new List <CellSide> {
                    CellSide.Top
                }
            }
            ;
            else
            {
                resultSides.Remove(CellSide.Top);
            }
            break;
        }

        return(new AICell(chainCell.Cell, resultSides));
    }
Beispiel #18
0
 public void SetNeighbor(CellSide side, Cell cell)
 {
     _neighbors[(int) side] = cell;
 }
Beispiel #19
0
        public Cell GetNeighbor(CellSide side)
        {
            var neighbor = _neighbors[(int) side];

            return neighbor;
        }
Beispiel #20
0
 public void SetNeighbor(CellSide side, Cell cell)
 {
     _neighbors[(int)side] = cell;
 }
Beispiel #21
0
        public Cell GetNeighbor(CellSide side)
        {
            var neighbor = _neighbors[(int)side];

            return(neighbor);
        }
        public static List<double> GetListOfPenetratedCellDistances(Grid gridInContext, Borehole bh, List<Index3> ListOfSelectedIntersectingGridCells, bool PerforatedZonesOnly, bool Vertical_only)
        {
            IPillarGridIntersectionService pgiservice = CoreSystem.GetService<IPillarGridIntersectionService>();
            Quadrilateral Face1;
            Quadrilateral Face2;
            CellCorner[] CellCorners = new CellCorner[4];
            Point3[] CellCornerPoints1 = new Point3[4];
            Point3[] CellCornerPoints2 = new Point3[4];
            CellSide Side = new CellSide() ;
            //Dictionary<Index3,List<double>> DictionaryOfSelectedCells = new Dictionary<Index3,List<double>>(ListOfSelectedIntersectingGridCells.Count);
               // List<double> Distance = new List<double>(3); //This array will contain the Height of the cell for the kh calculation and two extra elements that will be empty;
            List<double> Distance = new List<double>();

            if (!Vertical_only)
            {
                List<CellSide> ListOfEnteringSides = GetListOfEnteringSidesOfIntersectedCells(pgiservice, gridInContext, bh, ListOfSelectedIntersectingGridCells, PerforatedZonesOnly);
                for (int i = 0; i < ListOfEnteringSides.Count; i++)
                {
                    switch (ListOfEnteringSides[i])
                    {
                     case CellSide.Up:
                        CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]);

                        Side = CellSide.Down;
                        CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]);

                            break;

                     case CellSide.East:
                        CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]);

                        Side = CellSide.West;
                        CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]);

                            break;

                      case CellSide.West:
                           CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]);

                        Side = CellSide.East;
                        CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]);

                            break;

                      case CellSide.South:
                           CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]);

                            Side = CellSide.North;
                            CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]);

                            break;

                      case CellSide.North:
                           CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]);

                        Side = CellSide.South;
                        CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]);

                            break;

                        case CellSide.Down:
                            CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]);

                        Side = CellSide.Up;
                        CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]);

                            break;
                        default:

                            CellCornerPoints1 = null;
                            CellCornerPoints2= null;
                            break;
                    }

                    try
                    {
                        Face1 = new Quadrilateral(CellCornerPoints1[0], CellCornerPoints1[1], CellCornerPoints1[2], CellCornerPoints1[3]);
                    }
                    catch
                    {
                        Face1 = null;
                    }

                    try
                    {
                        Face2 = new Quadrilateral(CellCornerPoints2[0], CellCornerPoints2[1], CellCornerPoints2[2], CellCornerPoints2[3]);
                    }
                    catch
                    {
                        Face2 = null;
                    }

                    try
                    {
                        // Distance[0] = Face1.Centroid.Distance(Face2.Centroid);
                        //DictionaryOfSelectedCells.Add(ListOfSelectedIntersectingGridCells[i], Distance);
                        Distance.Add(Face1.Centroid.Distance(Face2.Centroid));
                    }
                    catch
                    {
                        Distance.Add(-1);
                        //DictionaryOfSelectedCells.Add(ListOfSelectedIntersectingGridCells[i], null);
                    }

                }
            }
            else //If only the vertical distance from top to base face of cell is required.
            {
                for (int i = 0; i < ListOfSelectedIntersectingGridCells.Count; i++)
                {
                    //CellCorners[0] = CellCorner.TopNorthWest; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.TopSouthWest;
                    //CellCorners[3] = CellCorner.TopSouthEast;
                    //CellCornerPoints = gridInContext.GetCellCorners(ListOfSelectedIntersectingGridCells[i], CellCorners);
                    Side = CellSide.Up;
                    CellCornerPoints1 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]);

                    Side = CellSide.Down;
                    CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]);

                    try
                    {
                        Face1 = new Quadrilateral(CellCornerPoints1[0], CellCornerPoints1[1], CellCornerPoints1[2], CellCornerPoints1[3]);
                    }
                    catch
                    {
                        Face1 = null;
                    }

                    try
                    {
                        Face2 = new Quadrilateral(CellCornerPoints2[0], CellCornerPoints2[1], CellCornerPoints2[2], CellCornerPoints2[3]);
                    }
                    catch
                    {
                        Face2 = null;
                    }

                    try
                    {
                        // Distance[0] = Face1.Centroid.Distance(Face2.Centroid);
                        //DictionaryOfSelectedCells.Add(ListOfSelectedIntersectingGridCells[i], Distance);

                        if (!Double.IsNaN(Face1.Centroid.Distance(Face2.Centroid)))
                        {
                            Distance.Add(Face1.Centroid.Distance(Face2.Centroid));
                        }
                        else
                        {
                            Distance.Add(-1);
                        }
                    }
                    catch
                    {
                        Distance.Add(-1);
                        //DictionaryOfSelectedCells.Add(ListOfSelectedIntersectingGridCells[i], null);
                    }

                }
            }

            return Distance;
            //return DictionaryOfSelectedCells;
        }
Beispiel #23
0
    public void SelectSide(GameObject prefab, CellSide side)
    {
        LineTransform line = this.GetLineTransform(side);

        GameObject selectionLine = Instantiate(prefab, line.Position, line.Rotation);

        RectTransform selectionLineRect = selectionLine.GetComponent <RectTransform>();

        selectionLineRect.SetParent(GetComponent <RectTransform>());
        selectionLineRect.localScale = new Vector3(1, 0.333f);

        Cell neighbourCell = null;

        switch (side)
        {
        case CellSide.Left:
            this.leftLine = selectionLine;
            if (this.Column > 0)
            {
                neighbourCell = this.gameMaster.Cells[this.Row][this.Column - 1];
            }

            break;

        case CellSide.Right:
            this.rightLine = selectionLine;
            if (this.Column < this.gameMaster.Cells.Count - 1)
            {
                neighbourCell = this.gameMaster.Cells[this.Row][this.Column + 1];
            }

            break;

        case CellSide.Bottom:
            this.bottomLine = selectionLine;
            if (this.Row < this.gameMaster.Cells.Count - 1)
            {
                neighbourCell = this.gameMaster.Cells[this.Row + 1][this.Column];
            }

            break;

        default:
            this.topLine = selectionLine;
            if (this.Row > 0)
            {
                neighbourCell = this.gameMaster.Cells[this.Row - 1][this.Column];
            }

            break;
        }

        bool isNeighboutClosed = false;

        if (neighbourCell != null)
        {
            isNeighboutClosed = neighbourCell.IsUpdatedNeighbourClosed(side, selectionLine);
        }

        if (this.IsClosed())
        {
            this.SetOwner();
            return;
        }

        if (isNeighboutClosed)
        {
            return;
        }

        this.gameMaster.UpdateTurn();
    }