fork download
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Diagnostics;
  7. public class Form1
  8. {
  9.  
  10. LogicMap Logic = new LogicMap();
  11. private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
  12. {
  13. if (e.KeyData == Keys.Space) {
  14. Console.WriteLine("------- New Step ---------");
  15. Logic.DoLogic();
  16. }
  17. }
  18.  
  19. private void Form1_Load(System.Object sender, System.EventArgs e)
  20. {
  21. Logic.AddGate(new Point(100, 130), 0, 0, 0);
  22. Logic.AddGate(new Point(160, 40), 0, 0, 4);
  23. Logic.AddGate(new Point(205, 105), 0, 3, 1);
  24. Logic.AddGate(new Point(450, 35), 0, 4, 0);
  25. Logic.AddGate(new Point(595, 135), 0, 0, 1);
  26.  
  27. Logic.AddPulse(Color.FromArgb(255, 0, 0), 1, 5);
  28. Logic.AddPulse(Color.FromArgb(255, 128, 162), 2, 7);
  29. }
  30.  
  31. private void DrawLogicMap()
  32. {
  33. Graphics g = this.CreateGraphics();
  34.  
  35.  
  36. }
  37.  
  38. public class LogicMap
  39. {
  40. public List<LogicGate> NextGates;
  41. public List<LogicGate> ActiveGates;
  42.  
  43. private List<LogicGate> Gates;
  44. public void AddGate(Point Pos, LogicType Logic, int TrueGate, int FalseGate)
  45. {
  46. Gates.Add(new LogicGate {
  47. L = Logic,
  48. NT = TrueGate,
  49. NF = FalseGate,
  50. P = new List<Pulse>(),
  51. isActive = false,
  52. id = Gates.Count,
  53. Position = Pos
  54. });
  55. Console.WriteLine("#Added Gate(" + Gates.Count - 1 + "): Logic(" + Logic + "), FalseGate(" + FalseGate + "), TrueGate(" + TrueGate + ")");
  56. }
  57.  
  58. public bool AddPulse(Color Color, int Gate, int Value)
  59. {
  60. if (Gate >= Gates.Count | Gate <= -1)
  61. return false;
  62. Gates[Gate].AddPulse(Color, ref this, ref Value);
  63. Console.WriteLine("#Added Pulse at Gate(" + Gate + ") with Value(" + Value + ")");
  64. return true;
  65. }
  66.  
  67. public LogicMap()
  68. {
  69. NextGates = new List<LogicGate>();
  70. ActiveGates = new List<LogicGate>();
  71. Gates = new List<LogicGate>();
  72. Console.WriteLine("#Created new Logic Map");
  73. }
  74.  
  75.  
  76. public bool DoLogic()
  77. {
  78. ActiveGates.Clear();
  79. //Replace and make room for new changes.
  80. ActiveGates.AddRange(NextGates);
  81. NextGates.Clear();
  82. Form1.CreateGraphics().Clear(Color.Black);
  83. foreach (object Gate_loopVariable in Gates) {
  84. Gate = Gate_loopVariable;
  85. Gate.DrawDebugBase();
  86. Gate.DebugDrawLines(this, Gates);
  87. }
  88.  
  89. foreach (LogicGate Gate in ActiveGates) {
  90. Gate.DoLogic(ref this, ref Gates);
  91. Gate.DrawDebug();
  92. }
  93.  
  94. return true;
  95. }
  96. }
  97.  
  98. public struct Pulse
  99. {
  100. public int Value;
  101. public Color Color;
  102. public object MoveTo(ref LogicMap LogMap, ref LogicGate OldGate, ref LogicGate NewGate, bool State)
  103. {
  104. OldGate.P.Remove(this);
  105.  
  106. Graphics G = Form1.CreateGraphics();
  107. Point Position = default(Point);
  108.  
  109. if (LogicGate.IsVoid(ref NewGate)) {
  110. Console.WriteLine("Stopped at Gate:" + OldGate.id);
  111.  
  112. if (State == false)
  113. Position = new Point(OldGate.Position.X + 20, OldGate.Position.Y + 10);
  114. else
  115. Position = new Point(OldGate.Position.X + 20, OldGate.Position.Y - 10);
  116. G.DrawEllipse(new Pen(this.Color), Position.X - 7, Position.Y - 7, 14, 14);
  117. return false;
  118. }
  119. NewGate.P.Add(this);
  120.  
  121. if (State == false)
  122. Position = new Point(OldGate.Position.X + 20, OldGate.Position.Y + 10);
  123. else
  124. Position = new Point(OldGate.Position.X + 20, OldGate.Position.Y - 10);
  125. G.DrawLine(new Pen(this.Color, this.Value), Position, NewGate.Position);
  126.  
  127. Console.WriteLine("Moved from to " + OldGate.id + " to Gate: " + NewGate.id);
  128. if (NewGate.isActive == false) {
  129. LogMap.NextGates.Add(NewGate);
  130. NewGate.isActive = true;
  131. }
  132. return true;
  133. }
  134. }
  135.  
  136. public struct LogicGate
  137. {
  138. public int NT;
  139. public int NF;
  140. public List<Pulse> P;
  141. public LogicType L;
  142. public bool isActive;
  143. public int id;
  144.  
  145. public Point Position;
  146. public bool AddPulse(Color Colore, ref LogicMap LogMap, ref int Value)
  147. {
  148. P.Add(new Pulse {
  149. Value = Value,
  150. Color = Colore
  151. });
  152. this.isActive = true;
  153. LogMap.NextGates.Add(this);
  154. return true;
  155. }
  156.  
  157. public static LogicGate VoidGate()
  158. {
  159. return new LogicGate {
  160. NT = -1,
  161. L = LogicType.None,
  162. NF = -1
  163. };
  164. }
  165.  
  166. public static bool IsVoid(ref LogicGate Gate)
  167. {
  168. if (Gate.NF == -1 & Gate.NT == -1 & Gate.L == LogicType.None & (Gate.P == null))
  169. return true;
  170. return false;
  171. }
  172.  
  173. public void DebugDrawLines(ref LogicMap LogMap, ref List<LogicGate> Gates)
  174. {
  175. LogicGate TrueGate = default(LogicGate);
  176. LogicGate FalseGate = default(LogicGate);
  177. Graphics g = Form1.CreateGraphics;
  178.  
  179. if ((NT >= Gates.Count | NT <= -1)) {
  180. TrueGate = LogicGate.VoidGate();
  181. Point PosTrue = new Point(Position.X + 20, Position.Y - 10);
  182. g.DrawEllipse(Pens.WhiteSmoke, PosTrue.X - 4, PosTrue.Y - 4, 8, 8);
  183. } else {
  184. TrueGate = Gates[NT];
  185. Point PosTrue = new Point(Position.X + 20, Position.Y - 10);
  186. g.DrawLine(Pens.White, PosTrue, TrueGate.Position);
  187.  
  188. }
  189. if ((NF >= Gates.Count | NF <= -1)) {
  190. Point PosFalse = new Point(Position.X + 20, Position.Y + 10);
  191. FalseGate = LogicGate.VoidGate();
  192. g.DrawEllipse(Pens.WhiteSmoke, PosFalse.X - 4, PosFalse.Y - 4, 8, 8);
  193. } else {
  194. FalseGate = Gates[NF];
  195. Point PosFalse = new Point(Position.X + 20, Position.Y + 10);
  196. g.DrawLine(Pens.White, PosFalse, FalseGate.Position);
  197.  
  198. }
  199. }
  200.  
  201.  
  202. public bool DoLogic(ref LogicMap LogMap, ref List<LogicGate> Gates)
  203. {
  204. LogicGate TrueGate = default(LogicGate);
  205. LogicGate FalseGate = default(LogicGate);
  206. this.isActive = false;
  207. if (L == LogicType.None)
  208. return false;
  209. if ((NT >= Gates.Count | NT <= -1))
  210. TrueGate = LogicGate.VoidGate();
  211. else
  212. TrueGate = Gates[NT];
  213. if ((NF >= Gates.Count | NF <= -1))
  214. FalseGate = LogicGate.VoidGate();
  215. else
  216. FalseGate = Gates[NF];
  217. return Form1.LFunc[L](LogMap, this, TrueGate, FalseGate);
  218. }
  219.  
  220. public void DrawDebug()
  221. {
  222. dynamic G = Form1.CreateGraphics();
  223. G.FillRectangle(Brushes.Red, Position.X - 20, Position.Y - 10, 40, 20);
  224. G.FillRectangle(Brushes.Green, Position.X + 18, Position.Y - 12, 4, 4);
  225. G.FillRectangle(Brushes.Blue, Position.X + 18, Position.Y + 8, 4, 4);
  226. }
  227.  
  228. public void DrawDebugBase()
  229. {
  230. dynamic G = Form1.CreateGraphics();
  231. G.FillRectangle(Brushes.Gray, Position.X - 20, Position.Y - 10, 40, 20);
  232. G.FillRectangle(Brushes.Green, Position.X + 18, Position.Y - 12, 4, 4);
  233. G.FillRectangle(Brushes.Blue, Position.X + 18, Position.Y + 8, 4, 4);
  234. G.DrawString(this.id.ToString(), Form1.Font, Brushes.Black, new Point(Position.X - 6, Position.Y - 7));
  235. }
  236. }
  237.  
  238. public enum LogicType
  239. {
  240. MoreThan = 0,
  241. LessThan = 1,
  242. MoreOrEqualTo = 2,
  243. LessOrEqualTo = 3,
  244. EqualTo = 4,
  245. NotEqualTo = 5,
  246. None = 255
  247. }
  248.  
  249. public static readonly System.Func<LogicMap, LogicGate, LogicGate, LogicGate, bool>[] LFunc = { (LogicMap LM, LogicGate L, LogicGate TL, LogicGate FL) =>
  250. {
  251. List<Pulse> TrueList = new List<Pulse>();
  252. List<Pulse> FalseList = new List<Pulse>();
  253. foreach (Pulse P1 in L.P) {
  254. int SumF = 0;
  255. int SumT = 0;
  256. foreach (Pulse P2 in L.P) {
  257. if (!(Pulse.ReferenceEquals(P1, P2))) {
  258. if (P1.Value >= P2.Value)
  259. SumT += 1;
  260. else
  261. SumF += 1;
  262. }
  263. }
  264. if (SumT >= SumF)
  265. TrueList.Add(P1);
  266. else
  267. FalseList.Add(P1);
  268. }
  269. foreach (Pulse P in TrueList) {
  270. Console.WriteLine("Pulse at Gate(" + L.id + ") Returned True");
  271. P.MoveTo(LM, L, TL, true);
  272. }
  273. foreach (Pulse P in FalseList) {
  274. Console.WriteLine("Pulse at Gate(" + L.id + ") Returned False");
  275. P.MoveTo(LM, L, FL, false);
  276. }
  277. return true;
  278.  
  279. } };
  280. public Form1()
  281. {
  282. Load += Form1_Load;
  283. KeyDown += Form1_KeyDown;
  284. }
  285.  
  286. }
  287.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(11,58): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(5,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(44,37): error CS0246: The type or namespace name `Point' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(58,38): error CS0246: The type or namespace name `Color' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(101,24): error CS0118: `Form1.Pulse.Color' is a `field' but a `type' was expected
prog.cs(145,24): error CS0246: The type or namespace name `Point' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(146,38): error CS0246: The type or namespace name `Color' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(5,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 8 error(s), 0 warnings
stdout
Standard output is empty