Exemplo n.º 1
0
        /// <summary>
        /// Switches the sides.
        /// </summary>
        /// <param name="target">The target.</param>
        public void SwitchSides(Edge target)
        {
            EdgeSide side = this.Side;

            this.Side   = target.Side;
            target.Side = side;
        }
Exemplo n.º 2
0
 public BuildRoadCommand NewBuildRoad(IPlayer player, int x, int y, EdgeSide side)
 {
     var board = scope.Resolve<IBoard>();
     var edge = board.FindEdge(x, y, side);
     if (edge == null)
         throw new ArgumentException($"No edge found for given coordinates (x: {x}, y: {y}, side: {side})");
     return new BuildRoadCommand(player, board, edge);
 }
Exemplo n.º 3
0
        public void TileWithSameXYIsAdjacent(int edgeX, int edgeY, EdgeSide side, int tileX, int tileY, bool expected)
        {
            var tile = new Mock<ITile>();
            tile.Setup(t => t.X).Returns(tileX);
            tile.Setup(t => t.Y).Returns(tileY);

            var edge = new Edge(edgeX, edgeY, side);
            bool result = edge.IsAdjacentTo(tile.Object);

            Assert.True(result == expected, $"Result: {result}, Expected: {expected}\nEdge(X: {edgeX}, Y: {edgeY}, {side}); Tile(X: {tileX}, Y: {tileY}");
        }
Exemplo n.º 4
0
    public EdgeSide getEdgeSide(EdgeSide lookedSide, EdgeSide sideOnTop, bool isFlipped)
    {
        int res = 0;

        if (!isFlipped)
        {
            res  = (int)lookedSide + (int)sideOnTop;
            res %= 4;
        }
        else
        {
            res = (int)lookedSide + 4 - (int)sideOnTop;
            res = (8 - res) % 4;
        }

        return((EdgeSide)res);
    }
        /// <summary>
        /// Reset all fields to default values in preparation for object recycling
        /// </summary>
        public void PrepareForRecycle()
        {
            PolyTyp = PolyType.Subject;
            Side    = EdgeSide.Left;

            Bot = Curr = Top = Delta = new IntPoint();

            Dx        = 0;
            WindDelta = 0;
            WindCnt   = 0;
            WindCnt2  = 0;
            OutIdx    = 0;

            Next      = Prev = null;
            PrevInAEL = PrevInSEL = null;
            NextInLML = NextInAEL = NextInSEL = null;
        }
Exemplo n.º 6
0
    public Edge getAbsoluteTopEdge(Edge match, EdgeSide side, bool isFlipped)
    {
        int res = 0;

        if (isFlipped)
        {
            res = (int)match.side + (int)side + 2;
        }
        else
        {
            res = (int)match.side + (6 - (int)side);
        }
        res %= 4;

        Edge edge = _tiles[match.tileID].edgesMatch.Find(e => e.side == (EdgeSide)res && e.flipped == isFlipped);

        if (edge == null)
        {
            Debug.LogWarning("$$$$$ Edge not found ?? in getAbsoluteTopEdge " + match.ToString() + "  || " + side.ToString());
        }

        return(edge);
    }
Exemplo n.º 7
0
        public void TestEdgeAdjacentCaseEast(int edgeX, int edgeY, int inputX, int inputY, EdgeSide inputSide, bool expected)
        {
            var input = new Mock<IEdge>();
            input.Setup(t => t.X).Returns(inputX);
            input.Setup(t => t.Y).Returns(inputY);
            input.Setup(t => t.Side).Returns(inputSide);

            var edge = new Edge(edgeX, edgeY, EdgeSide.East);
            bool result = edge.IsAdjacentTo(input.Object);

            Assert.True(result == expected, $"Result: {result}, Expected: {expected}\nEdge(X: {edgeX}, Y: {edgeY}, East); Edge(X: {inputX}, Y: {inputY}, {inputSide})");
        }
Exemplo n.º 8
0
 public Edge(string p_value, int p_id, EdgeSide p_side, bool p_flipped)
 {
     this.value = p_value; this.tileID = p_id; this.flipped = p_flipped; this.side = p_side;
 }
