public void Clear() { bestRecord = null; worstRecord = null; fear = 0; friend = 0; food = 0; straight = 0; eastWest = 0; wall = 0; }
private void Scan() { Vector3 actorPos = actor.transform.position; Vector3 facing = actor.Forward; Bounds liveable = World.Instance.GetLiveableArea(actor.liveableArea); for(int i=0; i<choice.Count; ++i) { Direction dir = (Direction)i; Vector3 dirVector = Utils.GetVector(dir); float dotp = Vector3.Dot(facing, dirVector); DirectionalData dirData = choice[i]; dirData.Clear(); if( dotp > 0.8 ) { dirData.straight = 10; } else if( dotp > 0.6) { dirData.straight = 6; } else { dirData.straight = 0; } dirData.eastWest = EastWestDesire(dir); if( dir == Direction.CENTER ) { //temp dirData.wall = -10; } else { dirData.wall = WallDesire(dir, actorPos, liveable); } choice[i] = dirData; } List<Actor> actors = World.Instance.allActors; for(int i=0; i<actors.Count; ++i) { Actor other = actors[i]; if( other == actor || !other.IsAlive ) { continue; } float range = Range(actor, other); BrainRecord record = null; if( records.ContainsKey(other.uid) ) { record = records[other.uid]; } else { record = new BrainRecord(other.uid); records.Add(other.uid, record); } Direction dir = Direction.CENTER; if( range > 3 ) { dir = Utils.GetDirection(actor, other); } int d = (int)dir; DirectionalData dirData = choice[d]; record.position = other.transform.position; record.age = 0; record.range = range; record.fear = FearDesire(actor, other); record.friend = FriendDesire(actor, other); record.food = FoodDesire(actor, other); dirData.fear = Mathf.Max(dirData.fear + record.fear, -10f); dirData.friend = Mathf.Min(dirData.friend + record.friend, 10f); dirData.food = Mathf.Min(dirData.food + record.food, 10f); if( record.WorseThan(dirData.worstRecord, behaviour) ) { dirData.worstRecord = record; } if( record.BetterThan(dirData.bestRecord, behaviour) ) { dirData.bestRecord = record; } choice[d] = dirData; } }
public bool WorseThan(BrainRecord other, BrainBehaviour behaviour) { float lhs = BadSum(behaviour); if( other == null ) { return lhs < 0; } float rhs = other.BadSum(behaviour); return lhs < rhs; }
public bool BetterThan(BrainRecord other, BrainBehaviour behaviour) { float lhs = GoodSum(behaviour); if( other == null ) { return lhs > 0; } float rhs = other.GoodSum(behaviour); return lhs > rhs; }