Exemplo n.º 1
0
    protected void chooseStartLocation(SimpleAgent a)
    {
        MazeRoom r = laby.rooms [Random.Range(0, laby.rooms.Count)];
        MazeCell c = r.cells [Random.Range(0, r.cells.Count)];

        a.transform.localPosition = new Vector3(c.transform.position.x, 52f, c.transform.position.z);
    }
Exemplo n.º 2
0
    protected void hitAgent(GameObject others)
    {
        SimpleAgent a = others.GetComponent <SimpleAgent> ();

        // Actual damage
        float damage = (DAMAGE + Random.Range(0, RANGE_DAMAGE));

        if (a.health > damage)
        {
            hasDamaged = true;

            a.health -= damage;

            // update health bar
            GameObject bar = a.transform.GetChild(4).gameObject;
            bar.transform.localScale = new Vector3(a.health * 0.015f, bar.transform.localScale.y, bar.transform.localScale.z);

            a.transform.GetChild(0).gameObject.GetComponent <Renderer> ().material = a.redMat;
            a.state = SimpleAgent.STATES.FIGHTING;
        }
        else
        {
            a.onDie();
        }
    }
Exemplo n.º 3
0
 protected internal static object FetchValue(Type type, NSJSValue value)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (typeof(NSJSValue).IsAssignableFrom(type))
     {
         return(type.IsInstanceOfType(value) ? value : null);
     }
     if (value == null || value.IsNullOrUndfined)
     {
         return(null);
     }
     if ((value.DateType & NSJSDataType.kFunction) > 0)
     {
         return(value);
     }
     if ((value.DateType & NSJSDataType.kArray) > 0 ||
         (value.DateType & NSJSDataType.kObject) > 0)
     {
         Func <NSJSValue, object> converter = SimpleAgent.GetConverterBox(type, true);
         if (converter == null)
         {
             return(null);
         }
         return(converter(value));
     }
     return(value.GetValue());
 }
Exemplo n.º 4
0
        private void startToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listLogs.Items.Clear();
            List <WebAction> actions = new List <WebAction>();

            //goto home url - https://www.bing.com/
            actions.Add(new SimpleWebAction(new UrlWebStep("open search", "https://www.bing.com/"),
                                            new LocatorCheckValidator(new SimpleHtmlElementLocator("q search box",
                                                                                                   new AttributeHtmlElementMatcher("q search box", "name", "q"))), waitForEvent: true));
            //submit a search
            actions.Add(new SimpleWebAction(new FormWebStep("submit search", new IdElementLocator("locate form to submit", "sb_form"), new Dictionary <String, String>
            {
                { "sb_form_q", "WebScraper.NET github" }
            }
                                                            ), waitForEvent: true));
            //load results
            actions.Add(new ExtractWebAction <String>(new StringHtmlElementDataExtractor("href"), "firstNavLink",
                                                      new TagElementLocator("match results", "ol", false, "firstResultLink",
                                                                            new SimpleChildHtmlElementLocator("find first link",
                                                                                                              filter: new SimpleChildHtmlElementLocator("get first a", new TagHtmlElementMatcher("match first a", "a"))),
                                                                            new IdHtmlElementMatcher("match results ol", "b_results"))));
            //goto first result
            actions.Add(new SimpleWebAction(new UrlWebStep("open search", "firstNavLink"), new TitleWebValidator("GitHub - perusworld/WebScraper.NET: A .Net based Web Scraper using the WebBrowser control"), waitForEvent: true));
            SimpleAgent bingSearchAgent = new SimpleAgent(webBrowser, actions);

            bingSearchAgent.MonitorTimings = true;
            bingSearchAgent.AgentCallback  = this;
            bingSearchAgent.init();
            bingSearchAgent.startAgent();
        }
Exemplo n.º 5
0
    protected void createAgents()
    {
        int nbAgents = this.transform.childCount;

        for (int i = nbAgents; i < MAX_AGENTS; i++)
        {
            GameObject o = Instantiate(agentPrefab) as GameObject;
            o.name = "Agent";
            SimpleAgent a = o.GetComponent <SimpleAgent> ();
            a.transform.parent = this.transform;
            a.maze             = laby;
            chooseStartLocation(a);
        }
    }