Exemplo n.º 9
0
 public Edge()
 {
     this.value = ""; this.tileID = -1; this.side = EdgeSide.TOP; this.flipped = false;
 }
Exemplo n.º 10
0
    public EdgeSide getOppositeEdge(EdgeSide side)
    {
        int sideNumber = System.Enum.GetValues(typeof(EdgeSide)).Length;

        return((EdgeSide)(((int)side + 2) % sideNumber));
    }
Exemplo n.º 11
0
        private static List<Color> GetEdge(Bitmap input, EdgeSide edgeSide)
        {
            int height = input.Height;
            var l = new List<Color>();
            if (edgeSide == EdgeSide.Left)
            {
                for (int i = 0; i < height; i++)
                    l.Add(input.GetPixel(0, i));

                return l;
            }

            // Calculate zero-based width
            int width = input.Width - 1;

            for (int i = 0; i < height; i++)
                l.Add(input.GetPixel(width, i));

            return l;
        }
Exemplo n.º 12
0
 public EdgeCoordinate(int x, int y, EdgeSide side)
 {
     X = x;
     Y = y;
     Side = side;
 }
Exemplo n.º 13
0
Arquivo: Edge.cs Projeto: Corne/VOC
 public Edge(int x, int y, EdgeSide side)
 {
     X = x;
     Y = y;
     Side = side;
 }
Exemplo n.º 14
0
        public void IsAdjacentTOEdgeCaseRight(int vertexX, int vertexY, int edgeX, int edgeY, EdgeSide side, bool expected)
        {
            var edge = new Mock<IEdge>();
            edge.Setup(e => e.X).Returns(edgeX);
            edge.Setup(e => e.Y).Returns(edgeY);
            edge.Setup(e => e.Side).Returns(side);

            var vertex = new Vertex(vertexX, vertexY, VertexTileSide.Right);

            bool result = vertex.IsAdjacentTo(edge.Object);

            Assert.True(result == expected, $"Result: {result}, Expected: {expected}\nVertext(X: {vertexX}, Y: {vertexY}, Right); Edge(X: {edgeX}, Y: {edgeY}, Side: {side}");

        }
Exemplo n.º 15
0
 private IEdge GetEdge(int x, int y, EdgeSide side)
 {
     return Edges.Single(e => e.X == x && e.Y == y && e.Side == side);
 }
Exemplo n.º 16
0
 public Edge(string stickerDef, int position, Sq1ImageProp properties)
 {
     Face = new EdgeFace(position, stickerDef[0], properties);
     Side = new EdgeSide(position, stickerDef[1], properties);
 }
Exemplo n.º 17
0
Arquivo: Board.cs Projeto: Corne/VOC
 public IEdge FindEdge(int x, int y, EdgeSide side)
 {
     return Edges.SingleOrDefault(e => e.X == x && e.Y == y && e.Side == side);
 }
