From: <cd...@us...> - 2007-01-09 20:55:25
|
Revision: 12 http://eos-game.svn.sourceforge.net/eos-game/?rev=12&view=rev Author: cduncan Date: 2007-01-09 12:55:13 -0800 (Tue, 09 Jan 2007) Log Message: ----------- Lord, I was born a rambling man... AI now turns occasionally, also made them slower so you can catch them. We'll speed them up again later. Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-01-09 15:06:09 UTC (rev 11) +++ ai.py 2007-01-09 20:55:13 UTC (rev 12) @@ -12,17 +12,24 @@ from vector import Vector2D class AI(Player): + + max_speed = 4 def __init__(self, camera): Player.__init__(self) self.camera = camera self.position += Vector2D(random.randint(-200, 200), random.randint(-200, 200)) + self.turning = 0 def update(self): # A.I. must chose which buttons to push + if not self.turning and random.randint(0,100) == 1: + self.turning = random.randint(-1, 1) + elif random.randint(0,40) == 1: + self.turning = 0 keystate = {} - keystate[K_LEFT] = 0 - keystate[K_RIGHT] = 0 + keystate[K_LEFT] = self.turning < 0 + keystate[K_RIGHT] = self.turning > 0 keystate[K_UP] = 1 keystate[K_DOWN] = 0 keystate[K_SPACE] = 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-01-10 08:12:57
|
Revision: 19 http://eos-game.svn.sourceforge.net/eos-game/?rev=19&view=rev Author: cduncan Date: 2007-01-10 00:12:54 -0800 (Wed, 10 Jan 2007) Log Message: ----------- Minor optimization: use inplace vector ops where possible Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-01-10 08:05:59 UTC (rev 18) +++ ai.py 2007-01-10 08:12:54 UTC (rev 19) @@ -18,7 +18,7 @@ def __init__(self, camera): Player.__init__(self) self.camera = camera - self.position += Vector2D(random.randint(-200, 200), random.randint(-200, 200)) + self.position += random.randint(-200, 200), random.randint(-200, 200) self.turning = 0 self.steerfunc = random.choice([self.pursuit, self.evade]) @@ -31,7 +31,9 @@ Player.update(self, keystate) # place self relative to the camera - where = Vector2D(self.camera.rect.centerx, self.camera.rect.centery) - self.camera.position + self.position + where = Vector2D(self.camera.rect.centerx, self.camera.rect.centery) + where -= self.camera.position # change where in-place + where += self.position # change where in-place self.rect.centerx = where.x self.rect.centery = where.y This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ob...@us...> - 2007-01-15 09:43:32
|
Revision: 35 http://eos-game.svn.sourceforge.net/eos-game/?rev=35&view=rev Author: oberon7 Date: 2007-01-15 01:43:31 -0800 (Mon, 15 Jan 2007) Log Message: ----------- Removed AI debugging print statements. Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-01-15 09:42:32 UTC (rev 34) +++ ai.py 2007-01-15 09:43:31 UTC (rev 35) @@ -21,11 +21,6 @@ return (self.position - target.position).normal * self.max_speed def steer(self, desired_velocity): - delta = self.heading - desired_velocity.radians - print self.heading - print desired_velocity.radians - print desired_velocity.normal - print return { K_a : 0, K_d : 0, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ob...@us...> - 2007-01-15 22:06:38
|
Revision: 44 http://eos-game.svn.sourceforge.net/eos-game/?rev=44&view=rev Author: oberon7 Date: 2007-01-15 14:06:36 -0800 (Mon, 15 Jan 2007) Log Message: ----------- Added ai.py unit tests. Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-01-15 21:39:01 UTC (rev 43) +++ ai.py 2007-01-15 22:06:36 UTC (rev 44) @@ -8,23 +8,81 @@ import random from pygame.locals import * +import game from player import Player -from vector import halfcircle, fullcircle +from vector import Vector2D class AI(Player): def __init__(self, target): Player.__init__(self) self.target = target - self.steerfunc = self.pursue + self.steerfunc = random.choice([self.seek, self.flee, self.pursue, self.evade]) def seek_position(self, target_position): + """Return desired velocity towards a fixed position + + >>> game.init(fullscreen=False) + >>> ai = AI(None) + >>> ai.max_speed = 10 + >>> ai.position = Vector2D(100, 0) + >>> vel = ai.seek_position(Vector2D(-100, 0)) + >>> vel.x + -10.0 + >>> vel.y + 0.0 + """ return (target_position - self.position).normal * self.max_speed def seek(self): + """Return desired velocity towards our target + + >>> game.init(fullscreen=False) + >>> ai = AI(AI(None)) + >>> ai.max_speed = 33.0 + >>> ai.position = Vector2D(0, 20) + >>> ai.target.position = Vector2D(0, 40) + >>> vel = ai.seek() + >>> vel.x + 0.0 + >>> vel.y + 33.0 + """ return self.seek_position(self.target.position) - def _predict_position(self, target): + def flee(self): + """Return desired velocity away from our target + + >>> game.init(fullscreen=False) + >>> ai = AI(AI(None)) + >>> ai.max_speed = 33.0 + >>> ai.position = Vector2D(0, 20) + >>> ai.target.position = Vector2D(0, 40) + >>> vel = ai.flee() + >>> vel.x + -0.0 + >>> vel.y + -33.0 + """ + return -self.seek() + + def predict_intercept(self, target): + """Return predicted position of target at the time + when we should intercept them + + >>> game.init(fullscreen=False) + >>> ai = AI(None) + >>> ai.max_speed = 100 + >>> ai.position = Vector2D(0, 0) + >>> target = AI(None) + >>> target.position = Vector2D(150, 0) + >>> target.velocity = Vector2D(20, 0) + >>> pos = ai.predict_intercept(target) + >>> pos.x + 180.0 + >>> pos.y + 0.0 + """ if target.velocity.normal is not None: T = self.position.distance(target.position) / self.max_speed return target.position + (target.velocity * T) @@ -32,8 +90,43 @@ return target.position def pursue(self): - return self.seek_position(self._predict_position(self.target)) + """Return desired velocity towards where we predict + our target to be + >>> game.init(fullscreen=False) + >>> ai = AI(None) + >>> ai.max_speed = 100 + >>> ai.position = Vector2D(0, 0) + >>> ai.target = AI(None) + >>> ai.target.position = Vector2D(150, 0) + >>> ai.target.velocity = Vector2D(-200, 0) + >>> vel = ai.pursue() + >>> vel.x + -100.0 + >>> vel.y + 0.0 + """ + return self.seek_position(self.predict_intercept(self.target)) + + def evade(self): + """Return desired velocity away from where we predict + our target to be + + >>> game.init(fullscreen=False) + >>> ai = AI(None) + >>> ai.max_speed = 42 + >>> ai.position = Vector2D(0, 0) + >>> ai.target = AI(None) + >>> ai.target.position = Vector2D(0, 150) + >>> ai.target.velocity = Vector2D(0, -200) + >>> vel = ai.evade() + >>> vel.x + -0.0 + >>> vel.y + 42.0 + """ + return -self.pursue() + def steer(self, desired_velocity): self.heading = (desired_velocity - self.velocity).radians return { @@ -59,3 +152,10 @@ # emulate being a legitimate player Player.update(self, keystate) + +if __name__ == '__main__': + """Run tests if executed directly""" + import sys, doctest + failed, count = doctest.testmod() + print 'Ran', count, 'test cases with', failed, 'failures' + sys.exit(failed) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-07-05 08:39:16
|
Revision: 237 http://eos-game.svn.sourceforge.net/eos-game/?rev=237&view=rev Author: cduncan Date: 2007-07-05 01:39:06 -0700 (Thu, 05 Jul 2007) Log Message: ----------- Increase proximity radius for vessel avoidance to prevent bunching, also increase radius where vessels are still considered "close" so that vessels keep track of their neighbors longer. Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-07-05 08:25:54 UTC (rev 236) +++ ai.py 2007-07-05 08:39:06 UTC (rev 237) @@ -44,7 +44,7 @@ self.mothership.add(mothership) self.steerfunc = self.standoff self.close_vessels = sprite.Group() - self.proximity_radius = self.vessel.collision_radius * 2 + self.proximity_radius = self.vessel.collision_radius * 3 self.sensor = sensor self.target_time = 0 @@ -229,7 +229,7 @@ center += vessel.position too_close.append(vessel) mass += vessel.mass - elif proximity > self.proximity_radius * 2: + elif proximity > self.proximity_radius * 4: # Other vessel is not considered "close" anymore self.close_vessels.remove(vessel) if too_close: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-01-31 07:04:05
|
Revision: 68 http://eos-game.svn.sourceforge.net/eos-game/?rev=68&view=rev Author: cduncan Date: 2007-01-30 23:04:02 -0800 (Tue, 30 Jan 2007) Log Message: ----------- Remove broken, unused declaration Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-01-31 07:01:41 UTC (rev 67) +++ ai.py 2007-01-31 07:04:02 UTC (rev 68) @@ -177,7 +177,6 @@ elif heading_diff < -halfcircle: heading_diff += fullcircle - turn_accel = self.vessel.directional_thrusters.accel turn_rate = self.vessel.turn_rate max_turn_rate = self.vessel.directional_thrusters.max_turn_rate if heading_diff > turn_rate / 3: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-02-15 07:28:30
|
Revision: 111 http://eos-game.svn.sourceforge.net/eos-game/?rev=111&view=rev Author: cduncan Date: 2007-02-14 23:28:22 -0800 (Wed, 14 Feb 2007) Log Message: ----------- Fix dumb bug in sensor that prevented it from selecting the closest vessel properly Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-02-15 07:16:36 UTC (rev 110) +++ ai.py 2007-02-15 07:28:22 UTC (rev 111) @@ -367,6 +367,7 @@ self.detected.empty() self._closest_dist = sys.maxint self.closest_vessel.empty() + self.last_sweep = game.frame_no if isinstance(other, Vessel): distance = self.vessel.position.distance(other.position) if distance < self._closest_dist: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-03-03 18:00:47
|
Revision: 118 http://eos-game.svn.sourceforge.net/eos-game/?rev=118&view=rev Author: cduncan Date: 2007-03-03 10:00:45 -0800 (Sat, 03 Mar 2007) Log Message: ----------- make ai hang back less. Changing this parameter alone turns the ai from easy to impossible (try 0.5 for instance). This makes it slightly harder but still beatable. Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-02-28 09:29:21 UTC (rev 117) +++ ai.py 2007-03-03 18:00:45 UTC (rev 118) @@ -36,7 +36,7 @@ self.steerfunc = netsync.random.choice([self.seek, self.pursue]) self.steerfunc = self.pursue - def seek_position(self, target_position, predict_ahead=1.0): + def seek_position(self, target_position, predict_ahead=0.75): """Return desired velocity towards a fixed position >>> game.init() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-03-05 23:25:48
|
Revision: 124 http://eos-game.svn.sourceforge.net/eos-game/?rev=124&view=rev Author: cduncan Date: 2007-03-05 15:25:47 -0800 (Mon, 05 Mar 2007) Log Message: ----------- Remove debug print Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-03-05 23:24:08 UTC (rev 123) +++ ai.py 2007-03-05 23:25:47 UTC (rev 124) @@ -75,7 +75,6 @@ target_velocity = self.target.sprite.velocity predict_ahead = (position + velocity * predict_ahead).distance( target_position + target_velocity * predict_ahead) / self.vessel.max_speed - print self.vessel, predict_ahead approach = (target_position + target_velocity * predict_ahead) - ( position + velocity * predict_ahead) new_heading = approach.radians This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-03-05 23:39:32
|
Revision: 125 http://eos-game.svn.sourceforge.net/eos-game/?rev=125&view=rev Author: cduncan Date: 2007-03-05 15:39:30 -0800 (Mon, 05 Mar 2007) Log Message: ----------- Dial back initial predict-ahead to "easy" this value can be modulated for overall difficulty Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-03-05 23:25:47 UTC (rev 124) +++ ai.py 2007-03-05 23:39:30 UTC (rev 125) @@ -52,7 +52,7 @@ return ((target_position - (self.vessel.position + self.vessel.velocity * predict_ahead) ) * game.avg_fps).clamp(self.vessel.max_speed) - def seek(self, predict_ahead=2.0): + def seek(self, predict_ahead=0.0): """Return desired velocity towards our target >>> game.init() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-03-14 06:07:22
|
Revision: 134 http://eos-game.svn.sourceforge.net/eos-game/?rev=134&view=rev Author: cduncan Date: 2007-03-13 23:07:21 -0700 (Tue, 13 Mar 2007) Log Message: ----------- Fix ai steering over-correction and oscillation Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-03-14 05:47:07 UTC (rev 133) +++ ai.py 2007-03-14 06:07:21 UTC (rev 134) @@ -219,9 +219,9 @@ turn_rate = self.vessel.turn_rate max_turn_rate = self.vessel.directional_thrusters.max_turn_rate - if heading_diff > turn_rate / 3: + if heading_diff > turn_rate: self.turn = 1 - elif heading_diff < -turn_rate / 3: + elif heading_diff < -turn_rate: self.turn = -1 else: self.turn = 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-03-20 21:44:51
|
Revision: 141 http://eos-game.svn.sourceforge.net/eos-game/?rev=141&view=rev Author: cduncan Date: 2007-03-20 14:24:05 -0700 (Tue, 20 Mar 2007) Log Message: ----------- Vessel avoidance based on mass. Smaller vessels move out of the way of larger ones (or the collective mass of their neighbors) Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-03-20 19:31:56 UTC (rev 140) +++ ai.py 2007-03-20 21:24:05 UTC (rev 141) @@ -204,18 +204,21 @@ """ center = Vector2D() too_close = [] + mass = 0 # Compute the center vector amongst close vessels and avoid it for vessel in list(self.close_vessels): proximity = max(self.vessel.position.distance(vessel.position) - vessel.radius, 0) if proximity < self.proximity_radius: center += vessel.position too_close.append(vessel) + mass += vessel.mass elif proximity > self.proximity_radius * 2: # Other vessel is not considered "close" anymore self.close_vessels.remove(vessel) if too_close: center /= len(too_close) - return (self.vessel.position - center).normal * self.vessel.max_speed + return (self.vessel.position - center).normal * ( + self.vessel.max_speed * (mass * 2.0 / self.vessel.mass)) else: return center This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-03-21 00:31:32
|
Revision: 142 http://eos-game.svn.sourceforge.net/eos-game/?rev=142&view=rev Author: cduncan Date: 2007-03-20 15:24:35 -0700 (Tue, 20 Mar 2007) Log Message: ----------- Only evade hostile vessels, fixes vessels adrift stuck on evade Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-03-20 21:24:05 UTC (rev 141) +++ ai.py 2007-03-20 22:24:35 UTC (rev 142) @@ -269,7 +269,9 @@ else: # No mothership, just head toward a planet self.target.add(game.planets) - elif (self.vessel.health < 0.66 and game.time - self.vessel.damage_time < 2000): + self.steerfunc = self.pursue + elif (self.vessel.health < 0.66 and game.time - self.vessel.damage_time < 2000 + and not self.vessel.is_friendly(self.target.sprite)): self.steerfunc = self.evade elif (self.vessel.health > 0.75 or self.target.sprite.position.distance(self.vessel.position) > 350): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-03-23 06:26:55
|
Revision: 152 http://eos-game.svn.sourceforge.net/eos-game/?rev=152&view=rev Author: cduncan Date: 2007-03-22 23:26:53 -0700 (Thu, 22 Mar 2007) Log Message: ----------- - AI targets other vessels first before missiles. Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-03-22 19:59:06 UTC (rev 151) +++ ai.py 2007-03-23 06:26:53 UTC (rev 152) @@ -349,6 +349,7 @@ self.detected = sprite.Group() self.closest_vessel = sprite.GroupSingle() self._closest_dist = sys.maxint + self._closest_type = None def disable(self): """Turn off sensor @@ -406,13 +407,16 @@ # This is a new frame, start a new sensor sweep self.detected.empty() self._closest_dist = sys.maxint + self._closest_type = None self.closest_vessel.empty() self.last_sweep = game.frame_no if isinstance(other, Vessel): distance = self.vessel.position.distance(other.position) - if distance < self._closest_dist: + if (distance < self._closest_dist or self._closest_type == 'missile' + and other.vessel_type != 'missle'): self.closest_vessel.sprite = other self._closest_dist = distance + self._closest_type = other.vessel_type self.detected.add(other) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-05-13 00:20:32
|
Revision: 225 http://eos-game.svn.sourceforge.net/eos-game/?rev=225&view=rev Author: cduncan Date: 2007-05-12 17:20:30 -0700 (Sat, 12 May 2007) Log Message: ----------- Use collision radius for ai vessel avoidance to avoid clumping Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-05-12 23:54:11 UTC (rev 224) +++ ai.py 2007-05-13 00:20:30 UTC (rev 225) @@ -37,7 +37,7 @@ if mothership: self.mothership.add(mothership) self.close_vessels = sprite.Group() - self.proximity_radius = self.vessel.radius * 2 + self.proximity_radius = self.vessel.collision_radius * 2 self.sensor = sensor self.steerfunc = self.pursue self.target_time = 0 @@ -215,7 +215,7 @@ # Compute the center vector amongst close vessels and avoid it for vessel in list(self.close_vessels): proximity = max(vector.distance( - self.vessel.position, vessel.position) - vessel.radius, 0) + self.vessel.position, vessel.position) - vessel.collision_radius, 0) if proximity < self.proximity_radius: center += vessel.position too_close.append(vessel) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-09-16 01:33:02
|
Revision: 257 http://eos-game.svn.sourceforge.net/eos-game/?rev=257&view=rev Author: cduncan Date: 2007-09-15 18:33:00 -0700 (Sat, 15 Sep 2007) Log Message: ----------- Make ai smarter about aiming at standoff distances. It's not perfect but it compensates nicely for the SC missiles. It especially helps the lotus. Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-09-16 01:31:22 UTC (rev 256) +++ ai.py 2007-09-16 01:33:00 UTC (rev 257) @@ -168,26 +168,28 @@ """Pursue a target, keeping our distance""" target = self.target.sprite position = self.vessel.position - if not target.velocity and vector.distance( - position, target.position) < target.collision_radius * 1.5: + to_target = target.position - position + if not target.velocity and vector.length(to_target) < target.collision_radius * 1.5: # close in to stationary target - return vector.radians(target.position - position), target.velocity + return vector.radians(to_target), target.velocity approach = self.predict_intercept(target) + distance = vector.length(target.position - position) if self.vessel.is_friendly(target): heading = target.heading - distance = self.vessel.collision_radius * 4 + target.collision_radius * 2 + desired_dist = self.vessel.collision_radius * 4 + target.collision_radius * 2 else: - distance = (self.vessel.collision_radius + target.collision_radius + + desired_dist = (self.vessel.collision_radius + target.collision_radius + self.vessel.standoff_distance) - heading = vector.radians(target.position - position) - if vector.length(approach) > distance * 1.5: + heading = (vector.radians(to_target) * desired_dist * 2 + + vector.radians(approach) * distance) / (desired_dist * 2 + distance) + if distance > desired_dist: # Far from target, catch up as fast as we can return vector.radians(approach), vector.clamp( approach * game.fps, self.vessel.max_speed) else: # close to target, keep a distance return heading, vector.clamp(-(approach * - (distance - vector.length(approach))), self.vessel.max_speed) + (desired_dist - vector.length(approach))), self.vessel.max_speed) def evade(self): """Return desired velocity away from where we predict This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-10-14 19:05:23
|
Revision: 290 http://eos-game.svn.sourceforge.net/eos-game/?rev=290&view=rev Author: cduncan Date: 2007-10-14 12:05:14 -0700 (Sun, 14 Oct 2007) Log Message: ----------- AI improvements: - Implement new vessel avoidance algorithm that calculates avoidance vectors for each close vessel individually rather than avoiding an averaged center vector of all. This helps reduce bunching alot in dog fights. - Reduce minimum look ahead in predict_intercept() to fix the "premature turnaround" problem. This makes warships (especially the lotus) track targets much more effectively on initial approach. Before they would turn away just as they got in range. This makes the lotus so much more effective it will probably warrant some stat tweaks to balance out. Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-10-13 17:45:35 UTC (rev 289) +++ ai.py 2007-10-14 19:05:14 UTC (rev 290) @@ -45,7 +45,7 @@ self.mothership.add(mothership) self.steerfunc = self.standoff self.close_vessels = Group() - self.proximity_radius = self.vessel.collision_radius * 3 + self.proximity_radius = self.vessel.collision_radius * 2.5 self.sensor = sensor self.target_time = 0 @@ -134,7 +134,7 @@ position = self.vessel.position predict_ahead = vector.distance(position + velocity * self_predict, target.position + target.velocity * target_predict) / self.vessel.max_speed - return (target.position + target.velocity * min(predict_ahead, 5.0)) - ( + return (target.position + target.velocity * min(predict_ahead, 1.0)) - ( position + velocity * self_predict) def pursue(self, predict_ahead=0.75): @@ -170,14 +170,15 @@ target = self.target.sprite position = self.vessel.position to_target = target.position - position - if not target.velocity and vector.length(to_target) < target.collision_radius * 1.5: - # close in to stationary target - return vector.radians(to_target), target.velocity approach = self.predict_intercept(target) distance = vector.length(target.position - position) - if self.vessel.is_friendly(target): + if not target.velocity: + # stationary target + heading = vector.radians(to_target) + desired_dist = target.collision_radius * 1.25 + elif self.vessel.is_friendly(target): heading = target.heading - desired_dist = self.vessel.collision_radius * 4 + target.collision_radius * 2 + desired_dist = self.vessel.collision_radius * 4 + target.collision_radius * 3 else: desired_dist = (self.vessel.collision_radius + target.collision_radius + self.vessel.standoff_distance) @@ -221,26 +222,21 @@ def avoid_vessels(self): """Return a vector away from other nearby vessels to avoid stacking up """ - center = vector.vector2() - too_close = [] - mass = 0 + avoid_vec = vector.vector2() # Compute the center vector amongst close vessels and avoid it for vessel in list(self.close_vessels): proximity = max(vector.distance( self.vessel.position, vessel.position) - vessel.collision_radius, 0) - if proximity < self.proximity_radius: - center += vessel.position - too_close.append(vessel) - mass += vessel.mass - elif proximity > self.proximity_radius * 4: + if proximity < self.proximity_radius * 4: + away = ((self.vessel.position + self.vessel.velocity / 5) - + (vessel.position + vessel.velocity / 5) - + (vessel.collision_radius + self.vessel.collision_radius)) * ( + vessel.mass / self.vessel.mass) + avoid_vec += away / (vector.length(away) / self.proximity_radius**2 or 0.001) + elif proximity > self.proximity_radius * 5: # Other vessel is not considered "close" anymore self.close_vessels.remove(vessel) - if too_close: - center /= len(too_close) - return vector.normal(self.vessel.position - center) * ( - self.vessel.max_speed * (mass * 4.0 / self.vessel.mass)) - else: - return center + return avoid_vec def steer(self, desired_heading, desired_velocity): heading_diff = desired_heading - self.vessel.heading This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-10-18 04:20:47
|
Revision: 293 http://eos-game.svn.sourceforge.net/eos-game/?rev=293&view=rev Author: cduncan Date: 2007-10-17 21:20:45 -0700 (Wed, 17 Oct 2007) Log Message: ----------- - Adjust some ai vessel avoidance parameters - Make sure a sensor never detects the vessel it is attached to Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-10-15 08:14:06 UTC (rev 292) +++ ai.py 2007-10-18 04:20:45 UTC (rev 293) @@ -45,7 +45,7 @@ self.mothership.add(mothership) self.steerfunc = self.standoff self.close_vessels = Group() - self.proximity_radius = self.vessel.collision_radius * 2.5 + self.proximity_radius = self.vessel.collision_radius * 5 self.sensor = sensor self.target_time = 0 @@ -232,7 +232,7 @@ (vessel.position + vessel.velocity / 5) - (vessel.collision_radius + self.vessel.collision_radius)) * ( vessel.mass / self.vessel.mass) - avoid_vec += away / (vector.length(away) / self.proximity_radius**2 or 0.001) + avoid_vec += away / (vector.length(away) / self.proximity_radius or 0.001) elif proximity > self.proximity_radius * 5: # Other vessel is not considered "close" anymore self.close_vessels.remove(vessel) @@ -582,7 +582,7 @@ >>> s.detected.sprites() [] """ - if other in self.exclude: + if other in self.exclude or other is self.vessel: return if self.last_sweep != game.frame_no and self.detected: # This is a new frame, start a new sensor sweep This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-10-18 05:57:26
|
Revision: 299 http://eos-game.svn.sourceforge.net/eos-game/?rev=299&view=rev Author: cduncan Date: 2007-10-17 22:57:25 -0700 (Wed, 17 Oct 2007) Log Message: ----------- Make sure ai vessels are always drawn below the local player Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-10-18 05:44:47 UTC (rev 298) +++ ai.py 2007-10-18 05:57:25 UTC (rev 299) @@ -443,6 +443,8 @@ sensor.disable() ai_class = globals()[ai] self.control = ai_class(self, target, mothership, sensor) + # Make sure we are behind the local player + self.layer.to_back(self) class Sensor: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2007-11-04 05:58:33
|
Revision: 320 http://eos-game.svn.sourceforge.net/eos-game/?rev=320&view=rev Author: cduncan Date: 2007-11-03 22:58:12 -0700 (Sat, 03 Nov 2007) Log Message: ----------- Improved ai behavior when near its stationary target Modified Paths: -------------- ai.py Modified: ai.py =================================================================== --- ai.py 2007-11-02 04:48:28 UTC (rev 319) +++ ai.py 2007-11-04 05:58:12 UTC (rev 320) @@ -177,7 +177,9 @@ if not target.velocity: # stationary target heading = vector.radians(to_target) - desired_dist = target.collision_radius * 1.25 + desired_dist = target.collision_radius + self.vessel.collision_radius * 5 + if distance < desired_dist: + return self.vessel.heading, vector.vector2() elif self.vessel.is_friendly(target): heading = target.heading desired_dist = self.vessel.collision_radius * 4 + target.collision_radius * 3 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |