Beispiel #1
0
        public static PipeSystem CreateV3e1(int psIndex)
        {
            Log.Debug("Creating pipe system 'V3e1'.");

            Inlet  v00 = new Inlet(0, -1);
            Valve  v01 = new Valve(1, 0, 24, -130);
            Fan    v02 = new Fan(2, 0, 24, -158);
            Valve  v04 = new Valve(4, 0, 24, -214);
            Outlet v05 = new Outlet(5, -1);

            Vertex[] vertices = { v00, v01, v02, v04, v05 };

            Vertex[][] edges =
            {
                new Vertex[] { v00, v01 },
                new Vertex[] { v01, v02 },
                new Vertex[] { v02, v04 },
                new Vertex[] { v04, v05 },
                new Vertex[] { v05 }
            };

            Valve[] openValvesAtStart = { v04 };

            PipeSystem result = new PipeSystem(psIndex, vertices, edges, openValvesAtStart);

            Debug.Assert(result.graph.VertexCount == 5, "wrong vertex count");
            Debug.Assert(result.graph.EdgeCount == 4, "wrong edge count");
            return(result);
        }
Beispiel #2
0
        public static PipeSystem CreateV3e4(int psIndex)
        {
            Log.Debug("Creating pipe system 'V3e4'.");

            Valve  v90  = new Valve(0, 1, 288, -120);
            Fan    v91  = new Fan(1, 1, 288, -144);
            Valve  v94  = new Valve(4, 4, 288, -202);
            Inlet  v100 = new Inlet(0, -1);
            Valve  v102 = new Valve(2, 1, 326, -158);
            Fan    v104 = new Fan(4, 0, 306, -222);
            Valve  v110 = new Valve(0, 2, 312, -102);
            Valve  v113 = new Valve(3, 2, 326, -204);
            Fan    v120 = new Fan(0, 2, 344, -102);
            Valve  v122 = new Valve(2, 2, 352, -176);
            Fan    v123 = new Fan(3, 2, 354, -206);
            Valve  v125 = new Valve(5, 0, 350, -244);
            Valve  v131 = new Valve(1, 4, 370, -138);
            Valve  v133 = new Valve(3, 3, 392, -206);
            Fan    v141 = new Fan(1, 2, 396, -138);
            Valve  v142 = new Valve(2, 3, 412, -156);
            Valve  v150 = new Valve(0, 3, 428, -120);
            Outlet v155 = new Outlet(5, -1);

            Vertex[] vertices = { v90, v91, v94, v100, v102, v104, v110, v113, v120, v122, v123, v125, v131, v133, v141, v142, v150, v155 };

            Vertex[][] edges =
            {
                new Vertex[] { v90,  v91,  v100 },
                new Vertex[] { v91,  v94,  v102 },
                new Vertex[] { v94,  v102, v104 },
                new Vertex[] { v100, v110 },
                new Vertex[] { v102, v113, v122 },
                new Vertex[] { v104, v113, v125 },
                new Vertex[] { v110, v120 },
                new Vertex[] { v113, v122, v123, v125},
                new Vertex[] { v120, v131, v150 },
                new Vertex[] { v122, v131 },
                new Vertex[] { v123, v133 },
                new Vertex[] { v125, v133, v142, v150, v155},
                new Vertex[] { v131, v141, v150 },
                new Vertex[] { v133, v142, v150, v155},
                new Vertex[] { v141, v142 },
                new Vertex[] { v142, v150, v155 },
                new Vertex[] { v150, v155 },
                new Vertex[] { v155 },
            };

            Valve[] openValvesAtStart = { v90, v94, v102, v122, v125, v131, v133, v142 };

            PipeSystem result = new PipeSystem(psIndex, vertices, edges, openValvesAtStart);

            Debug.Assert(result.graph.VertexCount == 18, "wrong vertex count");
            Debug.Assert(result.graph.EdgeCount == 32, "wrong edge count");
            return(result);
        }
Beispiel #3
0
        public PipesGame()
        {
            systems = new PipeSystem[] {
                PipeSystem.CreateV3e1(0),
                PipeSystem.CreateV3e2(1),
                PipeSystem.CreateV3e3(2),
                PipeSystem.CreateV3e4(3)
            };

            FanCount = ValveCount = 0;
            foreach (PipeSystem ps in systems)
            {
                FanCount   += ps.FanCount;
                ValveCount += ps.ValveCount;
            }

            Log.Info("Pipes game set up.");
        }
