public RepairDroidCoordinate(int x, int y, char item, RepairDroidMap map) { this.x = x; this.y = y; this.item = item; this.map = map; }
public RepairDroid(string[] instructionsInput) { // The computer's available memory should be much larger than the initial program. Memory beyond the initial program starts with // the value 0 and can be read or written like any other memory. (It is invalid to try to access memory at a negative address, though.) this.instructions = new string[10000]; for (int index = 0; index < instructions.Length; index++) { instructions.SetValue("0", index); } for (int index = 0; index < instructionsInput.Length; index++) { instructions.SetValue(instructionsInput[index], index); } // Initialize our map. this.map = new RepairDroidMap(); RepairDroidCoordinate currentLocation = this.map.CreateCoordinate(0, 0, 'D');; this.map.start = currentLocation; }
//public char DrawThisTile(char tileId) { // // 0 is an empty tile.No game object appears in this tile. // // 1 is a wall tile.Walls are indestructible barriers. // // 2 is a block tile.Blocks can be broken by the ball. // // 3 is a horizontal paddle tile. The paddle is indestructible. // // 4 is a ball tile.The ball moves diagonally and bounces off objects. // switch (tileId) { // case '0': // return ' '; // case '1': // return 'W'; // case '2': // return 'B'; // case '3': // return 'P'; // case '4': // return 'O'; // default: // return '?'; // } //} ////public void Print() { // this.CalculateScreenSize() //} //public void PrintScreen(Dictionary<string, string> robotCommands) { // this.CalculateScreenSize(robotCommands); // Console.WriteLine("\n"); // Dictionary<string, string> robotCommandsFormatted = new Dictionary<string, string>(); // foreach (string key in robotCommands.Keys) { // string[] coordinates = key.Split(','); // int x = Convert.ToInt32(coordinates[0]) + (-(this.minimumX)); // int y = Convert.ToInt32(coordinates[1]) + (-(this.minimumY)); // string newKey = x.ToString() + "," + y.ToString(); // robotCommandsFormatted[newKey] = robotCommands[key]; // } // int realMaximumX = this.maximumX + (-(this.minimumX)); // int realMaximumY = this.maximumY + (-(this.minimumY)); // // Console.WriteLine("SCORE: " + this.CurrentScore); // char[][] rows = new char[(realMaximumY)][]; // for (int row=0; row<realMaximumY; row++) { // char[] rowData = new char[realMaximumX]; // rows[row] = rowData; // } // foreach (string key in robotCommandsFormatted.Keys) { // string[] coordinates = key.Split(','); // int x = Convert.ToInt32(coordinates[0]); // int y = Convert.ToInt32(coordinates[1]); // string rawChar = (string)robotCommandsFormatted[key]; // char actualChar = rawChar.ToCharArray()[0]; // rows[y][x] = actualChar; // this.DrawThisTile(actualChar); // //// Where is the paddle and ball? // //if (actualChar == '3') { // // this.currentColPaddle = x; // //} // //else if (actualChar == '4') { // // this.currentColBall = x; // //} // } // foreach (char[] row in rows) { // string rowString = ""; // foreach (char currentChar in row) { // rowString += currentChar; // } // Console.WriteLine(rowString); // } // return; //} //private void ConstructCoordinates(int xPos, int yPos, out int xPosNew, out int yPosNew, int direction) { // switch (direction) { // case NORTH: // xPosNew = xPos; // yPosNew = yPos - 1; // break; // case SOUTH: // xPosNew = xPos; // yPosNew = yPos + 1; // break; // case WEST: // xPosNew = xPos - 1; // yPosNew = yPos; // break; // case EAST: // xPosNew = xPos + 1; // yPosNew = yPos; // break; // default: // xPosNew = xPos; // yPosNew = yPos; // Console.WriteLine("ERROR!"); // break; // } //} public Dictionary <string, string> FindTheOxygenSystem() { //int xPos = 0; //int yPos = 0; //int lastDirection = -1; this.input = DEFAULT_DIRECTION.ToString(); bool keepGoing = true; //bool calculatedScreenSize = false; this.currentlyRunning = true; RepairDroidMap map = new RepairDroidMap(); RepairDroidCoordinate currentLocation = map.CreateCoordinate(0, 0, 'D');; map.start = currentLocation; while (keepGoing) { int output = Convert.ToInt32(this.ContinueProgram()); Console.WriteLine(""); Console.WriteLine("Tried moving " + this.directionFriendly[System.Convert.ToInt32(this.input)] + ", got code " + this.returnCodeFriendly[output]); // What is the target of this attempted move? RepairDroidCoordinate targetLocation = currentLocation.FindNeighbor(Convert.ToInt32(this.input), true); switch (output) { case FOUND_OXYGEN_SYSTEM: // Mark the spot we are at now with a "." on the map. currentLocation.item = '.'; // Move our current position. currentLocation = targetLocation; // currentLocation.FindNeighbor(Convert.ToInt32(this.input), true); // Mark that position as a "O" for Oxygen. currentLocation.item = 'O'; // Let's cache this one. map.end = currentLocation; // Let's get out of here, yo! Console.WriteLine("FOUND IT!"); //keepGoing = false; break; case FAILURE_WALL: // Mark the wall we just hit as a wall in our map. //RepairDroidCoordinate neighbor = currentLocation.FindNeighbor(Convert.ToInt32(this.input), true); targetLocation.item = '#'; // Move to the next direction we want to try, amoeba-like, until we hit something interesting. // this.input = map.PickDirection(currentLocation).ToString(); break; case SUCCESSFUL_MOVE: // Mark the spot we just moved from as a "." on the map. currentLocation.item = '.'; // Move our current position. currentLocation = targetLocation; // currentLocation.FindNeighbor(Convert.ToInt32(this.input), true); // Mark that position as a "D" for Droid. currentLocation.item = 'D'; break; default: Console.WriteLine("ERROR! We got some super bogus output code."); Console.WriteLine("Press any key to continue..."); System.Console.ReadKey(); break; } // Figure out what direction to go to next. this.input = map.PickDirection(currentLocation).ToString(); // Are we stuck? Let's teleport to some other spot that we haven't evaluated yet. if (this.input == "-99") { // Mark the spot we are about to move away from as a "." on the map. currentLocation.item = '.'; currentLocation = map.TeleportToBetterSpot(); if (currentLocation == null) { Console.WriteLine("DONE: We navigated everything!"); keepGoing = false; } else { currentLocation.item = 'D'; this.input = map.PickDirection(currentLocation).ToString(); } } // Print out the map so we can follow along. //map.Print(); // Keep the console window open. Console.WriteLine(""); //Console.WriteLine("Press any key to continue..."); //System.Console.ReadKey(); } return(null); // robotCommands; }