Skip to content

Commit

Permalink
add demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvees committed Jul 5, 2018
1 parent 26c2ec3 commit 960f6b6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
5 changes: 5 additions & 0 deletions api/API_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ ht<span></span>tp://106.75.33.221:6000/

[攻击单元](https://github.com/KevinYeti/MagCore/blob/master/api/Attack_CN.md)


## SDK & Demo
[C# SDK](https://github.com/KevinYeti/MagCore/tree/master/src/sdk/MagCore.Sdk)

[Demo AI](https://github.com/KevinYeti/MagCore/tree/master/src/sdk/JustRush)
Binary file removed src/sdk.rar
Binary file not shown.
13 changes: 11 additions & 2 deletions src/sdk/JustRush/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static void Main(string[] args)

static void RushAttack()
{
//create a thread to protect self
Task.Factory.StartNew(() =>
{
Thread.CurrentThread.IsBackground = true;
Expand All @@ -101,12 +102,19 @@ static void RushAttack()
foreach (var pos in self.Bases)
{
MapHelper.Attack(game.Id, self.Id, pos.X, pos.Y);
var siblings = pos.GetSiblings();
foreach (var sibling in siblings)
{
MapHelper.Attack(game.Id, self.Id, sibling.X, sibling.Y);
}
}
Thread.Sleep(3000);
}
});

//another thread to get the newest game info
Task.Factory.StartNew(() => {
Thread.CurrentThread.IsBackground = true;
Expand All @@ -118,6 +126,7 @@ static void RushAttack()
}
});

//main thread to rush more as much as possible
while (true)
{
if (game.State == 1)
Expand All @@ -129,7 +138,7 @@ static void RushAttack()
if (cell.Type != 0 && cell.State != 1
&& cell.OwnerIndex == self.Index) //means this cell is self's
{
var siblings = cell.GetSiblings();
var siblings = cell.Position.GetSiblings();
foreach (var pos in siblings)
{
var target = game.Locate(pos.X, pos.Y);
Expand All @@ -149,7 +158,7 @@ static void RushAttack()
break;
}

Thread.Sleep(1000);
Thread.Sleep(500);
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/sdk/MagCore.Sdk/Models/Cell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,5 @@ public Cell(int x, int y)
public int State { get; set; }

public int OwnerIndex { get; set; }

public List<Position> GetSiblings()
{
int x = Position.X;
int y = Position.Y;

List<Position> siblings = new List<Position>();
if (x >= 1)
siblings.Add(new Position(x - 1, y));
siblings.Add(new Position(x + 1, y));
if (y >= 1)
siblings.Add(new Position(x, y - 1));
siblings.Add(new Position(x, y + 1));

return siblings;
}
}
}
14 changes: 14 additions & 0 deletions src/sdk/MagCore.Sdk/Models/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,19 @@ public override string ToString()

public int X { get; set; }
public int Y { get; set; }

public List<Position> GetSiblings()
{
List<Position> siblings = new List<Position>();
if (X >= 1)
siblings.Add(new Position(X - 1, Y));
siblings.Add(new Position(X + 1, Y));
if (Y >= 1)
siblings.Add(new Position(X, Y - 1));
siblings.Add(new Position(X, Y + 1));

return siblings;
}

}
}

0 comments on commit 960f6b6

Please sign in to comment.