Exemplo n.º 6
0
        private static void Main(string[] args)
        {
            Io.Initialize();
            var agent = new SimpleAgent();

            // game loop
            while (true)
            {
                var game = new Game();
                game.Initialize();
                var action = agent.GetAction(game);

                Io.WriteLine(action.GetAction());
            }
        }
Exemplo n.º 7
0
        protected internal static NSJSValue ConvertValue(NSJSVirtualMachine machine, object obj)
        {
            if (machine == null)
            {
                return(default(NSJSValue));
            }
            if (obj == null || obj == DBNull.Value)
            {
                return(NSJSValue.Null(machine));
            }
            if (obj is NSJSValue)
            {
                return(unchecked ((NSJSValue)obj));
            }
            NSJSValue value = ValueAuxiliary.As(obj, machine);

            if (value != null && !value.IsNullOrUndfined)
            {
                return(value);
            }
            return(SimpleAgent.ToObject(machine, obj));
        }
Exemplo n.º 8
0
        private static Game GetGame()
        {
            IAgent agent     = new SimpleAgent();
            var    factories = new List <ICellFactory>();

            factories.Add(new EmptyCellFactory());
            factories.Add(new PitCellFactory());
            factories.Add(new BatCellFactory());
            var actions = new List <IAction>();

            actions.Add(new MoveAction());
            actions.Add(new FireAction());
            actions.Add(new TurnLeftAction());
            actions.Add(new TurnRightAction());
            actions.Add(new FindWumpusAction());
            actions.Add(new GrabAction());
            IMapGenerator generator = new RandomGenerator(factories);

            generator.AddMapGeneratedHook(new GoldAddHook());
            var game = new Game(generator, actions, agent);

            game.RegisterInitialisationHook(new GiveArrowHook());
            return(game);
        }
Exemplo n.º 9
0
        public VirusInterface(Virus virus, int tilesize = 20, bool immediateAI = false, params String[] names)
        {
            InitializeComponent();
            this.virus       = virus;
            this.tileSize    = tilesize;
            this.immediateAI = immediateAI;
            this.MouseClick += MouseClickHandler1;
            this.Size        = new Size(
                virus.Size * tileSize + 17,
                virus.Size * tileSize + 55);
            this.names.Add("Player 0");
            this.names.AddRange(names);
            while (this.names.Count < virus.Players + 1)
            {
                this.names.Add("Player " + this.names.Count);
            }
            //Save("Lalalafil");
            agents = new Agent[this.names.Count];
            int n = 1;

            for (byte i = 1; i < this.names.Count; i++)
            {
                String p = this.names[i];
                switch (p)
                {
                case "QAI":
                    agents[i] = new QAgent(i);
                    if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N"))
                    {
                        ((QAgent)agents[i]).Load("TrainingData");
                        ((QAgent)agents[i]).TurnOffExploration();
                        ((QAgent)agents[i]).TurnOffLearning();
                    }
                    this.names[i] = "AI " + n;
                    n++;
                    break;

                case "AnnAI":
                    agents[i]     = new AnnAgent(false, virus.Size, i);
                    this.names[i] = "AI " + n;
                    n++;
                    break;

                case "MinimaxAI":
                    agents[i]     = new MinimaxAgent(4, i);
                    this.names[i] = "AI " + n;
                    n++;
                    break;

                case "MiniMaxMixAI":
                    if (File.Exists("TrainingData.Q"))
                    {
                        agents[i] = new MiniMaxMixAgent("TrainingData", 2, i);
                    }
                    else
                    {
                        agents[i] = new BruteForceAgent(i);
                    }
                    this.names[i] = "AI " + n;
                    n++;
                    break;

                case "MixedAI":
                    agents[i]     = new MixedAgent(0.5, false, i);
                    this.names[i] = "AI " + n;
                    n++;
                    break;

                case "BruteAI":
                    agents[i]     = new BruteForceAgent(i);
                    this.names[i] = "AI " + n;
                    n++;
                    break;

                case "RandomAI":
                    agents[i]     = new RandomAgent(i);
                    this.names[i] = "AI " + n;
                    n++;
                    break;

                case "SimpleAI":
                    agents[i]     = new SimpleAgent(i);
                    this.names[i] = "AI " + n;
                    n++;
                    break;
                }
            }

            message = this.names[1] + "'s turn";

            colors    = new Color[virus.Players + 1];
            colors[0] = Color.White;
            colors[1] = Color.FromArgb(128, 160, 255);
            colors[2] = Color.FromArgb(96, 255, 96);
            if (virus.Players > 2)
            {
                colors[3] = Color.FromArgb(255, 96, 96);
            }
            if (virus.Players > 3)
            {
                colors[4] = Color.FromArgb(255, 255, 64);
            }
            Random rand = new Random();

            for (int i = 5; i <= virus.Players; i++)
            {
                colors[i] = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));
            }
        }
