[Gcblue-commits] gcb_wx/scripts AI.py,1.12,1.13
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-11-03 16:36:53
|
Update of /cvsroot/gcblue/gcb_wx/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15682/scripts Modified Files: AI.py Log Message: AI experimentation Index: AI.py =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/scripts/AI.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** AI.py 9 Aug 2004 02:35:14 -0000 1.12 --- AI.py 3 Nov 2004 16:36:43 -0000 1.13 *************** *** 65,71 **** UI.SetUpdate(30.0) # engage hostiles in range ! track_id = GetSuitableTarget(UI) ! if (track_id != -1): ! UI.SetTarget(track_id) UI.SetHeadingToInterceptTarget() UI.SetUpdate(4.0) --- 65,84 ---- UI.SetUpdate(30.0) # engage hostiles in range ! ! missile_score, missile_id = GetSuitableTargetAll(UI, 64) ! if (missile_score >= 3.0): ! best_id = missile_id ! else: ! surf_score, surf_id = GetSuitableTargetAll(UI, 16) ! air_score, air_id = GetSuitableTargetAll(UI, 32) ! ! if (air_score > surf_score): ! best_id = air_id ! else: ! best_id = surf_id ! ! #track_id = GetSuitableTarget(UI) ! if (best_id != -1): ! UI.SetTarget(best_id) UI.SetHeadingToInterceptTarget() UI.SetUpdate(4.0) *************** *** 269,274 **** UI.SetUpdate(10) ! ! def GetSuitableTarget(UI): --- 282,315 ---- UI.SetUpdate(10) ! # this version iterates through all tracks ! def GetSuitableTargetAll(UI, class_mask): ! # anAffiliation: UNKNOWN = 0, FRIENDLY = 1, NEUTRAL = 2, HOSTILE = 3 ! # ! # anClassMask: ! # PTYPE_SURFACE 0x0010 ! # PTYPE_AIR 0x0020 ! # PTYPE_MISSILE 0x0040 ! # PTYPE_SUBSURFACE 0x0080 ! # PTYPE_FIXED 0x0100 ! # int anClassMask, float afMaxRange_km, UINT8 anAffiliation ! track_list = UI.GetTrackList(class_mask, 150, 3) ! nTracks = track_list.Size() ! best_score = 0 ! best_target = -1 ! info_string = '' ! for n in range(0, nTracks): ! track_info = track_list.GetTrack(n) ! track_id = track_info.ID ! engaged_count = track_info.GetEngagedCount() ! UI.SetTarget(track_id) ! score = ScoreTarget(UI, track_info) ! if (score > best_score): ! best_score = score ! best_target = track_id ! ! info_string = '%s %d (%.1f %d)' % (info_string, track_id, score, engaged_count) ! ! UI.DisplayMessage('%d: %s\n' % (class_mask, info_string)) ! return (best_score, best_target) def GetSuitableTarget(UI): *************** *** 308,312 **** if target_id == -1: return ! # check if effective weapon is available target_info = UI.GetTargetTrackInfo() --- 349,353 ---- if target_id == -1: return ! # check if effective weapon is available target_info = UI.GetTargetTrackInfo() *************** *** 315,318 **** --- 356,361 ---- if (launcher == -1): # if (no effective launcher is available) return 0 + engaged_count = target_info.GetEngagedCount() + UI.DisplayMessage('target id: %d, engaged count: %d\n' % (target_id, engaged_count)) launch_range = launcher_info.Range_km # reference max range, use for launch decision target_range = UI.GetRangeToTarget() *************** *** 322,325 **** --- 365,393 ---- return 2 + def ScoreTarget(UI, target_info): + target_id = target_info.ID + if target_id == -1: + return + + # check if effective weapon is available + launcher_info = UI.GetBestLauncher() + launcher = launcher_info.Launcher + if (launcher == -1): # if (no effective launcher is available) + return 0 + engaged_count = target_info.GetEngagedCount() + if (engaged_count > 4): + return 0 + + launch_range = launcher_info.Range_km # reference max range, use for launch decision + target_range = UI.GetRangeToTarget() + if (target_range > launch_range): + score = 1 + 0.001 * (target_range - launch_range) + else: + score = 3 + 0.001 * target_range + + score = score * 0.2 * (5-engaged_count) + return score + + def InterceptTarget(UI): targetid = UI.GetTarget() *************** *** 341,345 **** # debug_file.close() ! if (target_info.GetEngagedCount() > 4): UI.SetTarget(-1) # clear target return --- 409,413 ---- # debug_file.close() ! if (target_info.GetEngagedCount() > 2): UI.SetTarget(-1) # clear target return *************** *** 378,382 **** launch_qty = 1 elif target_info.IsMissile(): ! launch_qty = 2 elif target_info.IsSurface(): launch_qty = 4 --- 446,450 ---- launch_qty = 1 elif target_info.IsMissile(): ! launch_qty = 1 elif target_info.IsSurface(): launch_qty = 4 |