public static int nonIntelligent(int a, int b) { int numOfMoves = 1; int[,] nonIntelliBoard = new int[8, 8]; //Making a game board of 8x8 of int Knight nonIntelliKnight = new Knight(a, b); //change the parameters of the intelligent method and non intelli so that theyit will go as the user said nonIntelliBoard[nonIntelliKnight.a, nonIntelliKnight.b] = numOfMoves; int move = 0; do { Choices choice = new Choices(); string[] knightMoves = choice.goodMovesNonIntelli(choice.convertListToString(nonIntelliKnight.a, nonIntelliKnight.b), nonIntelliBoard); move = knightMoves.Length; if (knightMoves[0] == "") { move = 0; break; } if (move == 1) { int first = (int)Char.GetNumericValue(knightMoves[0][0]); int second = (int)Char.GetNumericValue(knightMoves[0][1]); nonIntelliKnight.a = first; nonIntelliKnight.b = second; numOfMoves++; nonIntelliBoard[nonIntelliKnight.a, nonIntelliKnight.b] = numOfMoves; } else { Random rnd = new Random(); int random = rnd.Next(0, knightMoves.Length); //random number is generated Choices cRan = new Choices(); while (cRan.randomers == random) { random = rnd.Next(0, knightMoves.Length); } cRan.randomers = random; int first = (int)Char.GetNumericValue(knightMoves[random][0]); int second = (int)Char.GetNumericValue(knightMoves[random][1]); nonIntelliKnight.a = first; nonIntelliKnight.b = second; numOfMoves++; nonIntelliBoard[nonIntelliKnight.a, nonIntelliKnight.b] = numOfMoves; } } while (move > 0); // Console.WriteLine(numOfMoves + "these are the moves"); saver += "\n"; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { // Console.Write("{0:D2} ", nonIntelliBoard[i, j]); if (nonIntelliBoard[i, j].ToString().Length == 1) { saver += string.Format(" {0} ", nonIntelliBoard[i, j]); } else { saver += string.Format(" {0} ", nonIntelliBoard[i, j]); } } // Console.WriteLine(""); saver += "\n"; } saver += "\n"; saver += "\n"; return(numOfMoves); }
public int intelligent(int a, int b) { int numOfMoves = 1; int[,] intelliBoard = { { -2, -3, -4, -4, -4, -4, -3, -2 }, { -3, -4, -6, -6, -6, -6, -4, -3 }, { -4, -6, -8, -8, -8, -8, -6, -4 }, { -4, -6, -8, -8, -8, -8, -6, -4 }, { -4, -6, -8, -8, -8, -8, -6, -4 }, { -4, -6, -8, -8, -8, -8, -6, -4 }, { -3, -4, -6, -6, -6, -6, -4, -3 }, { -2, -3, -4, -4, -4, -4, -3, -2 } };//Making a game board of 8x8 of int with - ve values in it Knight intelliKnight = new Knight(a, b); //change the parameters of the intelli gent method and non intelli so that theyit will go as the user said intelliBoard[intelliKnight.a, intelliKnight.b] = numOfMoves; int move = 0; do { string[] knightMoves = goodMovesIntelli(convertListToString(intelliKnight.a, intelliKnight.b), intelliBoard); move = knightMoves.Length; if (knightMoves[0] == "") { move = 0; break; } if (move == 1) { int first = (int)Char.GetNumericValue(knightMoves[0][0]); int second = (int)Char.GetNumericValue(knightMoves[0][1]); intelliKnight.a = first; intelliKnight.b = second; numOfMoves++; intelliBoard[intelliKnight.a, intelliKnight.b] = numOfMoves; } else { Random rnd = new Random(); int random = rnd.Next(0, knightMoves.Length); //random number is generated while (randomer == random) { random = rnd.Next(0, knightMoves.Length); } randomer = random; int first = (int)Char.GetNumericValue(knightMoves[random][0]); int second = (int)Char.GetNumericValue(knightMoves[random][1]); intelliKnight.a = first; intelliKnight.b = second; numOfMoves++; intelliBoard[intelliKnight.a, intelliKnight.b] = numOfMoves; } } while (move > 0); // Console.WriteLine(numOfMoves + "these are the moves"); //used to print the multi dimensional array for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (intelliBoard[i, j] < 0) { intelliBoard[i, j] = 0; } } } saver += "\n"; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { // Console.Write("{0:D2} ", intelliBoard[i, j]); if (intelliBoard[i, j].ToString().Length == 1) { saver += string.Format(" {0} ", intelliBoard[i, j]); } else { saver += string.Format(" {0} ", intelliBoard[i, j]); } } // Console.WriteLine(""); saver += "\n"; } saver += "\n"; saver += "\n"; return(numOfMoves); }
public void nonIntelligent(int a, int b) { int numOfMoves = 1; int[,] nonIntelliBoard = new int[8, 8]; //Making a game board of 8x8 of int Knight nonIntelliKnight = new Knight(a, b); //change the parameters of the intelligent method and non intelli so that theyit will go as the user said nonIntelliBoard[nonIntelliKnight.a, nonIntelliKnight.b] = numOfMoves; int move = 0; do { string[] knightMoves = goodMovesNonIntelli(convertListToString(nonIntelliKnight.a, nonIntelliKnight.b), nonIntelliBoard); move = knightMoves.Length; if (knightMoves[0] == "") { move = 0; break; } if (move == 1) { int first = (int)Char.GetNumericValue(knightMoves[0][0]); int second = (int)Char.GetNumericValue(knightMoves[0][1]); nonIntelliKnight.a = first; nonIntelliKnight.b = second; numOfMoves++; nonIntelliBoard[nonIntelliKnight.a, nonIntelliKnight.b] = numOfMoves; } else { Random rnd = new Random(); int random = rnd.Next(0, knightMoves.Length); //random number is generated while (randomers == random) { random = rnd.Next(0, knightMoves.Length); } randomers = random; int first = (int)Char.GetNumericValue(knightMoves[random][0]); int second = (int)Char.GetNumericValue(knightMoves[random][1]); nonIntelliKnight.a = first; nonIntelliKnight.b = second; numOfMoves++; nonIntelliBoard[nonIntelliKnight.a, nonIntelliKnight.b] = numOfMoves; } } while (move > 0); Console.WriteLine(numOfMoves + "these are the moves"); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Console.Write(nonIntelliBoard[i, j] + " "); } Console.WriteLine(); } }