示例#1
0
        public List <Point> RemoveWire(int x, int y)
        {
            LinkedList <WireTransfer> result = new LinkedList <WireTransfer>();
            WireTransfer updatedWire         = getWireTransfer(new Point(x, y));

            result.AddFirst(updatedWire);

            if (updatedWire.isPowered() || updatedWire.getTransfer() != WireCurrentTransfer.NONE)
            {
                WireTransfer[] neighbours = new WireTransfer[4];
                storeNeighbours(updatedWire, neighbours, true);
                updatedWire.setCurrent(CurrentType.OFF);
                updatedWire.setCurrentTransfer(WireCurrentTransfer.NONE);
                for (int i = 0; i < 4; i++)
                {
                    if (neighbours[i] == null)
                    {
                        continue;
                    }
                    updatePowerGrid(neighbours[i], ref result);
                }
            }
            List <Point> finalResult = new List <Point>();

            foreach (WireTransfer t in result)
            {
                if (!finalResult.Contains(t.location))
                {
                    finalResult.Add(t.location);
                }
            }
            return(finalResult);
        }
示例#2
0
        public List <Point> AddOrUpdateWire(int x, int y, CurrentType newCurrent, WireCurrentTransfer currentTransfer)
        {
            LinkedList <WireTransfer> result = new LinkedList <WireTransfer>();
            WireTransfer updatedWire         = getWireTransfer(new Point(x, y));

            if (newCurrent == CurrentType.ON)
            {
            }
            else if (newCurrent == CurrentType.SENDER)
            {
                currentTransfer = WireCurrentTransfer.DOWN | WireCurrentTransfer.LEFT | WireCurrentTransfer.RIGHT | WireCurrentTransfer.UP;
                updatedWire.setCurrentTransfer(currentTransfer);
                updatedWire.setCurrent(CurrentType.SENDER);
                updatePowerGrid(updatedWire, ref result);
            }
            else if (newCurrent == CurrentType.OFF)
            {
                WireTransfer[] neighbours = new WireTransfer[4];
                storeNeighbours(updatedWire, neighbours, true);
                updatedWire.setCurrent(CurrentType.OFF);
                updatedWire.setCurrentTransfer(currentTransfer);
                updatePowerGrid(updatedWire, ref result);
                for (int i = 0; i < 4; i++)
                {
                    if (neighbours[i] == null)
                    {
                        continue;
                    }
                    updatePowerGrid(neighbours[i], ref result);
                }
            }
            List <Point> finalResult = new List <Point>();

            foreach (WireTransfer t in result)
            {
                if (!finalResult.Contains(t.location))
                {
                    finalResult.Add(t.location);
                }
            }
            return(finalResult);
        }