// Cloned by Jake Grogan on 6 Nov 2018 from Mind "Simple Mind" by Starter user // Please leave this clone trail here.// ==== Starter Mind ===============================================================================================// (c) Ancient Brain Ltd. All rights reserved.// This code is only for use on the Ancient Brain site.// This code may be freely copied and edited by anyone on the Ancient Brain site.// This code may not be copied, re-published or used on any other website.// To include a run of this code on another website, see the "Embed code" links provided on the Ancient Brain site.// ==================================================================================================================// =================================================================================================// Sample Mind for simple starter World // =================================================================================================// World tells us agent position and enemy position// World does not tell us of existence of walls// if return invalid move (not empty square) World just ignores it and we miss a turn functionMind(){
prev =-1;
nextMove =-1function getBestMove(options, enemy){
best =0;
bestMove =[-1,-1];
console.log("OPTIONS", options)for(i =0; i < options.length; i++){// if(options[i][0] == 0 && options[i][1] == 0) {// continue;// }
distance =(options[i][0]- enemy[0])+(options[i][1]- enemy[1]);if(distance <0){
distance = distance *-1;}
console.log(distance);if(distance > best){
best = distance;
bestMove[0]= options[i][0];
bestMove[1]= options[i][1];}}
console.log("Best Move: ", bestMove);return bestMove;}function getOptions(me){// up down left right
options =[[0,0],[0,0],[0,0],[0,0]]// Check if not against top wall (Can move up)if(me[1]!=1){
options[0]=[me[0], me[1]-1]}// Can move downif(me[1]!=18){
options[1]=[me[0], me[1]+1]}// Can move leftif(me[0]!=1){
options[2]=[me[0]-1, me[1]]}if(me[0]!=18){
options[3]=[me[0]+1, me[1]]}
console.log(options);return(options);}function makeMove(me, bestMove){if(bestMove[0]> me[0]){return1;}elseif(bestMove[0]< me[0]){return0;}elseif(bestMove[1]> me[1]){return2;}else{return3;}}this.newRun =function(){};this.getAction =function( state ){
me =[state[0], state[1]];
enemy =[state[2], state[3]];//ops = getOptions(me);
options =[[0,0],[0,0],[0,0],[0,0]]// Check if not against top wall (Can move up)if(me[1]!=1){
options[0]=[me[0], me[1]-1]}// Can move downif(me[1]!=18){
options[1]=[me[0], me[1]+1]}// Can move leftif(me[0]!=1){
options[2]=[me[0]-1, me[1]]}if(me[0]!=18){
options[3]=[me[0]+1, me[1]]}
best =0;
bestMove =[-1,-1];for(i =0; i < options.length; i++){// if(options[i][0] == 0 && options[i][1] == 0) {// continue;// }
distance =(options[i][0]- enemy[0])+(options[i][1]- enemy[1]);if(distance <0){
distance = distance *-1;}
console.log(distance);if(distance > best){
best = distance;
bestMove[0]= options[i][0];
bestMove[1]= options[i][1];}}if(bestMove[0]> me[0]){
move =1;}elseif(bestMove[0]< me[0]){
move =0;}elseif(bestMove[1]> me[1]){
move =2;}else{
move =3;}//bm = getBestMove(options, enemy);//move = makeMove(me, bm);if(prev === move){
move = AB.randomIntAtoB(0,3);}
prev = move;
console.log(move);return(move);};this.endRun =function(){};}