AI hat erste Anzeichen von I aus AI (Viel A, ein bisschen I)

This commit is contained in:
Wafa Sadri
2014-06-05 12:47:57 +02:00
parent 3107b7065b
commit 8cfdc1682e
2 changed files with 36 additions and 5 deletions

View File

@@ -1,23 +1,51 @@
using System; using System;
using System.Timers; using System.Timers;
using System.Collections.Generic;
namespace WorldOfPeacecraft namespace WorldOfPeacecraft
{ {
public class AI public class AI
{ {
Timer timer; private Timer timer;
bool challengeSomeone = false; private Random r;
private int decision;
private Backend Backend;
public AI () public AI (Backend b)
{ {
r = new Random ();
timer = new Timer (5000.0); timer = new Timer (5000.0);
timer.Elapsed += new ElapsedEventHandler (OnTimedEvent); timer.Elapsed += new ElapsedEventHandler (this.OnTimedEvent);
Backend = b;
timer.Start (); 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 <int, Player> 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 ();
} }
} }
} }

View File

@@ -21,6 +21,7 @@ namespace WorldOfPeacecraft
private AutoResetEvent InitializedEvent = new AutoResetEvent(false); private AutoResetEvent InitializedEvent = new AutoResetEvent(false);
private bool initialized = false; private bool initialized = false;
private Pathwalker Pathwalker = new Pathwalker(); private Pathwalker Pathwalker = new Pathwalker();
private AI ai;
public delegate void ChallengeEventHandler(Challenge c); public delegate void ChallengeEventHandler(Challenge c);
public event ChallengeEventHandler Challenge; public event ChallengeEventHandler Challenge;
@@ -40,6 +41,8 @@ namespace WorldOfPeacecraft
SenderBuffer.AddLine ("get:ents"); SenderBuffer.AddLine ("get:ents");
SenderBuffer.AddLine ("get:me"); SenderBuffer.AddLine ("get:me");
SenderBuffer.AddLine ("get:map"); SenderBuffer.AddLine ("get:map");
ai = new AI(this);
} }
public void SetSelfId (int id) public void SetSelfId (int id)