Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var arena = {};
- arena.map = arguments[0];
- arena.rows = arena.map.split('\\n');
- arena.find = function(toFind){
- for(var i = 0; i < 10; i++){
- if(typeof arena.rows[i] !== 'undefined'){
- if(arena.rows[i].indexOf(toFind) !== -1){
- return [arena.rows[i].search(toFind), i];
- }
- }
- }
- };
- arena.findAtPos = function(x, y){
- return arena.rows[y].charAt(x);
- };
- me = {};
- me.pos = arena.find('Y');
- me.x = me.pos[0];
- me.y = me.pos[1];
- me.energy = parseInt(arena.rows[10].replace("Y ", ""));
- foe = {};
- foe.pos = arena.find('X');
- foe.x = foe.pos[0];
- foe.y = foe.pos[1];
- foe.energy = parseInt(arena.rows[11].replace("X ", ""));
- function FindFoe(){
- if(me.x < foe.x){
- if(me.y < foe.y){
- foe.direction = 'NW';
- }
- else if(me. y === foe.y){
- foe.direction = 'W';
- }
- else{
- foe.direction = 'SW'
- }
- }
- if(me.x === foe.x){
- if(me.y < foe.y){
- foe.direction = 'N';
- }
- else{
- foe.direction = 'S'
- }
- }
- if(me.x > foe.x){
- if(me.y < foe.y){
- foe.direction = 'NE';
- }
- else if(me. y === foe.y){
- foe.direction = 'E';
- }
- else{
- foe.direction = 'SE'
- }
- }
- }
- function findCentre(){
- if(me.x < 4){
- if(me.y < 4){
- centreDirection = 'NW';
- }
- else if(me. y === 4){
- centreDirection = 'W';
- }
- else{
- centreDirection = 'SW'
- }
- }
- if(me.x === 4){
- if(me.y < 4){
- centreDirection = 'N';
- }
- else{
- centreDirection = 'S'
- }
- }
- if(me.x > 4){
- if(me.y < 4){
- centreDirection = 'NE';
- }
- else if(me. y === 4){
- centreDirection = 'E';
- }
- else{
- centreDirection = 'SE'
- }
- }
- }
- if(me.x !== 4 && me.y !== 4){
- print(centerDirection);
- }else{
- print('B ' + foe.direction);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement