using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Console_Games.Ascii_Showdown { class AsciiShowdown_AI { //you can have it fire a horizontal line of bullets, or fire every third step, or fire a bunch in a straight line //give it shooting patterns that it can cycle through based on situation List lastDirection = new List(); //0 left, 1 right List lastMode = new List(); //last movetype stored in last index Random rnd = new Random(); int type = 0; int iterationsOfType = 0; bool lineOfSight = true; int lastKnownPos = 0; public int cX { get; set; } public int cY { get; set; } public char[,] moveCPU(char[,] grid, int width, int uX, int uY, bool boost) { if (grid[uX, uY - 2] == '█') { //checks if user is hiding uX = lastKnownPos; lineOfSight = false; } else { lineOfSight = true; } type = getAItype(grid, width, uX, uY, boost); if (type == 0) { return grid; } else if (type == 1) { //defensive, retreat and shoot every 8th if (iterationsOfType % 8 == 0) { grid[cX, cY + 1] = '▼'; } if (iterationsOfType % 4 == 0) { if (cX < uX) { grid = moveRight(grid, width); } else { grid = moveLeft(grid, width); } } } else if (type == 2) { //aggressive } else if (type == 3) { //try to break walls } else if (type == 4) { //try to block off player } else if (type == 5) { //retreat and not shoot if (iterationsOfType % 2 == 0) { if (cX < 3) { grid = moveRight(grid, width); } else if (cX > width - 4) { grid = moveLeft(grid, width); } else if (cX > uX) { grid = moveRight(grid, width); } else { grid = moveLeft(grid, width); } } } else if (type == 6) { //blanket shot } iterationsOfType++; return grid; } private int getAItype(char[,] grid, int width, int uX, int uY, bool boost) { if (lastMode.Count > 1 && lastMode[lastMode.Count - 1] != lastMode[lastMode.Count - 2]) { iterationsOfType = 0; } if (!lineOfSight) { wonder(grid, width); lastMode.Add(0); //wander return 0; } if (boost) { lastMode.Add(5); //retreat and not shoot return 5; } lastMode.Add(1); return 1; } private char[,] wonder(char[,] grid, int width) { if (iterationsOfType % 4 == 0) { int shoot = rnd.Next(1, 5); int move = rnd.Next(0, 2); if (shoot == 1) { grid[cX, cY + 1] = '▼'; } if (move == 1) { grid = moveLeft(grid, width); } else { grid = moveRight(grid, width); } } iterationsOfType++; return grid; } private char[,] moveLeft(char[,] grid, int width) { if (cX - 1 > 0) { lastDirection.Add(0); grid[cX, cY] = ' '; cX--; grid[cX, cY] = '☻'; } return grid; } private char[,] moveRight(char[,] grid, int width) { if (cX + 1 < width - 1) { lastDirection.Add(1); grid[cX, cY] = ' '; cX++; grid[cX, cY] = '☻'; } return grid; } public void dispose() { lastDirection.Clear(); } /* string lastdir = ""; for (int i = 0; i < lastDirection.Count; i++) { lastdir += lastDirection[i]; } string lastmode = ""; for (int i = 0; i < lastMode.Count; i++) { lastmode += lastMode[i]; } Console.SetCursorPosition(0, 22); Console.WriteLine("Last direction: " + lastdir); Console.WriteLine("Last mode: " + lastmode); Console.WriteLine("Iterations of mode: " + iterationsOfType); */ } }