Skip to content

Commit

Permalink
Merge branch 'eesast:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamEnderKing authored Apr 24, 2024
2 parents ca5e537 + 829b7ce commit 064d3d9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 74 deletions.
27 changes: 7 additions & 20 deletions CAPI/cpp/API/src/AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include "constants.h"
// 注意不要使用conio.h,Windows.h等非标准库
// 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新,大致一帧更新一次
extern const bool asynchronous = true;
extern const bool asynchronous = false;

// 选手需要依次将player1到player4的船类型在这里定义
extern const std::array<THUAI7::ShipType, 4> ShipTypeDict = {
THUAI7::ShipType::MilitaryShip,
THUAI7::ShipType::CivilianShip,
THUAI7::ShipType::MilitaryShip,
THUAI7::ShipType::MilitaryShip,
THUAI7::ShipType::FlagShip,
};

Expand All @@ -22,36 +22,23 @@ void AI::play(IShipAPI& api)
{
if (this->playerID == 1)
{
// player1的操作
}
else if (this->playerID == 2)
{
while (true)
{
api.MoveDown(100);
std::this_thread::sleep_for(std::chrono::seconds(1));
api.MoveLeft(100);
api.PrintSelfInfo();
api.PrintShip();
api.Recover(10);
std::this_thread::sleep_for(std::chrono::seconds(1));
api.Attack(1.5);
}
// player2的操作
}

else if (this->playerID == 3)
{
// player3的操作
}
else if (this->playerID == 4)
{
api.MoveDown(100);
std::this_thread::sleep_for(std::chrono::seconds(1));
api.MoveLeft(100);
// player4的操作
}
}

void AI::play(ITeamAPI& api) // 默认team playerID 为0
{
api.PrintSelfInfo();
std::this_thread::sleep_for(std::chrono::seconds(1));
api.InstallModule(2, THUAI7::ModuleType::ModuleLaserGun);
// player0的操作
}
32 changes: 1 addition & 31 deletions CAPI/python/PyAPI/AI.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,12 @@ def __init__(self, pID: int):
def ShipPlay(self, api: IShipAPI) -> None:
# 公共操作
if self.__playerID == 1:
api.PrintSelfInfo()
api.MoveLeft(100)
time.sleep(1)
api.MoveRight(100)
time.sleep(1)
api.MoveDown(100)
time.sleep(1)
api.MoveUp(100)
time.sleep(1)
# player1的操作
return
elif self.__playerID == 2:
api.PrintSelfInfo()
api.MoveLeft(100)
time.sleep(1)
api.MoveRight(100)
time.sleep(1)
api.MoveDown(100)
time.sleep(1)
api.MoveUp(100)
time.sleep(1)
# player2的操作
return
elif self.__playerID == 3:
api.PrintSelfInfo()
api.MoveLeft(100)
time.sleep(1)
api.MoveRight(100)
time.sleep(1)
api.MoveDown(100)
time.sleep(1)
api.MoveUp(100)
time.sleep(1)
# player3的操作
return
elif self.__playerID == 4:
Expand All @@ -74,8 +47,5 @@ def ShipPlay(self, api: IShipAPI) -> None:
return

def TeamPlay(self, api: ITeamAPI) -> None:
assert self.__playerID == 0, "Team's playerID must be 0"
api.BuildShip(shipType=THUAI7.ShipType.MilitaryShip,birthIndex=0)
time.sleep(2)
# 操作
# player0的操作
return
2 changes: 1 addition & 1 deletion logic/Client/View/CircleLabel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
x:Class="Client.View.CircleLabel"
x:Name="this">
<Grid BindingContext="{x:Reference this}" Margin="{Binding CLMargin}">
<Ellipse HeightRequest="{Binding CLDiameter}" WidthRequest="{Binding CLDiameter}" BackgroundColor="{Binding CLBackgroundColor}" />
<Ellipse HeightRequest="{Binding CLDiameter}" WidthRequest="{Binding CLDiameter}" Fill="{Binding CLBackgroundColor}" Stroke="{Binding CLBackgroundColor}" />
<Label Text="{Binding CLText}" TextColor="{Binding CLTextColor}" FontSize="{Binding CLFontSize}" />
</Grid>
</ContentView>
9 changes: 4 additions & 5 deletions logic/Client/View/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public MainPage()
}

//timer = Dispatcher.CreateTimer();
//timer.Interval = TimeSpan.FromMilliseconds(500);
//timer.Interval = TimeSpan.FromMilliseconds(100);
//timer.Tick += new EventHandler(TestRefresh);
//timer.Start();

