public string PixelDataGenerator() { int[,] PixelDrawXY = new int[16, 16]; Random r = new Random(); int z = r.Next(16); int d; int sd = 0; for (int y = 0; y <= 15; y++) { for (int x = 0; x <= 15; x++) { if (x == z) { PixelDrawXY[x, y] = 1; } else { PixelDrawXY[x, y] = 0; } } d = r.Next(-1, 2); if (y != 0) { if (d == 1 && sd == -1) { d = r.Next(-1, 1); } else if (d == -1 && sd == 1) { d = r.Next(2); } } sd = d; z = z + d; if (z == -1) { z++; } if (z == 16) { z--; } } PixelJSON p = new PixelJSON(); p.PixelID = HexGen(); p.PixelLabel = "-"; p.PixelDataXY = PixelDrawXY; return(JsonConvert.SerializeObject(p)); }
private void PixelConsolDrawing(string JSONdata) { PixelJSON data = JsonConvert.DeserializeObject <PixelJSON>(JSONdata); Console.WriteLine("──────────────────────────────"); Console.WriteLine(); Console.WriteLine("PixelID: " + data.PixelID); Console.WriteLine("PixelLabel: " + data.PixelLabel); Console.WriteLine(); Console.Write("┌"); for (int i = 0; i < 16; i++) { Console.Write("─"); } Console.WriteLine("┐"); for (int y = 0; y <= 15; y++) { Console.Write("│"); for (int x = 0; x <= 15; x++) { if (data.PixelDataXY[y, x] == 0) { Console.Write(" "); } else if (data.PixelDataXY[y, x] == 1) { Console.Write("█"); } } Console.WriteLine("│"); } Console.Write("└"); for (int i = 0; i < 16; i++) { Console.Write("─"); } Console.WriteLine("┘"); Console.WriteLine(); }
public PixelJSON PixelDataGeneratorJSON() { int[,] PixelDrawXY = new int[16, 16]; Random r = new Random(); int z = r.Next(16); int d; int sd = 0; for (int y = 0; y <= 15; y++) { for (int x = 0; x <= 15; x++) { if (x == z) { PixelDrawXY[x, y] = 1; } else { PixelDrawXY[x, y] = 0; } } d = r.Next(-1, 2); if (y != 0) { if (d == 1 && sd == -1) { d = r.Next(-1, 1); } else if (d == -1 && sd == 1) { d = r.Next(2); } } sd = d; z = z + d; if (z == -1) { z++; } if (z == 16) { z--; } } if (PixelDrawXY[0, 0] == 1 || PixelDrawXY[1, 1] == 1 || PixelDrawXY[1, 0] == 1 || PixelDrawXY[0, 1] == 1) { PixelDrawXY[0, 0] = 1; PixelDrawXY[1, 1] = 1; PixelDrawXY[1, 0] = 1; PixelDrawXY[0, 1] = 1; } for (int y = 0; y < 15; y = y + 2) { for (int x = 0; x < 15; x = x + 2) { if (PixelDrawXY[x, y] == 1 || PixelDrawXY[x + 1, y + 1] == 1 || PixelDrawXY[x + 1, y] == 1 || PixelDrawXY[x, y + 1] == 1) { PixelDrawXY[x, y] = 1; PixelDrawXY[x + 1, y + 1] = 1; PixelDrawXY[x + 1, y] = 1; PixelDrawXY[x, y + 1] = 1; } } } PixelJSON p = new PixelJSON(); p.PixelID = HexGen(); p.PixelLabel = "-"; p.PixelDataXY = PixelDrawXY; return(p); }
private void PixelConsolAnalyze(string JSONdata) { PixelJSON data = JsonConvert.DeserializeObject <PixelJSON>(JSONdata); Console.WriteLine("──────────────────────────────"); Console.WriteLine(); Console.WriteLine("PixelID: " + data.PixelID); Console.WriteLine("PixelLabel: " + data.PixelLabel); Console.WriteLine(); Console.Write("┌"); for (int i = 0; i < 23; i++) { if (i == 2 || i == 5 || i == 8 || i == 11 || i == 14 || i == 17 || i == 20) { Console.Write("┬"); } else if (i == 9) { Console.Write("Y"); } else if (i == 10) { Console.Write("▼"); } else if (i == 12) { Console.Write("X"); } else if (i == 13) { Console.Write("►"); } else { Console.Write("─"); } } Console.WriteLine("┐"); for (int y = 0; y <= 15; y++) { if (y == 2 || y == 4 || y == 6 || y == 8 || y == 10 || y == 12 || y == 14) { Console.WriteLine("├──┼──┼──┼──┼──┼──┼──┼──┤"); } Console.Write("│"); for (int x = 0; x <= 15; x++) { if (data.PixelDataXY[y, x] == 0) { Console.Write(" "); } else if (data.PixelDataXY[y, x] == 1) { Console.Write("█"); } if (x == 1 || x == 3 || x == 5 || x == 7 || x == 9 || x == 11 || x == 13) { Console.Write("│"); } } Console.WriteLine("│"); } Console.Write("└"); for (int i = 0; i < 23; i++) { if (i == 2 || i == 5 || i == 8 || i == 11 || i == 14 || i == 17 || i == 20) { Console.Write("┴"); } else { Console.Write("─"); } } Console.WriteLine("┘"); Console.WriteLine(); }
static void Main(string[] args) { Console.WindowHeight = 40; Console.WindowWidth = 40; Console.BufferHeight = 1000; Console.BufferWidth = 40; Program p = new Program(); PixelData pd = new PixelData(); JSONdb jdb = new JSONdb(); PixelAI ai = new PixelAI(); /// TESTING SMALLSCALE VERSION //MiniPixel mini = new MiniPixel(); //mini.run(); /////////////////////////////// /// TESTING AI FUNCTION //PixelJSON data = pd.PixelDataGeneratorJSON(); //p.PixelConsolAnalyze(JsonConvert.SerializeObject(data)); //ai.AI(data); //for (int i = 0; i < 250; i++) //{ // p.PixelConsolAnalyze(JsonConvert.SerializeObject(pd.PixelDataGeneratorJSON())); // ai.AI(data); // //Thread.Sleep(1500); //} /////////////////////////////// int answer = 0; while (answer != 9) { PixelJSON pJSON = pd.PixelDataGeneratorJSON(); p.PixelConsolAnalyze(JsonConvert.SerializeObject(pJSON)); Console.WriteLine(); Console.WriteLine("What is the line?"); Console.WriteLine("1. straight"); Console.WriteLine("2. curved"); Console.WriteLine("3. sinewave"); Console.Write("# "); answer = Int32.Parse(Console.ReadLine()); if (answer == 1) { pJSON.PixelLabel = "straight"; } if (answer == 2) { pJSON.PixelLabel = "curved"; } if (answer == 3) { pJSON.PixelLabel = "sinewave"; } if (answer == 1 || answer == 2 || answer == 3) { jdb.PutData(JsonConvert.SerializeObject(pJSON)); } } List <PixelDataJSON> PixelDataList = new List <PixelDataJSON>(); PixelDataList = jdb.GetData(); foreach (PixelDataJSON item in PixelDataList) { PixelJSON pj = JsonConvert.DeserializeObject <PixelJSON>(item.PixelJSON); Console.WriteLine(pj.PixelID); } foreach (PixelDataJSON item in PixelDataList) { p.PixelConsolAnalyze(item.PixelJSON); Console.Read(); } Console.WriteLine("Done"); Console.Read(); }
public PixelJSON ML(PixelJSON PixelData) { return(PixelData); }
public PixelJSON AI(PixelJSON PixelData) { int xyLength = 15; string[] xy = new string[xyLength]; int c = 0; for (int x = 0; x < xyLength; x = x + 2) { for (int y = 0; y < xyLength; y = y + 2) { if (PixelData.PixelDataXY[y, x] == 1) { int x1 = x; int y1 = y; if (x1 == 2) { x1 = 1; } if (x1 == 4) { x1 = 2; } if (x1 == 6) { x1 = 3; } if (x1 == 8) { x1 = 4; } if (x1 == 10) { x1 = 5; } if (x1 == 12) { x1 = 6; } if (x1 == 14) { x1 = 7; } if (y1 == 2) { y1 = 1; } if (y1 == 4) { y1 = 2; } if (y1 == 6) { y1 = 3; } if (y1 == 8) { y1 = 4; } if (y1 == 10) { y1 = 5; } if (y1 == 12) { y1 = 6; } if (y1 == 14) { y1 = 7; } xy[c] = y1 + "," + x1; c++; } } } for (int i = 0; i < xyLength; i++) { Console.WriteLine(xy[i]); } //only to see the coordinates int downCount = 0; int upCount = 0; for (int i = 1; i < xyLength; i++) { if (xy[i] == null) { break; } string[] xyFirst = xy[i - 1].Split(','); string[] xySecond = xy[i].Split(','); if (int.Parse(xyFirst[0]) < int.Parse(xySecond[0])) { downCount++; } if (int.Parse(xyFirst[0]) > int.Parse(xySecond[0])) { upCount++; } } if ((upCount == 0 || downCount == 0) || (downCount == 0 && upCount == 0)) { Console.WriteLine("S"); } return(PixelData); }