root/src/BRAINSFramework/Agent.cs

113
1
//****************************************************************//
2
//********************copyright Rik Dodsworth 2009****************//
3
//****************************************************************//
4
//***************************free to use**************************//
5
//****************************************************************//
6
//*******************please just leave this header****************//
7
//*************************for recognition************************//
8
//****************************************************************//
9
//****************************************************************//
10
11
using System;
1
using System;
12
using System.Collections.Generic;
2
using System.Collections.Generic;
13
using System.Linq;
3
using System.Linq;
...
...
26
using System.IO;
16
using System.IO;
27
using System.Reflection;
17
using System.Reflection;
28
using Brains.Framework.Designer;
18
using Brains.Framework.Designer;
19
using Brains.Framework.Map;
29
20
30
namespace Brains.Framework
21
namespace Brains.Framework
31
{
22
{
32
    /// <summary>
23
    /// <summary>
33
    /// Class to represent an AI Agent. Add the Agent to a World
24
    /// Represents an autonomous agent in the AI world.
34
    /// </summary>
25
    /// </summary>
35
    /// <remarks>You can implement your own Agent by inheriting from this class</remarks>
26
    /// <remarks>You can implement your own Agent by inheriting from this class</remarks>
36
    public class Agent
27
    public class Agent
...
...
186
            // - for each component calculate row and col
177
            // - for each component calculate row and col
187
178
188
            Vector2 vDistanceFromMapCenter = this.Position;
179
            Vector2 vDistanceFromMapCenter = this.Position;
189
            Grid map = ParentWorld.Map.Cluster[0];
180
            Grid map = ParentWorld.Map.ClusterGrid.Grids[0];
190
            float _hstep = (map.Width/ ((float)map.Cols));
181
            float _hstep = (map.Width/ ((float)map.Cols));
191
            float _vstep = (map.Height/ ((float)map.Rows));
182
            float _vstep = (map.Height/ ((float)map.Rows));
192
            float xComponent = (vDistanceFromMapCenter.X / _hstep) ;
183
            float xComponent = (vDistanceFromMapCenter.X / _hstep) ;
...
...
224
        }
215
        }
225
        public Grid GetGridAtPosition(Vector2 position)
216
        public Grid GetGridAtPosition(Vector2 position)
226
        {
217
        {
227
            foreach (var item in ParentWorld.Map.Cluster)
218
            foreach (var item in ParentWorld.Map.ClusterGrid.Grids)
228
            {
219
            {
229
                if (
220
                if (
230
                    (position.X > item.Position.X && position.X < (item.Position.X + item.Width)) &&
221
                    (position.X > item.Position.X && position.X < (item.Position.X + item.Width)) &&