Esempio n. 1
0
    public List <Coordinate> GetBetween(Coordinate origin, WallLocation location)
    {
        Coordinate other;



        switch (location)
        {
        default:
        case WallLocation.Upper:
            other = GameObjects.GridGenerator.GetNeighborInDirection(origin, WallLocation.Upper);
            break;

        case WallLocation.Lower:
            other = GameObjects.GridGenerator.GetNeighborInDirection(origin, WallLocation.Lower);
            break;

        case WallLocation.UpperLeft:
            other = GameObjects.GridGenerator.GetNeighborInDirection(origin, WallLocation.UpperLeft);
            break;

        case WallLocation.LowerRight:
            other = GameObjects.GridGenerator.GetNeighborInDirection(origin, WallLocation.LowerRight);
            break;

        case WallLocation.UpperRight:
            other = GameObjects.GridGenerator.GetNeighborInDirection(origin, WallLocation.UpperRight);
            break;

        case WallLocation.LowerLeft:
            other = GameObjects.GridGenerator.GetNeighborInDirection(origin, WallLocation.LowerLeft);
            break;
        }

        return(new List <Coordinate> {
            origin, other
        });
    }
        public void PlayTest()
        {
            // the size of the board (2 ≤ N ≤ 40)
            byte N = 4;
            // the number of marbles (M > 0)
            byte M = 3;
            // the number of walls
            byte W = 1;

            // locations of the marbles
            Marble[] marbles = new Marble[] { new Marble(1, 0, 1), new Marble(2, 1, 0), new Marble(3, 1, 2) };

            // locations of the holes
            Hole[] holes = new Hole[] { new Hole(1, 2, 3), new Hole(2, 2, 1), new Hole(3, 3, 2) };

            WallLocation[] walls = new WallLocation[] { new WallLocation(new Location(1, 1), new Location(1, 2)) };

            MarbleGame game = new MarbleGame();

            var result = game.Play(N, walls, holes, marbles);

            Assert.Fail();
        }
Esempio n. 3
0
        public bool[,] GetActive()
        {
            var active      = new bool[Height, Width];
            var searchStack = new Stack <(int Row, int Col)>();

            searchStack.Push((Height / 2, Width / 2));

            while (searchStack.Count > 0)
            {
                var thisCell = searchStack.Pop();
                active[thisCell.Row, thisCell.Col] = true;

                foreach (var thisCellDirection in (WallLocation[])Enum.GetValues(typeof(WallLocation)))
                {
                    WallLocation otherCellDirection = WallLocation.Top;
                    (int Row, int Col)otherCell = thisCell;
                    switch (thisCellDirection)
                    {
                    case WallLocation.Top:
                    {
                        if (thisCell.Row == 0)
                        {
                            continue;
                        }

                        otherCellDirection = WallLocation.Bottom;
                        otherCell.Row--;
                        break;
                    }

                    case WallLocation.Right:
                    {
                        if (thisCell.Col == Width - 1)
                        {
                            continue;
                        }

                        otherCellDirection = WallLocation.Left;
                        otherCell.Col++;
                        break;
                    }

                    case WallLocation.Bottom:
                    {
                        if (thisCell.Row == Height - 1)
                        {
                            continue;
                        }

                        otherCellDirection = WallLocation.Top;
                        otherCell.Row++;
                        break;
                    }

                    case WallLocation.Left:
                    {
                        if (thisCell.Col == 0)
                        {
                            continue;
                        }

                        otherCellDirection = WallLocation.Right;
                        otherCell.Col--;
                        break;
                    }
                    }

                    var thisCellValue  = Cells[thisCell.Row, thisCell.Col];
                    var otherCellValue = Cells[otherCell.Row, otherCell.Col];
                    if ((thisCellValue & (int)thisCellDirection) != 0 &&
                        (otherCellValue & (int)otherCellDirection) != 0 &&
                        (!active[otherCell.Row, otherCell.Col]))
                    {
                        searchStack.Push(otherCell);
                    }
                }
            }

            return(active);
        }
