Skip to content

Commit

Permalink
Merge pull request #40 from nitkagoshima-sysken/bot
Browse files Browse the repository at this point in the history
[Release] Bot 2.8.0
  • Loading branch information
SeitaHigashi committed Jul 7, 2018
2 parents 3cfc88e + 44d27c4 commit 1bb197e
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 78 deletions.
44 changes: 32 additions & 12 deletions Bot/Bot.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using nitkagoshima_sysken.Procon29.Visualizer;
using nitkagoshima_sysken.Procon29.Visualizer;

namespace nitkagoshima_sysken
{
Expand Down Expand Up @@ -47,15 +41,41 @@ public void Question(Calc calc)
/// エージェントを動かしたときに、状態がどう変化するか計算します。
/// </summary>
/// <param name="action">どうエージェントが動くか指定します。</param>
/// <param name="take">ほしい情報を指定します。</param>
/// <returns></returns>
public int Simulate(AgentActivityData[,] action, Func<Team, int> take)
/// <returns>エージェントを動かしたときの計算データが返ってきます。</returns>
public Calc Simulate(AgentActivityData[,] action)
{
Calc.MoveAgent(action);
int p = take(Team);
var c = (Calc)Calc.DeepCopy();
Calc.Undo();
return p;
return c;
}

/// <summary>
/// エージェントを動かしたときに、状態がどう変化するか計算します。
/// </summary>
/// <param name="action">どうエージェントが動くか指定します。</param>
/// <returns>エージェントを動かしたときの計算データが返ってきます。</returns>
public Calc Simulate(Team team, AgentActivityData[] action)
{
Calc.MoveAgent(team, action);
var c = (Calc)Calc.DeepCopy();
Calc.Undo();
return c;
}

/// <summary>
/// エージェントを動かしたときに、状態がどう変化するか計算します。
/// </summary>
/// <param name="action">どうエージェントが動くか指定します。</param>
/// <returns>エージェントを動かしたときの計算データが返ってきます。</returns>
public Calc Simulate(Team team, AgentNumber agentNumber, AgentActivityData action)
{
Calc.MoveAgent(team, agentNumber, action);
var c = (Calc)Calc.DeepCopy();
Calc.Undo();
return c;
}

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Bot/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 以下のように '*' を使用します:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.7.1")]
[assembly: AssemblyFileVersion("1.1.7.1")]
[assembly: AssemblyVersion("1.2.8.0")]
[assembly: AssemblyFileVersion("1.2.8.0")]
34 changes: 21 additions & 13 deletions Bot/readme.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# Procon29 Bot 1.1
# Procon29 Bot 2.8.0

## What's new (ver. 1.1)
## What's new (ver. 2.8.0)

### ASCの変更

`SucceededInRemoveingOurTile``SucceededInRemovingOurTile`に変更された
`SucceededInRemoveingOpponentTile``SucceededInRemovingOpponentTile`に変更された
`FailedInMovingByUnkownError`がASC992に変更された
`FailedInRemovingOurTileByUnkownError`がASC993に変更された
`FailedInRemovingOpponentTileByUnkownError`がASC994に変更された
`FailedInMovingByBeingNotChebyshevNeighborhood``FailedInMovingByBeingNotMooreNeighborhood`に変更された
`FailedInRemovingOurTileByBeingNotChebyshevNeighborhood``FailedInRemovingOurTileByBeingNotMooreNeighborhood`に変更された
`FailedInRemovingOpponentTileByBeingNotChebyshevNeighborhood``FailedInRemovingOpponentTileByBeingNotMooreNeighborhood`に変更された
### Visualier 8.0 に対応した

## What's new

### ボットを作れるようになった
### ver. 0.7.0

- ボットを作れるようになった

### ver. 1.7.1

- `SucceededInRemoveingOurTile``SucceededInRemovingOurTile`に変更された
- `SucceededInRemoveingOpponentTile``SucceededInRemovingOpponentTile`に変更された
- `FailedInMovingByUnkownError`がASC992に変更された
- `FailedInRemovingOurTileByUnkownError`がASC993に変更された
- `FailedInRemovingOpponentTileByUnkownError`がASC994に変更された
- `FailedInMovingByBeingNotChebyshevNeighborhood``FailedInMovingByBeingNotMooreNeighborhood`に変更された
- `FailedInRemovingOurTileByBeingNotChebyshevNeighborhood``FailedInRemovingOurTileByBeingNotMooreNeighborhood`に変更された
- `FailedInRemovingOpponentTileByBeingNotChebyshevNeighborhood``FailedInRemovingOpponentTileByBeingNotMooreNeighborhood`に変更された

### ver. 2.8.0

- Visualier 8.0 に対応した
128 changes: 82 additions & 46 deletions TegetegeBot/TegetegeBot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Drawing;
using System;
using System.Drawing;
using System.Linq;
using nitkagoshima_sysken.Procon29.Visualizer;

namespace nitkagoshima_sysken
Expand All @@ -9,7 +11,9 @@ namespace TegetegeBot
{
/// <summary>
/// テスト用プログラム
/// ちなみにこのボットは、いかなるときも(0,0)へ移動しようとするボットだった。
/// このボットは、
/// エージェントの周りのマスに行ってみて、
/// その中で一番、得点が高かったマスを計算するボットです。
/// </summary>
class TegetegeBot : Bot.Bot
{
Expand All @@ -27,60 +31,92 @@ public TegetegeBot() : base() { }
public override AgentActivityData[] Answer()
{
var result = new AgentActivityData[2];
var a1mp = -100;
var a2mp = -100;
Point ap1 = new Point();
Point ap2 = new Point();
for (int x = 0; x < Calc.Field.Width(); x++)

// 一人目のエージェントの最高得点を保存するために使う変数
var agnt1maxp = -16;
// 二人目のエージェントの最高得点を保存するために使う変数
var agnt2maxp = -16;
// 一人目のエージェントがどこに行くかを保存するために使う変数
Coordinate agnt1pos = new Coordinate();
// 二人目のエージェントがどこに行くかを保存するために使う変数
Coordinate agnt2pos = new Coordinate();

/*
* これはクエリ式というもので、
* まるで、データベースで使うSQL文のようにデータを扱えるようになっている
* var list =
* エージェントが行けるマスをリストにする変数をここで宣言している。
* from cell in Calc.Field
* 《from句》どのデータテーブルからデータを読むか
* 今回の場合は、「Calcのフィールドから、マスを一つずつ取り出して、それにcellという名前をつける」
* where cell.Coordinate.ChebyshevDistance(Calc.Agents[Team, AgentNumber.One].Position) == 1
* 《where句》取り出したいデータに対する条件
* 今回の場合は、「取り出したマス(cell)の座標から一人目のエージェントのいる場所までのチェビシェフ距離がちょうど1なら条件に適している」
* (つまり、エージェントの隣のマスなら条件に適している)
* select cell.Coordinate;
* 《select句》条件にヒットしたデータの何を取り出すか
* 今回の場合は、条件にヒットしたマス(つまり、エージェントの隣のマス)の座標を取り出して、それをリスト化する
*
* …つまり、この行では、一人目のエージェントの隣のマスの一覧をリストにしている。
* C#のクエリ式についてはネットで調べれば、もっと詳しく載っているので、そちらを参照した方がいい。
*/
var list =
from cell in Calc.Field
where cell.Coordinate.ChebyshevDistance(Calc.Agents[Team, AgentNumber.One].Position) == 1
select cell.Coordinate;
// 取り出したリストから一つずつ座標を取り出して、for文のように繰り返し処理を行う。
foreach (var coordinate in list)
{
for (int y = 0; y < Calc.Field.Height(); y++)
var trying = new AgentActivityData[2]
{
var trying = new AgentActivityData[2, 2];
var otherteam = (Team == Team.A) ? Team.B : Team.A;

// Bot側のチーム、1人目のエージェントが(x,y)に移動する
trying[(int)Team, (int)AgentNumber.One] = new AgentActivityData(AgentStatusCode.RequestMovement, new Point(x, y));
// Bot側のチーム、1人目のエージェントがcoordinateに移動する
new AgentActivityData(AgentStatusCode.RequestMovement, coordinate),
// Bot側のチーム、2人目のエージェントは何もしない
trying[(int)Team, (int)AgentNumber.Two] = new AgentActivityData(AgentStatusCode.RequestNotToDoAnything, new Point());
// 敵側のチーム、1人目のエージェントは何もしない
trying[(int)otherteam, (int)AgentNumber.One] = new AgentActivityData(AgentStatusCode.RequestNotToDoAnything, new Point());
// 敵側のチーム、2人目のエージェントは何もしない
trying[(int)otherteam, (int)AgentNumber.Two] = new AgentActivityData(AgentStatusCode.RequestNotToDoAnything, new Point());
var p = Simulate(action: trying, take: Calc.TotalPoint);
new AgentActivityData(AgentStatusCode.RequestNotToDoAnything)
};

if (Calc.AgentPosition[(int)Team, 0].ChebyshevDistance(new Point(x, y)) != 1) continue;
// 今までの中で一番、得点が高かったら、ap1の座標を更新する
if (a1mp < p)
{
a1mp = p;
ap1 = new Point(x, y);
}
/*
* Simulate関数
* これはもしもそこへ行ったらどうなるかをシミュレートしてくれる関数です。
*/
var c = Simulate(team: Team, action: trying);

// 今までの中で一番、得点が高かったら、得点とその座標を更新する
if (agnt1maxp < c.TotalPoint(Team))
{
agnt1maxp = c.TotalPoint(Team);
agnt1pos = new Coordinate(coordinate);
}
}
// Bot側のチーム、1人目のエージェントがap1に行くことが確定する
result[0] = new AgentActivityData(AgentStatusCode.RequestMovement, ap1);
for (int x = 0; x < Calc.Field.Width(); x++)
{
for (int y = 0; y < Calc.Field.Height(); y++)
{
var trying = new AgentActivityData[2, 2];
var otherteam = (Team == Team.A) ? Team.B : Team.A;
// Bot側のチーム、1人目のエージェントがagnt1posに行くことが確定する
result[(int)AgentNumber.One] = new AgentActivityData(AgentStatusCode.RequestMovement, agnt1pos);

trying[(int)Team, (int)AgentNumber.One] = new AgentActivityData(AgentStatusCode.RequestNotToDoAnything, new Point());
trying[(int)Team, (int)AgentNumber.Two] = new AgentActivityData(AgentStatusCode.RequestMovement, new Point(x, y));
trying[(int)otherteam, (int)AgentNumber.One] = new AgentActivityData(AgentStatusCode.RequestNotToDoAnything, new Point());
trying[(int)otherteam, (int)AgentNumber.Two] = new AgentActivityData(AgentStatusCode.RequestNotToDoAnything, new Point());
var p = Simulate(action: trying, take: Calc.TotalPoint);
/*
* 実は、エージェントの場所から1ターンでいける範囲は、
* Arrowを使ってもっと簡単に実装できます。
* Arrowはenum型で、
* Arrow.Up で 上に行く
* Arrow.Rightで 右に行く
* とかできます。
* foreach (Arrow arrow in Enum.GetValues(typeof(Arrow)))
* で、Arrowのすべての要素を一つずつ実行できるので、
* エージェントのいるところから、周り1マス分のマスに関して、
* すべてシミュレーションできます。
*/
foreach (Arrow arrow in Enum.GetValues(typeof(Arrow)))
{
var c = Simulate(
Team,
AgentNumber.Two,
new AgentActivityData(AgentStatusCode.RequestMovement, Calc.Agents[Team, AgentNumber.Two].Position + arrow));

if (Calc.AgentPosition[(int)Team, 1].ChebyshevDistance(new Point(x, y)) != 1) continue;
if (a2mp < p)
{
a2mp = p;
ap2 = new Point(x, y);
}
if (agnt2maxp < c.TotalPoint(Team))
{
agnt2maxp = c.TotalPoint(Team);
agnt2pos = new Coordinate(Calc.Agents[Team, AgentNumber.Two].Position + arrow);
}
}
result[1] = new AgentActivityData(AgentStatusCode.RequestMovement, ap2);
result[(int)AgentNumber.Two] = new AgentActivityData(AgentStatusCode.RequestMovement, agnt2pos);
return result;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Visualizer/CreateNewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void SelectBotButton1_Click(object sender, EventArgs e)

foreach (System.Text.RegularExpressions.Match match in mc)
{
bot1 = Activator.CreateInstance(m.GetType("nitkagoshima_sysken.procon29_Competition." + match.Groups["file"].Value + "." + match.Groups["file"].Value));
bot1 = Activator.CreateInstance(m.GetType("nitkagoshima_sysken.Procon29." + match.Groups["file"].Value + "." + match.Groups["file"].Value));
MainForm.botName[1] = match.Groups["file"].Value;
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ private void SelectBotButton0_Click(object sender, EventArgs e)

foreach (System.Text.RegularExpressions.Match match in mc)
{
bot0 = Activator.CreateInstance(m.GetType("nitkagoshima_sysken.procon29_Competition." + match.Groups["file"].Value + "." + match.Groups["file"].Value));
bot0 = Activator.CreateInstance(m.GetType("nitkagoshima_sysken.Procon29." + match.Groups["file"].Value + "." + match.Groups["file"].Value));
MainForm.botName[0] = match.Groups["file"].Value;
}
}
Expand Down
6 changes: 3 additions & 3 deletions Visualizer/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class Field : IEnumerable<Cell>
/// </summary>
/// <returns>列挙されたセル</returns>
public IEnumerable<Cell> GetEnumerator()
{
{
foreach (Cell item in Cells)
{
yield return item;
}
}

/// <summary>
/// 列挙します
/// </summary>
Expand All @@ -45,7 +45,7 @@ IEnumerator<Cell> IEnumerable<Cell>.GetEnumerator()
yield return item;
}
}

/// <summary>
/// フィールドの幅を取得します。
/// </summary>
Expand Down

0 comments on commit 1bb197e

Please sign in to comment.