public Connect4IA() : base() { //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: this.grid = new int[GRID_SIZE][GRID_SIZE]; this.grid = RectangularArrays.RectangularIntArray(GRID_SIZE, GRID_SIZE); NewGame(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @RepeatedTest(2) void stressTest() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void StressTest() { //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: int[][] data = new int[10][10]; int[][] data = RectangularArrays.RectangularIntArray(10, 10); AtomicBoolean stop = new AtomicBoolean(); AtomicInteger writerId = new AtomicInteger();
private static nPuzzle readProblemFile(string fileName) // this allow only one puzzle to be specified in a problem file { try { //create file reading objects StreamReader reader = new StreamReader(fileName); StreamReader puzzle = new StreamReader(reader); nPuzzle result; string puzzleDimension = puzzle.ReadLine(); //split the string by letter "x" string[] bothDimensions = puzzleDimension.Split("x", true); //work out the "physical" size of the puzzle //here we only deal with NxN puzzles, so the puzzle size is taken to be the first number int puzzleSize = int.Parse(bothDimensions[0]); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: int[][] startPuzzleGrid = new int[puzzleSize][puzzleSize]; int[][] startPuzzleGrid = RectangularArrays.RectangularIntArray(puzzleSize, puzzleSize); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: int[][] goalPuzzleGrid = new int[puzzleSize][puzzleSize]; int[][] goalPuzzleGrid = RectangularArrays.RectangularIntArray(puzzleSize, puzzleSize); //fill in the start state string startStateString = puzzle.ReadLine(); startPuzzleGrid = ParseStateString(startStateString, startPuzzleGrid, puzzleSize); //fill in the end state string goalStateString = puzzle.ReadLine(); goalPuzzleGrid = ParseStateString(goalStateString, goalPuzzleGrid, puzzleSize); //create the nPuzzle object... result = new nPuzzle(startPuzzleGrid, goalPuzzleGrid); puzzle.Close(); return(result); } catch (FileNotFoundException) { //The file didn't exist, show an error Console.WriteLine("Error: File \"" + fileName + "\" not found."); Console.WriteLine("Please check the path to the file."); Environment.Exit(1); } catch (IOException) { //There was an IO error, show and error message Console.WriteLine("Error in reading \"" + fileName + "\". Try closing it and programs that may be accessing it."); Console.WriteLine("If you're accessing this file over a network, try making a local copy."); Environment.Exit(1); } //this code should be unreachable. This statement is simply to satisfy Eclipse. return(null); }
public virtual int[][] List() { int[][] list = RectangularArrays.RectangularIntArray(productMap.Values.Count, 2); int i = 0; foreach (int code in productMap.Keys) { list[i][0] = code; list[i][1] = productMap[code].Amount(); i++; } return(list); }
private int[][] cloneArray(int[][] cloneMe) { //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: int[][] result = new int[cloneMe.Length][cloneMe[0].Length]; int[][] result = RectangularArrays.RectangularIntArray(cloneMe.Length, cloneMe[0].Length); for (int i = 0; i < cloneMe.Length; i++) { for (int j = 0; j < cloneMe[i].Length; j++) { result[i][j] = cloneMe[i][j]; } } return(result); }
public virtual int[][] List() { client.Println(FrameType.LIST.ToString()); int[][] result = new int[0][2]; int lines = client.ReadInt(); result = RectangularArrays.RectangularIntArray(lines, 2); for (int i = 0; i < lines; i++) { result[i][0] = client.ReadInt(); result[i][1] = client.ReadInt(); } return(result); }
//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to C#: // import static helpers.Printer.*; /// <summary> /// Given an image represented by an NxN matrix, where each pixel in /// the image is 4 bytes, write a method to rotate the image by 90 /// degrees. Can you do this in place? /// </summary> // With extra space. internal static int[][] rotate(int[][] matrix) { int n = matrix.Length; //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: int[][] ret = new int[n][n]; int[][] ret = RectangularArrays.RectangularIntArray(n, n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { ret[i][j] = matrix[n - 1 - j][i]; } } return(ret); }
public static int[][] listMinuteChunks(int numberOfChunks) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[][] minuteChunks = new int[numberOfChunks][2]; //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: int[][] minuteChunks = new int[numberOfChunks][2]; int[][] minuteChunks = RectangularArrays.RectangularIntArray(numberOfChunks, 2); int chunkLength = 60 / numberOfChunks; for (int i = 0; i < numberOfChunks; i++) { minuteChunks[i][0] = chunkLength * i; minuteChunks[i][1] = chunkLength * (i + 1) - 1; } minuteChunks[numberOfChunks - 1][1] = 59; return(minuteChunks); }
public static void Main(string[] args) { //Scanner input = new Scanner(System.in); var input = Console.ReadLine().Split(); int n = int.Parse(input[0]), m = int.Parse(input[1]); int[][] G = RectangularArrays.RectangularIntArray(n, n); for (int i = 0; i < m; i++) { input = Console.ReadLine().Split(); int a = int.Parse(input[0]), b = int.Parse(input[1]); G[a][b] = i + 1; G[b][a] = i + 1; } if ((m & 1) == 1) { Console.WriteLine("impossible"); } else { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { G[i][j]--; } } int[] partner = new int[m]; for (int i = 0; i < m; i++) { partner[i] = -1; } pairUp(partner, G); for (int i = 0; i < m; i++) { if (i > partner[i]) { Console.WriteLine(i + " " + partner[i]); } } } }
internal virtual void initpic(int w, int h) { this.picture = RectangularArrays.RectangularIntArray(h, w); }
//Function to add item into warehouse public static void addItem(int length, int width, int height) { //The cordinates of the corner of the best fit int[] bestFit = { -1, -1, -1 }; //The best surface area fit = how much wall/other package can the new touch? int bestSAFit = -1; //For rotation, store the order of the length, width, and height int[] bestOrientation = { -1, -1, -1 }; //Create the rotations using the length, width, and height int[][] orientations = RectangularArrays.RectangularIntArray(6, 3); orientations[0][0] = length; orientations[0][1] = width; orientations[0][2] = height; orientations[1][0] = length; orientations[1][1] = height; orientations[1][2] = width; orientations[2][0] = width; orientations[2][1] = length; orientations[2][2] = height; orientations[3][0] = width; orientations[3][1] = height; orientations[3][2] = length; orientations[4][0] = height; orientations[4][1] = width; orientations[4][2] = length; orientations[5][0] = height; orientations[5][1] = length; orientations[5][2] = width; //Checks if any of the slots are open for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 5; k++) { if (warehouse[i][j][k] == true) { //std::cout << "Checking if item fits..." << std::endl; //for rotation, check with different orders of length, width, and height //would need to keep track of rotation, somehow //Goes through each orientation for (int o = 0; o < 6; o++) { bool fits = checkForSpace(orientations[o][0], orientations[o][1], orientations[o][2], i, j, k); if (fits == true) { //check neighboring spaces for heuristic int newSA = checkSAHeuristic(orientations[o][0], orientations[o][1], orientations[o][2], i, j, k); //Updates if a new best surface area fit is found if (newSA > bestSAFit) { Console.Write("New bestSAFit"); Console.Write("\n"); bestFit[0] = i; bestFit[1] = j; bestFit[2] = k; bestSAFit = newSA; bestOrientation[0] = orientations[o][0]; bestOrientation[1] = orientations[o][1]; bestOrientation[2] = orientations[o][2]; } } } } } } } //choose best fit, fill spaces if (bestFit[0] != -1 && bestFit[1] != -1 && bestFit[2] != -1) { fillSpaces(bestOrientation[0], bestOrientation[1], bestOrientation[2], bestFit[0], bestFit[1], bestFit[2]); } else { Console.Write("The new item does not fit"); Console.Write("\n"); } Console.Write("best sa fit "); Console.Write(bestSAFit); Console.Write("\n"); //Add item dimensions (in the rotation the item was places), coordinate, and name to list. return; }
public void Writemasks(String inputfile, String outputfile, int choice) { int i3, i2, i1, n, m, j, k; imagehandler img = new imagehandler(); img.loadbitmap(inputfile, 0); byte[][] f = img.returnrawpixels(); int width = (f[0]).Length; int height = f.Length; int[][] newframe = RectangularArrays.RectangularIntArray(height, width); for (int i = 0; i < height; i++) { for (int i4 = 0; i4 < width; i4++) { newframe[i][i4] = f[i][i4] & 0xFF; } } int mask = newframe[height - 1][0]; switch (choice) { case 1: for (i3 = 0; i3 < height; i3++) { for (int i4 = 0; i4 < width; i4++) { if (newframe[i3][i4] == mask) { newframe[i3][i4] = this.outputmask; } else { newframe[i3][i4] = 255; } } } break; case 2: for (i3 = 0; i3 < height; i3++) { int i4; for (i4 = 0; i4 < width - 1; i4++) { if (newframe[i3][i4] == mask && newframe[i3][i4 + 1] != mask && i4 + 1 != width - 1) { newframe[i3][i4] = -2; } } for (i4 = width - 1; i4 > 0; i4--) { if (newframe[i3][i4] == mask && newframe[i3][i4 - 1] != mask && i4 + 1 != width - 1) { newframe[i3][i4] = -2; } } } for (i2 = 0; i2 < width; i2++) { int i4; for (i4 = 0; i4 <= height - 2; i4++) { if (newframe[i4][i2] == mask && newframe[i4 + 1][i2] != mask && newframe[i4 + 1][i2] != -2) { newframe[i4][i2] = -2; } } for (i4 = height - 1; i4 > 0; i4--) { if (newframe[i4][i2] == mask && newframe[i4 - 1][i2] != mask && newframe[i4 - 1][i2] != -2) { newframe[i4][i2] = -2; } } } for (i1 = 0; i1 < height; i1++) { for (int i4 = 0; i4 < width; i4++) { if (newframe[i1][i4] != -2) { newframe[i1][i4] = this.outputmask; } } } break; case 3: for (i1 = 0; i1 < height; i1++) { for (int i4 = 0; i4 < width; i4++) { if (newframe[i1][i4] < 16 || newframe[i1][i4] > 23) { newframe[i1][i4] = this.outputmask; } } } break; case 4: for (i1 = 0; i1 < height; i1++) { for (int i4 = 0; i4 < width; i4++) { if (newframe[i1][i4] == 131) { newframe[i1][i4] = 131; } else { newframe[i1][i4] = this.outputmask; } } } break; case 5: for (i1 = 0; i1 < height; i1++) { int i4; for (i4 = 0; i4 < width - 1; i4++) { if (newframe[i1][i4] == mask && newframe[i1][i4 + 1] != mask && i4 + 1 != width - 1) { newframe[i1][i4] = -2; } } for (i4 = width - 1; i4 > 0; i4--) { if (newframe[i1][i4] == mask && newframe[i1][i4 - 1] != mask && i4 + 1 != width - 1) { newframe[i1][i4] = -2; } } } for (n = 0; n < width; n++) { int i4; for (i4 = 0; i4 <= height - 2; i4++) { if (newframe[i4][n] == mask && newframe[i4 + 1][n] != mask && newframe[i4 + 1][n] != -2) { newframe[i4][n] = -2; } } for (i4 = height - 2; i4 > 0; i4--) { if (newframe[i4][n] == mask && newframe[i4 - 1][n] != mask && newframe[i4 - 1][n] != -2) { newframe[i4][n] = -2; } } } for (m = 0; m < height; m++) { int i4; for (i4 = 0; i4 < width - 1; i4++) { if (newframe[m][i4] == mask && newframe[m][i4 + 1] != mask && i4 + 1 != width - 1) { newframe[m][i4] = -3; } } for (i4 = width - 1; i4 > 0; i4--) { if (newframe[m][i4] == mask && newframe[m][i4 - 1] != mask && i4 + 1 != width - 1) { newframe[m][i4] = -3; } } } for (j = 0; j < width; j++) { int i4; for (i4 = 0; i4 <= height - 2; i4++) { if (newframe[i4][j] == mask && newframe[i4 + 1][j] != mask && newframe[i4 + 1][j] != -3) { newframe[i4][j] = -3; } } for (i4 = height - 2; i4 > 0; i4--) { if (newframe[i4][j] == mask && newframe[i4 - 1][j] != mask && newframe[i4 - 1][j] != -3) { newframe[i4][j] = -3; } } } for (k = 0; k < height; k++) { for (int i4 = 0; i4 < width; i4++) { if (newframe[k][i4] != -3) { newframe[k][i4] = this.outputmask; } } } break; default: Console.WriteLine("Unrecognized command"); break; } Aokbitmap b = new Aokbitmap(this.outputmask, this.outline1, this.outline2, this.shadow); b.Write(outputfile, newframe, f[0].Length, f.Length); }
public virtual void getframe(int num, string path, string filename, bool msk, bool o1, bool o2, bool pl, bool sh) { imagehandler img = new imagehandler(); img.loadbitmap(path.ToString() + filename, 0); byte[][] f = img.returnrawpixels(); int width = (f[0]).Length; int height = f.Length; int[][] newframe = RectangularArrays.RectangularIntArray(height, width); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { newframe[i][j] = f[i][j] & 0xFF; } } if (msk) { string str = this.maskfile; if (File.Exists(str)) { img.loadbitmap(str, 0); } f = img.returnrawpixels(); //replace black pixel by transparent pixel for (int j = 0; j < height; j++) { for (int k = 0; k < width; k++) { int pixel = f[j][k] & 0xFF; if (pixel == 0) { newframe[j][k] = -1; } //var test = newframe[1584][32]; } } } if (o1) { string str = path.ToString() + "U" + filename.Substring(1); img.loadbitmap(str, 0); f = img.returnrawpixels(); for (int j = 0; j < height; j++) { for (int k = 0; k < width; k++) { int pixel = f[j][k] & 0xFF; if (pixel != 0) { newframe[j][k] = -2; } } } } if (o2) { string str = path.ToString() + "O" + filename.Substring(1); img.loadbitmap(str, 0); f = img.returnrawpixels(); for (int j = 0; j < height; j++) { for (int k = 0; k < width; k++) { int pixel = f[j][k] & 0xFF; if (pixel != 0) { newframe[j][k] = -3; } } } } if (pl) { string str = path.ToString() + "P" + filename.Substring(1); img.loadbitmap(str, 0); f = img.returnrawpixels(); for (int j = 0; j < height; j++) { for (int k = 0; k < width; k++) { int pixel = f[j][k] & 0xFF; if (pixel != 0) { newframe[j][k] = pixel; } } } this.plcolorused = true; } if (sh) { string str = path.ToString() + "H" + filename.Substring(1); img.loadbitmap(str, 0); f = img.returnrawpixels(); Console.WriteLine("Entering shadow stuff"); for (int j = 0; j < height; j++) { for (int k = 0; k < width; k++) { int pixel = f[j][k] & 0xFF; if (pixel != 0) { newframe[j][k] = -4; } } } } if (this.frames == null) { this.frames = new frame[num + 1]; } this.frames[num] = new frame(); (this.frames[num]).width = width; (this.frames[num]).height = height; (this.frames[num]).picture = newframe; if (this.cvtused) { this.frames[num].convertcvt(this.mapping); } }
public static int findMaxPoints(int[][] A) { // To store points collected by Person P1 // when he/she begins journy from start and // from end. int[][] P1S = RectangularArrays.RectangularIntArray(4 + 1, 4 + 1); int[][] P1E = RectangularArrays.RectangularIntArray(4 + 1, 4 + 1); // To store points collected by Person P2 // when he/she begins journey from start and // from end. int[][] P2S = RectangularArrays.RectangularIntArray(4 + 1, 4 + 1); int[][] P2E = RectangularArrays.RectangularIntArray(4 + 1, 4 + 1); // Table for P1's journey from // start to meeting cell for (int i = 1; i <= DefineConstants.N; i++) { for (int j = 1; j <= DefineConstants.M; j++) { P1S[i][j] = Math.Max(P1S[i - 1][j], P1S[i][j - 1]) + A[i - 1][j - 1]; } } // Table for P1's journey from // end to meet cell for (int i = DefineConstants.N; i >= 1; i--) { for (int j = DefineConstants.M; j >= 1; j--) { P1E[i][j] = Math.Max(P1E[i + 1][j], P1E[i][j + 1]) + A[i - 1][j - 1]; } } // Table for P2's journey from start to meeting cell for (int i = DefineConstants.N; i >= 1; i--) { for (int j = 1; j <= DefineConstants.M; j++) { P2S[i][j] = Math.Max(P2S[i + 1][j], P2S[i][j - 1]) + A[i - 1][j - 1]; } } // Table for P2's journey from end to meeting cell for (int i = 1; i <= DefineConstants.N; i++) { for (int j = DefineConstants.M; j >= 1; j--) { P2E[i][j] = Math.Max(P2E[i - 1][j], P2E[i][j + 1]) + A[i - 1][j - 1]; } } // Now iterate over all meeting positions (i,j) int ans = 0; for (int i = 2; i < DefineConstants.N; i++) { for (int j = 2; j < DefineConstants.M; j++) { int op1 = P1S[i][j - 1] + P1E[i][j + 1] + P2S[i + 1][j] + P2E[i - 1][j]; int op2 = P1S[i - 1][j] + P1E[i + 1][j] + P2S[i][j - 1] + P2E[i][j + 1]; ans = Math.Max(ans, Math.Max(op1, op2)); } } return(ans); }