Expand All @@ -125,11 +125,10 @@ private void TestRefresh(object sender, EventArgs e)
{
lock (viewModel.drawPicLock)
{
for (int i = 0; i < viewModel.ShipCircList.Count; i++)
for (int i = 0; i < viewModel.numOfShips; i++)
{
System.Diagnostics.Debug.WriteLine(String.Format("ship{0}.xy=({1}, {2})", i, viewModel.ShipCircList[i].X, viewModel.ShipCircList[i].Y));
System.Diagnostics.Debug.WriteLine(String.Format("numOfShipCirc{0}", shipCirc.Count));
//shipCirc[i].Margin = XY2Margin(viewModel.ShipCircList[i].X, viewModel.ShipCircList[i].Y);
//viewModel.myLogger.LogInfo(String.Format("MainPage.xaml: ship{0}.Color - {1}", i, Convert.ToString(shipCirc[i].CLBackgroundColor)));
//viewModel.myLogger.LogInfo(String.Format("MainPage.xaml: ship{0}.Thick - {1}", i, Convert.ToString(shipCirc[i].CLMargin)));
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions logic/Client/ViewModel/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ private void Refresh(object sender, EventArgs e)
else BluePlayer.Ships.Add(ship);
BlueShipCount++;
}

//else
//{
// Ship ship = new Ship
Expand Down Expand Up @@ -584,8 +583,8 @@ private void Refresh(object sender, EventArgs e)
// RedPlayer.Ships[i] = ship;
// else RedPlayer.Ships.Add(ship);
//}
myLogger.LogInfo("============= Draw Ship list ================");
}
myLogger.LogInfo("============= Draw Ship list ================");

for (int i = 0; i < RedPlayer.Ships.Count; i++)
{
Expand Down Expand Up @@ -709,7 +708,7 @@ private void UpdateTest(object sender, EventArgs e)

public readonly int ShipStatusAttributesFontSize = 13;

Logger myLogger;
public Logger myLogger;

public GeneralViewModel()
{
Expand Down
28 changes: 14 additions & 14 deletions logic/Client/ViewModel/MapViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,44 +273,44 @@ private void DrawShip()
for (int i = 0; i < listOfShip.Count; i++)
{
MessageOfShip data = listOfShip[i];
DrawCircLabel shipinfo = ShipCircList[i];
//DrawCircLabel shipinfo = ShipCircList[i];
PointF point = UtilFunctions.Grid2CellPoint(data.X, data.Y);
shipinfo.X = point.X;
shipinfo.Y = point.Y;
myLogger.LogInfo(String.Format("shipinfo.X:{0}", shipinfo.X));
myLogger.LogInfo(String.Format("shipinfo.Y:{0}", shipinfo.Y));
ShipCircList[i].X = point.X;
ShipCircList[i].Y = point.Y;
myLogger.LogInfo(String.Format("shipinfo.X:{0}", ShipCircList[i].X));
myLogger.LogInfo(String.Format("shipinfo.Y:{0}", ShipCircList[i].Y));
long team_id = data.TeamId;
myLogger.LogInfo(String.Format("shipTeamid{0}", team_id));
switch (team_id)
{
case 0:
myLogger.LogInfo("shipinfo.color = red");
shipinfo.Color = Colors.DarkRed;
ShipCircList[i].Color = Colors.DarkRed;
break;

case 1:
myLogger.LogInfo("shipinfo.color = blue");

shipinfo.Color = Colors.DarkBlue;
ShipCircList[i].Color = Colors.DarkBlue;
break;

default:
myLogger.LogInfo("shipinfo.color = black");

shipinfo.Color = Colors.DarkGreen;
ShipCircList[i].Color = Colors.DarkGreen;
break;
}
//shipinfo.Radius = 4.5F;
//shipinfo.FontSize = 5.5F;
//shipinfo.TextColor = Colors.White;
//ShipCircList.Add(shipinfo);
}
for (int i = 0; i < ShipCircList.Count; i++)
{
myLogger.LogInfo(String.Format("DrawnShip{0}.X:{1}", i, ShipCircList[i].X));
myLogger.LogInfo(String.Format("DrawnShip{0}.Y:{1}", i, ShipCircList[i].Y));
myLogger.LogInfo(String.Format("DrawnShip{0}.Color:{1}", i, ShipCircList[i].Color));
}
//for (int i = 0; i < ShipCircList.Count; i++)
//{
// myLogger.LogInfo(String.Format("DrawnShip{0}.X:{1}", i, ShipCircList[i].X));
// myLogger.LogInfo(String.Format("DrawnShip{0}.Y:{1}", i, ShipCircList[i].Y));
// myLogger.LogInfo(String.Format("DrawnShip{0}.Color:{1}", i, ShipCircList[i].Color));
//}
}

private void DrawBullet()
Expand Down

0 comments on commit 064d3d9

Please sign in to comment.