creative4 - function [out] = creative4(self, enemy, tank,...

This preview shows pages 1–2. Sign up to view the full content.

function [out] = creative4(self, enemy, tank, mine, req) switch req case 'info' out.team = 'Creative4'; out.student(1).first = 'Eddie'; out.student(1).last = 'Lo'; out.student(1).SID = '19483002'; out.student(1).lab = 18; case 'move' % set up parameters for robot params.speed_fuel = 2.2; params.speed_end = 0.5; params.speed_chase = 2.5; if enemy.fuel < self.fuel if ~isempty(tank) if norm(self.pos - enemy.pos) > 10 % start d at infinity d = inf; I = 0; % loop through fuel tanks checking if current fuel tank is % closer than previous closest. for i = 1:length(tank) % get distance to this fuel tank D = norm(tank(i).pos - self.pos); if D < d d = D; I = i; end end if norm(tank(I).pos(1)-enemy.pos(1)) < norm(tank(I).pos(2)- enemy.pos(2)) for i = 2:length(tank) % get distance to this fuel tank D = norm(tank(i).pos - self.pos); if D < d d = D; I = i; end end % make movement towards NEXT closest fuel tank dx = (params.speed_fuel/d)*(tank(I).pos(1)- self.pos(1)); dy = (params.speed_fuel/d)*(tank(I).pos(2)-

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/16/2009 for the course ENGIN 7 taught by Professor Horowitz during the Spring '08 term at University of California, Berkeley.

Page1 / 3

creative4 - function [out] = creative4(self, enemy, tank,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online