Exemplo n.º 18
0
    void searchNeighbours(int x, int y, EdgeSide sideOnTop, int offset = 0)
    {
        if (offset > _tiles.Count + 1)
        {
            return;
        }

        if (IsDebug)
        {
            Debug.Log(Tools.writeOffset(offset) + "Pos " + x + ", " + y + "  (side on top is : " + sideOnTop.ToString() + ")");
        }

        if (!_grid.ContainsKey(new KeyValuePair <int, int>(x, y)))
        {
            Debug.LogError(Tools.writeOffset(offset) + "Problem, _grid should contain tile at " + x + "," + y);
            return;
        }

        Tile currentTile = _tiles[_grid[new KeyValuePair <int, int>(x, y)].Key.tileID];
        bool isFlip      = _grid[new KeyValuePair <int, int>(x, y)].Value;

        if (IsDebug)
        {
            Debug.Log(Tools.writeOffset(offset) + " flip ? " + isFlip.ToString());
        }

        EdgeSide currentSide = EdgeSide.TOP;
        int      i           = x;
        int      j           = y;

        //Looking for neighbour on TOP
        currentSide = EdgeSide.TOP;
        i           = x;
        j           = y + 1;
        computeNeighbour(i, j, currentSide, sideOnTop, currentTile, isFlip, offset);

        if (IsDebug)
        {
            Debug.Log(Tools.writeOffset(offset) + "(memo) Pos " + x + ", " + y + "  (side on top is : " + sideOnTop.ToString() + ")");   // memo
        }
        //Looking for neighbour on BOT
        currentSide = EdgeSide.BOT;
        i           = x;
        j           = y - 1;
        computeNeighbour(i, j, currentSide, sideOnTop, currentTile, isFlip, offset);

        if (IsDebug)
        {
            Debug.Log(Tools.writeOffset(offset) + "(memo) Pos " + x + ", " + y + "  (side on top is : " + sideOnTop.ToString() + ")");   // memo
        }
        //Looking for neighbour on LEFT
        currentSide = EdgeSide.LEFT;
        i           = x - 1;
        j           = y;
        computeNeighbour(i, j, currentSide, sideOnTop, currentTile, isFlip, offset);

        if (IsDebug)
        {
            Debug.Log(Tools.writeOffset(offset) + "(memo) Pos " + x + ", " + y + "  (side on top is : " + sideOnTop.ToString() + ")");   // memo
        }
        //Looking for neighbour on RIGHT
        currentSide = EdgeSide.RIGHT;
        i           = x + 1;
        j           = y;
        computeNeighbour(i, j, currentSide, sideOnTop, currentTile, isFlip, offset);
    }
Exemplo n.º 19
0
    void computeNeighbour(int i, int j, EdgeSide currentSide, EdgeSide sideOnTop, Tile currentTile, bool isFlip, int offset = 0)
    {
        if (!_grid.ContainsKey(new KeyValuePair <int, int>(i, j)))
        {
            Debug.Log(Tools.writeOffset(offset) + "Computing " + currentSide);

            EdgeSide EdgeSide = getEdgeSide(currentSide, sideOnTop, isFlip);
            Edge     edge     = currentTile.edgesMatch.Find(e => e.flipped == isFlip && e.side == EdgeSide);

            if (IsDebug)
            {
                Debug.Log(Tools.writeOffset(offset) + "\t" + currentSide + " edge is " + edge.ToString());
            }

            Edge matchingEdge = _matchings.Find(e => e.Key == edge).Value;
            if (matchingEdge != null)
            {
                if (IsDebug)
                {
                    Debug.Log(Tools.writeOffset(offset) + "\t\tFound matching edge for " + currentSide + " : " + matchingEdge.ToString());
                }

                bool flip = (edge.flipped != matchingEdge.flipped) ? isFlip : !isFlip;


                Edge topMatchingEdge = getAbsoluteTopEdge(matchingEdge, currentSide, flip);
                if (IsDebug)
                {
                    Debug.Log(Tools.writeOffset(offset) + "\t -> topMatchingEdge is  :" + topMatchingEdge.ToString());
                }

                _grid.Add(new KeyValuePair <int, int>(i, j), new KeyValuePair <Edge, bool>(topMatchingEdge, flip));

                if (i < xBounds.x)
                {
                    xBounds = new Vector2(i, xBounds.y);
                }
                if (i > xBounds.y)
                {
                    xBounds = new Vector2(xBounds.x, i);
                }

                if (j < yBounds.x)
                {
                    yBounds = new Vector2(j, yBounds.y);
                }
                if (j > yBounds.y)
                {
                    yBounds = new Vector2(yBounds.x, j);
                }

                Debug.Log(Tools.writeOffset(offset) + "\t bounds are " + xBounds.ToString() + " && " + yBounds.ToString());

                searchNeighbours(i, j, topMatchingEdge.side, offset + 1);
            }
            else if (IsDebug)
            {
                Debug.Log(Tools.writeOffset(offset) + "\t\tNo match found, we're on edge of puzzle");
            }
        }
        else if (IsDebug)
        {
            Debug.Log(Tools.writeOffset(offset) + currentSide + " is already in grid, skip ! ");
        }
    }