/* * Print Game Board: */ private static void PrintSolution(IntVar[,] board, int[] frameSums) { for (int i = 0; i < 9; i++) { Console.Write(" "); Console.Write(frameSums[i].ToString("D2")); } Console.WriteLine(); for (int i = 0; i < board.GetLength(0); i++) { Console.Write(frameSums[1 * 9 + i].ToString("D2")); for (int j = 0; j < board.GetLength(1); j++) { Console.Write("[{0}] ", board[i, j].Value()); } Console.Write(frameSums[2 * 9 + i].ToString("D2")); Console.WriteLine(); } for (int i = 3 * 9; i < 3 * 9 + 9; i++) { Console.Write(" "); Console.Write(frameSums[i].ToString("D2")); } }
/* * Print Game Board: */ private static void PrintSolution(IntVar[,] board, String[] rows, String[] cols) { if (rows.GetLength(0) != board.GetLength(0) || cols.GetLength(0) != board.GetLength(1)) { throw new ArgumentException("Dimensions do not match !"); } Console.Write("".PadRight(rows[0].Length + 2, ' ')); for (int j = 0; j < board.GetLength(1); j++) { Console.Write("[{0}] ", cols[j]); } Console.WriteLine(); for (int i = 0; i < board.GetLength(0); i++) { Console.Write("{0}: ", rows[i]); for (int j = 0; j < board.GetLength(1); j++) { Console.Write("[{0}] ", board[i, j].Value()); } Console.WriteLine(); } }
private static void PrintSolution(IntVar[,] magicSquare) { for (int i = 0; i < magicSquare.GetLength(0); i++) { for (int j = 0; j < magicSquare.GetLength(1); j++) { Console.Write("[{00}]", magicSquare[i, j].Value()); } Console.Write("\n"); } }
/* * Print Game Board: */ private static void PrintSolution(IntVar[,] board) { for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { Console.Write("[{0}] ", board[i, j].Value()); } Console.WriteLine(); } }
private static void PrintSolution(IntVar[,] binoxxo) { for (int i = 0; i < binoxxo.GetLength(0); i++) { for (int j = 0; j < binoxxo.GetLength(1); j++) { String value = (binoxxo[i, j].Value() == 0 ? "O" : "X"); Console.Write("[{0}]", value); } Console.Write("\n"); } }
// Matrix API public static IntVar[] Flatten(this IntVar[,] vars) { int rows = vars.GetLength(0); int cols = vars.GetLength(1); IntVar[] flat = new IntVar[cols * rows]; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { flat[i * cols + j] = vars[i, j]; } } return(flat); }