diff --git a/src/AI.cs b/src/AI.cs index 6a6e7d6..a63f759 100644 --- a/src/AI.cs +++ b/src/AI.cs @@ -1,23 +1,51 @@ using System; using System.Timers; +using System.Collections.Generic; + namespace WorldOfPeacecraft { public class AI { - Timer timer; - bool challengeSomeone = false; + private Timer timer; + private Random r; + private int decision; + private Backend Backend; - public AI () + public AI (Backend b) { + r = new Random (); timer = new Timer (5000.0); - timer.Elapsed += new ElapsedEventHandler (OnTimedEvent); + timer.Elapsed += new ElapsedEventHandler (this.OnTimedEvent); + Backend = b; + timer.Start (); } - private static void OnTimedEvent(object source, ElapsedEventArgs e) + private void OnTimedEvent(object source, ElapsedEventArgs e) { + think (); + } + private void think() + { + timer.Stop (); + if (r.Next (0, 2) == 0) { + Console.WriteLine ("Challenging someone"); + lock (Backend) { + Dictionary playerlist; + Player player; + int x, y; + playerlist = Backend.getPlayerList (); + player = playerlist[2235]; + x = player.GetX (); + y = player.GetY (); + Backend.MoveTo (x, y); + } + } else { + Console.WriteLine ("Waiting for someone"); + } + timer.Start (); } } } diff --git a/src/Backend.cs b/src/Backend.cs index f2d30ff..46da47f 100644 --- a/src/Backend.cs +++ b/src/Backend.cs @@ -21,6 +21,7 @@ namespace WorldOfPeacecraft private AutoResetEvent InitializedEvent = new AutoResetEvent(false); private bool initialized = false; private Pathwalker Pathwalker = new Pathwalker(); + private AI ai; public delegate void ChallengeEventHandler(Challenge c); public event ChallengeEventHandler Challenge; @@ -40,6 +41,8 @@ namespace WorldOfPeacecraft SenderBuffer.AddLine ("get:ents"); SenderBuffer.AddLine ("get:me"); SenderBuffer.AddLine ("get:map"); + + ai = new AI(this); } public void SetSelfId (int id)