Professional Documents
Culture Documents
Nature Token 3
Nature Token 3
ملف Bot.java
قبل:
تحديث ما بعد التعديالت: بعد
wildlife الخاص ب الscore للحصول على الbotstratgy تم مالئمة هذا الكود الستخدام الميثود من
tile و
nature token strategy من الموجود أمام المستخدم وذلك ليتم اختيار األفضل منها وحساب ال
BoardTile tileChoice = null;
WildLifeToken tokenChoice = null;
boolean choicePicked = false;
//if user has a nature token, they are given options with selecting tiles and tokens
if (bots.get(i).getNumNatureTokens() > 0) {
if (view.askBotUseToken(tilesScores, tokensScores)) {
view.displayBotChoice(bots.get(i), "to use a nature token.");
: بعد
if (i < 20) {
view.nextTurn();
//ask the user for input, next or quit
// Command c = view.getBotInput();
// if (c.isQuit()) {
// view.displayQuit();
// commandQuit = true;
// }
}
التاليين هما كودين اختياريين حيث تم برمجة بديل لهما من قبل فريقكم وفريقنا ويجب تنفيذهما معا او عدم2 و1 إختياري ( الكودين رقم
)تنفذيها معا
1 كود رقم
: قبل
::بعد
//Function to choose a tile and token pair and place it on the board
//returns 1,2,3,or 4 corresponding to pairs a,b,c, or d
//always chooses first pair for now
/// update-- now choosing the best pair
public static int chooseTokenTilePair(int[] tilesScores, int[] tokensScores) {
int maxIndex = 0;
::بعد
int choice = 4;
while (choice == 4) {
choice = chooseTokenTilePair(tilesScores, tokensScores);
String stringChoice = switch (choice) {
case 0 -> "a";
case 1 -> "b";
case 2 -> "c";
case 3 -> "d";
default -> " ";
};
view.displayBotChoice(bots.get(i), stringChoice);
}
chooseBotUseNatureToken تعديل ميثود
وهذه القيمة يمكن٢ تزيد عنtile و الtoken الناتجة عن اختيار اي من الscore هذا الكود يقوم بفحص اذا كانت ال
تغييرها
nature token فإن كانت أعلى فإنه ال يستخدم
أما إن كانت أقل فانه يقوم باستخدامها ألجل الحصول على نتيجة افضل
:قبل
::بعد
public static boolean chooseBotUseNatureToken(int[] tilesScores, int[] tokensScores) {
try {
}
chooseBotNatureTokenUseType تعديل ميثود
nature token يقوم هذا الكود بنفس الكود السابق ولكن هذه المرة لتحديد اي طريقة الستخدام ال
منفصلين والحصول على نتيجة جيدة فإنه يقوم بذلكtile وtoken فإن كان من الممكن اختيار
::قبل
::بعد
public static int chooseBotNatureTokenUseType(int[] tilesScores, int[] tokensScores) {
// if a tile and a token has a good score choose one
// else choose two to change the tokens
بعد
}
public static String chooseATokenFromFour(int[] tokensScores) {
return getBest(tokensScores);
int maxIndex = 0;
return String.valueOf(letters[maxIndex]);
}
إضافة الميثود
nature tokeen ليتم استبدالها بواسطة الwildlife token تقوم هذه الميثود بإختيار أسوأ
::جديد
public static String chooseBadTokenFromFour(int[] tokensScores) {
char[] letters = {'a', 'b', 'c', 'd'};
int minIndex = 0;
}
View.java ملف
استبدال الميثودين التاليتين
في ملف بوت8تم تعديل هاتين الميثود لكي تستخدم الميثود الجديدة المضافة
بدال من االختيار العشوائي
::قبل
public int[] UseBotTokenOption1() {
do {
options[0] = -1;
System.out.println("Choose any board tile. (a/b/c/d)");
String str = Bot.chooseATileFromFour(tilesScores);
str = str.trim().toLowerCase();
switch (str) {
case "a" -> options[0] = 0;
case "b" -> options[0] = 1;
case "c" -> options[0] = 2;
case "d" -> options[0] = 3;
}
} while (options[0] == -1);
System.out.println("Chosen: " + options[0]);
do {
options[1] = -1;
str = Bot.chooseATileFromFour();
if (str.equalsIgnoreCase("a")) {
option[i] = 1;
} else if (str.equalsIgnoreCase("b")) {
option[i] = 2;
} else if (str.equalsIgnoreCase("c")) {
option[i] = 3;
} else if (str.equalsIgnoreCase("d")) {
option[i] = 4;
}
} while (option[i] != 1 && option[i] != 2 && option[i] != 3 && option[i] != 4);
System.out.println("Chosen: " + str);
}
return option;
}
::بعد
str = Bot.chooseBadTokenFromFour(tilesScores);
if (str.equalsIgnoreCase("a")) {
option[i] = 1;
} else if (str.equalsIgnoreCase("b")) {
option[i] = 2;
} else if (str.equalsIgnoreCase("c")) {
option[i] = 3;
} else if (str.equalsIgnoreCase("d")) {
option[i] = 4;
}
} while (option[i] != 1 && option[i] != 2 && option[i] != 3 && option[i] != 4);
System.out.println("Chosen: " + str);
}
return option;
}
::إستبدال الميثودين التاليتين بالجديدات
::بعد
public boolean askBotUseToken(int[] tilesScores, int[] tokensScores) {
System.out.println("Would you like to use a nature token? (y/n)");
boolean answer = Bot.chooseBotUseNatureToken(tilesScores,tokensScores);
System.out.println("Chosen answer: " + (answer ? "Y" : "N"));
return answer;
}
::جديد
public void nextTurn() {
int i = 4;
System.out.print("Next Turn in 5...");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
do {
System.out.print(i + "...");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
i--;
} while (i > 0);
System.out.println("Starting Next Turn...");