Esempio n. 4
0
    public Coordinate GetNeighborInDirection(Coordinate origin, WallLocation direction)
    {
        var neighbors = GetNeighborsDirections(origin);

        var neighbor = neighbors.Where(n => n.Key == direction).ToList();

        if (neighbor.Count == 0 || neighbor.Count > 1)
        {
            Coordinate coordinate = origin;

            if (direction == WallLocation.Upper)
            {
                coordinate.r += 1;
            }
            else if (direction == WallLocation.Lower)
            {
                coordinate.r -= 1;
            }
            else
            {
                if (origin.q % 2 == 0)
                {
                    switch (direction)
                    {
                    default:
                    case WallLocation.UpperLeft:
                        coordinate.q -= 1;
                        break;

                    case WallLocation.LowerRight:
                        coordinate.q += 1;
                        coordinate.r -= 1;
                        break;

                    case WallLocation.UpperRight:
                        coordinate.q += 1;
                        break;

                    case WallLocation.LowerLeft:
                        coordinate.q -= 1;
                        coordinate.r -= 1;
                        break;
                    }
                }
                else
                {
                    switch (direction)
                    {
                    default:
                    case WallLocation.UpperLeft:
                        coordinate.q -= 1;
                        coordinate.r += 1;
                        break;

                    case WallLocation.LowerRight:
                        coordinate.q += 1;
                        break;

                    case WallLocation.UpperRight:
                        coordinate.q += 1;
                        coordinate.r += 1;
                        break;

                    case WallLocation.LowerLeft:
                        coordinate.q -= 1;
                        break;
                    }
                }
            }

            return(coordinate);
        }

        return(neighbor[0].Value);
    }
Esempio n. 5
0
    public void SpawnWall(WallType type, WallLocation location, GameObject owner)
    {
        GameObject WallObject;

        switch (type)
        {
        default:
        case WallType.None:
            return;

        case WallType.BarbedWire:
            WallObject = Instantiate(WireFencePrefab) as GameObject;
            break;

        case WallType.BrickWall:
            WallObject = Instantiate(BrickWallPrefab) as GameObject;
            break;

        case WallType.WoodWall:
            WallObject = Instantiate(WoodWallPrefab) as GameObject;
            break;
        }

        var WallScript = WallObject.GetComponent <WallScript>();

        WallScript.betweenA = owner.GetComponent <HexTile>().Coordinate;
        WallScript.betweenB = GetBetween(WallScript.betweenA, location)[1];

        WallObject.transform.SetParent(owner.transform);

        switch (location)
        {
        default:
        case WallLocation.Upper:
            WallObject.transform.localPosition = new Vector3(-0.8683267f, 0f);
            break;

        case WallLocation.Lower:
            WallObject.transform.localPosition = new Vector3(0.8683267f, 0f);
            break;

        case WallLocation.UpperLeft:
            WallObject.transform.localPosition = new Vector3(-0.4341633f, 0.7519927f);
            WallObject.transform.localRotation = Quaternion.Euler(0f, 0f, -60f);
            break;

        case WallLocation.LowerRight:
            WallObject.transform.localPosition = new Vector3(0.4341633f, -0.7519927f);
            WallObject.transform.localRotation = Quaternion.Euler(0f, 0f, -60f);
            break;

        case WallLocation.UpperRight:
            WallObject.transform.localPosition = new Vector3(-0.4341624f, -0.7519927f);
            WallObject.transform.localRotation = Quaternion.Euler(0f, 0f, -120f);
            break;

        case WallLocation.LowerLeft:
            WallObject.transform.localPosition = new Vector3(0.4341624f, 0.7519927f);
            WallObject.transform.localRotation = Quaternion.Euler(0f, 0f, -120f);
            break;
        }
    }