Exemplo n.º 10
0
        public void StartGame(
            Virus virus,
            PerformedMoveCallback callback,
            UpdatePiecesCallback piecesCallback,
            EndCallback end,
            string id,
            params VirusPlayer[] players)
        {
            Random rand = new Random();

            PerformedMove    = callback;
            UpdatePieces     = piecesCallback;
            End              = end;
            PlayerID         = id;
            this.virus       = virus;
            this.immediateAI = true;
            this.MouseClick += MouseClickHandler1;
            tileSize         = 49;
            this.Size        = new Size(
                virus.Size * tileSize + 17,
                virus.Size * tileSize + 55);
            int smallestSide = this.Size.Height < this.Size.Width ? this.Size.Height : this.Size.Width;

            tileSize = smallestSide / virus.Size;
            this.players.Add(new VirusPlayer("Player 0", "", Color.White));
            this.players.AddRange(players);
            while (this.players.Count < virus.Players + 1)
            {
                this.players.Add(new VirusPlayer("BruteAI", "AI", Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256))));
            }
            //Save("Lalalafil");
            agents = new Agent[this.players.Count];
            int n = 1;

            for (byte i = 1; i < this.players.Count; i++)
            {
                String p = this.players[i].Name;
                switch (p)
                {
                case "AIQ":
                    agents[i] = new QAgent(i);
                    if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N"))
                    {
                        ((QAgent)agents[i]).Load("TrainingData");
                        ((QAgent)agents[i]).TurnOffExploration();
                        ((QAgent)agents[i]).TurnOffLearning();
                    }
                    //this.players[i].Name = "AI " + n;
                    n++;
                    break;

                case "AIMQ":
                    agents[i] = new MemoryQAgent(i);
                    if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N"))
                    {
                        ((MemoryQAgent)agents[i]).Load("TrainingData");
                        ((MemoryQAgent)agents[i]).TurnOffExploration();
                    }
                    //this.players[i].Name = "AI " + n;
                    n++;
                    break;

                case "AIMinimax":
                    agents[i] = new MinimaxAgent(4, i);
                    //this.players[i].Name = "AI " + n;
                    n++;
                    break;

                case "AIMiniMaxMix":
                    if (File.Exists("TrainingData.Q"))
                    {
                        agents[i] = new MiniMaxMixAgent("TrainingData", 2, i);
                    }
                    else
                    {
                        agents[i] = new BruteForceAgent(i);
                    }
                    //this.players[i].Name = "AI " + n;
                    n++;
                    break;

                case "AIMixed":
                    agents[i] = new MixedAgent(0.5, false, i);
                    //this.players[i].Name = "AI " + n;
                    n++;
                    break;

                case "AIBrute":
                    agents[i] = new BruteForceAgent(i);
                    //this.players[i].Name = "AI " + n;
                    n++;
                    break;

                case "AIRandom":
                    agents[i] = new RandomAgent(i);
                    //this.players[i].Name = "AI " + n;
                    n++;
                    break;

                case "AISimple":
                    agents[i] = new SimpleAgent(i);
                    //this.players[i].Name = "AI " + n;
                    n++;
                    break;
                }
            }

            message = this.players[1].Name + "'s turn";

            /*colors = new Color[virus.Players + 1];
             * colors[0] = Color.White;
             * colors[1] = Color.FromArgb(128, 160, 255);
             * colors[2] = Color.FromArgb(96, 255, 96);
             * if(virus.Players > 2)
             *      colors[3] = Color.FromArgb(255, 96, 96);
             * if(virus.Players > 3)
             *      colors[4] = Color.FromArgb(255, 255, 64);
             *
             * for (int i = 5; i <= virus.Players; i++)
             *      colors[i] = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));*/
        }
Exemplo n.º 11
0
 void Awake()
 {
     agent = GetComponent <SimpleAgent>();
     Do();
 }