Beispiel #4
0
        public static PipeSystem CreateV3e3(int psIndex)
        {
            Log.Debug("Creating pipe system 'V3e3'.");

            Inlet  v50 = new Inlet(0, -1);
            Fan    v52 = new Fan(2, 2, 160, -166);
            Valve  v54 = new Valve(4, 2, 160, -194);
            Fan    v60 = new Fan(0, 0, 180, -120);
            Valve  v61 = new Valve(1, 2, 180, -146);
            Valve  v63 = new Valve(3, 1, 188, -194);
            Valve  v70 = new Valve(0, 0, 208, -120);
            Outlet v75 = new Outlet(5, -1);
            Fan    v80 = new Fan(0, 1, 235, -120);
            Valve  v81 = new Valve(1, 3, 246, -146);
            Fan    v83 = new Fan(3, 1, 246, -184);
            Valve  v84 = new Valve(4, 3, 246, -214);

            Vertex[] vertices = { v50, v52, v54, v60, v61, v63, v70, v75, v80, v81, v83, v84 };

            Vertex[][] edges =
            {
                new Vertex[] { v50, v60 },
                new Vertex[] { v52, v54, v61},
                new Vertex[] { v54, v63, v75, v84},
                new Vertex[] { v60, v70 },
                new Vertex[] { v61, v63, v81, v83},
                new Vertex[] { v63, v75, v81, v83, v84},
                new Vertex[] { v70, v80 },
                new Vertex[] { v75, v84 },
                new Vertex[] { v80, v81 },
                new Vertex[] { v81, v83 },
                new Vertex[] { v83, v84 },
                new Vertex[] { v84 },
            };

            Valve[] openValvesAtStart = { v54, v70, v81, v84 };

            PipeSystem result = new PipeSystem(psIndex, vertices, edges, openValvesAtStart);

            Debug.Assert(result.graph.VertexCount == 12, "wrong vertex count");
            Debug.Assert(result.graph.EdgeCount == 19, "wrong edge count");
            return(result);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pipes"></param>
        /// <returns>true iff the pipe system is solved</returns>
        private bool UpdatePipes(PipeSystem pipes)
        {
            // solved systems cannot be manipulated
            if (pipes.RunningFansCount >= pipes.FanCount)
            {
                return(true);
            }

            // update pipe system to get all manipulated valves (and fans with consequentially changed states)
            HashSet <Vertex> changedFansAndValves = pipes.Update(Physical);

            // notify observers about changes
            foreach (Vertex vertex in changedFansAndValves)
            {
                Log.Verbose("{0} state changed @ row={1} pos={2}", vertex.GetType(), vertex.Row, vertex.PositionInRow);
                if (vertex is Valve)
                {
                    OnValveTurned?.Invoke(this, new ValveTurnedEventArgs(pipes, (Valve)vertex));
                }
                else if (vertex is Fan)
                {
                    OnFanTriggered?.Invoke(this, new FanTriggeredEventArgs(pipes, (Fan)vertex));
                }
                else
                {
                    throw new InvalidOperationException(vertex.Type.ToString());
                }
            }

            bool systemSolved = pipes.RunningFansCount == pipes.FanCount;

            if (systemSolved)
            {
                Log.Info("Pipe system {0} now solved.", pipes.Index);
            }

            return(systemSolved);
        }
Beispiel #6
0
        public static PipeSystem CreateV3e2(int psIndex)
        {
            Log.Debug("Creating pipe system 'V3e2'.");

            Valve  v21 = new Valve(1, 1, 64, -130);
            Fan    v23 = new Fan(3, 0, 64, -158);
            Valve  v32 = new Valve(2, 0, 90, -154);
            Valve  v34 = new Valve(4, 1, 90, -214);
            Inlet  v40 = new Inlet(0, -1);
            Fan    v41 = new Fan(1, 0, 118, -112);
            Fan    v42 = new Fan(2, 1, 104, -176);
            Valve  v43 = new Valve(3, 0, 120, -196);
            Outlet v45 = new Outlet(5, -1);

            Vertex[] vertices = { v21, v23, v32, v34, v40, v41, v42, v43, v45 };

            Vertex[][] edges =
            {
                new Vertex[] { v21, v23, v32, v41 },
                new Vertex[] { v23, v34 },
                new Vertex[] { v32, v41, v42 },
                new Vertex[] { v34, v43, v45 },
                new Vertex[] { v40, v41 },
                new Vertex[] { v41 },
                new Vertex[] { v42, v43 },
                new Vertex[] { v43, v45 },
                new Vertex[] { v45 },
            };

            Valve[] openValvesAtStart = { v21, v32, v34, v43 };

            PipeSystem result = new PipeSystem(psIndex, vertices, edges, openValvesAtStart);

            Debug.Assert(result.graph.VertexCount == 9, "wrong vertex count");
            Debug.Assert(result.graph.EdgeCount == 11, "wrong edge count");
            return(result);
        }
Beispiel #7
0
 internal FanTriggeredEventArgs(PipeSystem system, Fan fan)
 {
     System = system;
     Fan    = fan;
 }
Beispiel #8
0
 internal ValveTurnedEventArgs(PipeSystem system, Valve valve)
 {
     System = system;
     Valve  = valve;
 }