I have written a script that allows a user to walk around a dungeon pick up gold and once they have picked it all up they can exit the game through an exit.
What I am doing now is writing a bot to do the same. So far I have come up with a 'stupid' bot that is based mainly on randomness. The bot has has actions to the following functions;
look() - Can see around the ASCII map in a radius of 2. The function prints it out so the bot cant actually store it in memory(I am allowed to store it memory).
move <direction>() - move in the direction these include N E S W.
pickUp() - If the bot is standing on gold this picks it up.
exitGame() - If the bot is standing on an exit, has all the gold and this command is ran he will exit the game.
Here is my bot code so far.
import java.io.IOException;
import java.util.Random;
public class Bot{
public GameLogic bot;
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
GameLogic bot = new GameLogic("map2.txt");
bot.startGame();
int gold = bot.gold();
System.out.println(gold);
int turn = 0;
char[][] myWorld = bot.getMap();
while(true){
int posX = bot.getPosX();
int posY = bot.getPosY();
Random rn = new Random();
int min = 0;
int max = 3;
int n = max - min + 1;
int i = rn.nextInt(n);
if(myWorld[posX][posY] == 'G'){
bot.pickUp();
}
if(myWorld[posX][posY] == 'E'){
boolean y = bot.exitGame();
if(y){break;}
}
turn++;
if(i == 0){
bot.moveN();
}else if(i == 1){
bot.moveE();
}else if(i == 2){
bot.moveS();
}else if(i == 3){
bot.moveW();
}else{
System.out.println("SOMETHING WENT WRONG!!!");
}
}
System.out.println(turn);
}
}
What I am asking is what would be a better way to do this. How can I improve my bot so it takes less turns to complete? How can I make my bot 'smarter'?