Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Commit 82532a5

Browse files
authored
Merge pull request #58 from THU-ASTA/develop
Fix bugs
2 parents b6def57 + ef25787 commit 82532a5

File tree

5 files changed

+77
-50
lines changed

5 files changed

+77
-50
lines changed

Source/ChargingPile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public ChargingPile(
5555
/// </returns>
5656
public bool IsInInfluenceScope(Dot position)
5757
{
58-
return ((decimal)Dot.Distance(position, this._position) <
58+
return ((decimal)Dot.Distance(position, this._position) <=
5959
this._influenceScopeRadius);
6060
}
6161

Source/Game.cs

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ public static readonly (int Min, int Max) BarrierSideLengthRange = (
132132

133133
#region Parameters related to the charging piles.
134134

135+
/// <summary>
136+
/// The max number of charging piles of a camp.
137+
/// </summary>
138+
public const int ChargingPileMaxNumber = 3;
139+
135140
/// <summary>
136141
/// The increasing rate of the max distances of vehicles in the influence
137142
/// scope of their own charging piles in centimeter per second.
@@ -168,7 +173,7 @@ public static readonly (int Min, int Max) BarrierSideLengthRange = (
168173
/// The range of the delivery durations of orders.
169174
/// </summary>
170175
public static readonly (long Min, long Max) OrderDeliveryDurationRange = (
171-
20, 60
176+
20000, 60000
172177
);
173178

174179
/// <summary>
@@ -594,6 +599,26 @@ public void SetChargingPile()
594599
return;
595600
}
596601

602+
// Avoid setting too many charging piles.
603+
int chargingPileNumber = 0;
604+
foreach (var chargingPile in this._chargingPileList)
605+
{
606+
if (chargingPile.Camp == this._camp)
607+
{
608+
++chargingPileNumber;
609+
}
610+
}
611+
if (chargingPileNumber > Game.ChargingPileMaxNumber)
612+
{
613+
return;
614+
}
615+
616+
// Can only set charging piles in the first half.
617+
if (this._gameStage != GameStageType.FirstHalf)
618+
{
619+
return;
620+
}
621+
597622
this._chargingPileList.Add(new ChargingPile(
598623
(CampType)this._camp,
599624
(Dot)this._vehicle[(CampType)this._camp].Position,
@@ -859,57 +884,54 @@ void TakeAndDeliverOrder()
859884

860885
var vehiclePosition = (Dot)vehicle.Position;
861886

862-
// The vehicle should park there for at least 0ms.
863-
if (vehicle.ParkingDuration >= 0)
887+
888+
// Count the orders in delivery.
889+
var deliveringOrderNumber = 0;
890+
foreach (var order in this._orderList)
864891
{
865-
// Count the orders in delivery.
866-
var deliveringOrderNumber = 0;
867-
foreach (var order in this._orderList)
892+
if (order.Status == OrderStatusType.InDelivery)
868893
{
869-
if (order.Status == OrderStatusType.InDelivery)
870-
{
871-
++deliveringOrderNumber;
872-
}
894+
++deliveringOrderNumber;
873895
}
896+
}
874897

875-
foreach (var order in this._orderList)
898+
foreach (var order in this._orderList)
899+
{
900+
// Take orders.
901+
if (order.Status == OrderStatusType.Pending)
876902
{
877-
// Take orders.
878-
if (order.Status == OrderStatusType.Pending)
903+
// Check if the capacity is full.
904+
if (deliveringOrderNumber > Game.OrderDeliveryCapacity)
879905
{
880-
// Check if the capacity is full.
881-
if (deliveringOrderNumber > Game.OrderDeliveryCapacity)
882-
{
883-
continue;
884-
}
906+
continue;
907+
}
885908

886-
if ((decimal)Dot.Distance(order.DeparturePosition, vehiclePosition)
887-
<= Game.OrderContactScopeRadius)
888-
{
889-
order.Take((long)this.GameTime);
909+
if ((decimal)Dot.Distance(order.DeparturePosition, vehiclePosition)
910+
<= Game.OrderContactScopeRadius)
911+
{
912+
order.Take((long)this.GameTime);
890913

891-
// Play the take sound.
892-
Game.OrderSoundTake.Play();
893-
}
914+
// Play the take sound.
915+
Game.OrderSoundTake.Play();
894916
}
895-
else if (order.Status == OrderStatusType.InDelivery)
917+
}
918+
else if (order.Status == OrderStatusType.InDelivery)
919+
{
920+
if ((decimal)Dot.Distance(order.DestinationPosition, vehiclePosition)
921+
<= Game.OrderContactScopeRadius)
896922
{
897-
if ((decimal)Dot.Distance(order.DestinationPosition, vehiclePosition)
898-
<= Game.OrderContactScopeRadius)
899-
{
900-
order.Deliver((long)this.GameTime);
923+
order.Deliver((long)this.GameTime);
901924

902-
if (order.OvertimeDuration == null)
903-
{
904-
throw new Exception("The overtime duration of the order is null.");
905-
}
925+
if (order.OvertimeDuration == null)
926+
{
927+
throw new Exception("The overtime duration of the order is null.");
928+
}
906929

907-
this._score[(CampType)this._camp] +=
908-
Math.Max(order.Commission + Game.ScoreDeliveryOvertimeRate * (long)order.OvertimeDuration, 0);
930+
this._score[(CampType)this._camp] +=
931+
Math.Max(order.Commission + Game.ScoreDeliveryOvertimeRate * (long)order.OvertimeDuration, 0);
909932

910-
// Player the deliver sound.
911-
Game.OrderSoundDeliver.Play();
912-
}
933+
// Player the deliver sound.
934+
Game.OrderSoundDeliver.Play();
913935
}
914936
}
915937
}

Source/MainWindow.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ public MainWindow()
180180
InitializeComponent();
181181

182182
// Initialize the label texts
183-
this.labelScoreVehicleA.Text = "0.000";
184-
this.labelScoreVehicleB.Text = "0.000";
185-
this.labelGameTime.Text = "0.00";
183+
this.labelScoreVehicleA.Text = "N/A";
184+
this.labelScoreVehicleB.Text = "N/A";
185+
this.labelGameTime.Text = "N/A";
186186
this.labelGameHalf.Text = "Pre-match";
187187

188188
// Resize icons
@@ -809,6 +809,11 @@ private void buttonEnd_Click(object sender, EventArgs e)
809809
private void buttonReset_Click(object sender, EventArgs e)
810810
{
811811
this._game = new Game();
812+
813+
this.labelScoreVehicleA.Text = "N/A";
814+
this.labelScoreVehicleB.Text = "N/A";
815+
this.labelGameTime.Text = "N/A";
816+
this.labelGameHalf.Text = "Pre-match";
812817
}
813818

814819
private void buttonFoul_Click(object sender, EventArgs e)

Source/PacketGetGameInformationHost.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public PacketGetGameInformationHost(byte[] bytes)
4646
int currentIndex = 0;
4747

4848
// Gamestage
49-
this._gameStage = (GameStageType)BitConverter.ToInt32(data, currentIndex);
50-
currentIndex += 4;
49+
this._gameStage = (GameStageType)(data[currentIndex]);
50+
currentIndex += 1;
5151

5252
// Obstacle data
5353
int barrierListLength = BitConverter.ToInt32(data, currentIndex);
@@ -94,7 +94,7 @@ public override byte[] GetBytes()
9494
{
9595
// Compute the length of the data
9696
int dataLength = (
97-
1 * 4 + // this._currentGameStage
97+
1 + // this._currentGameStage
9898
4 + // this._obstacleListLength
9999
this._barrierList.Count * 16 +
100100
1 * 8 + // this._duration
@@ -110,8 +110,8 @@ public override byte[] GetBytes()
110110

111111

112112
// Gamestage
113-
BitConverter.GetBytes((int)this._gameStage).CopyTo(data, currentIndex);
114-
currentIndex += 4;
113+
BitConverter.GetBytes((byte)this._gameStage).CopyTo(data, currentIndex);
114+
currentIndex += 1;
115115

116116
// Barrier
117117
BitConverter.GetBytes(this._barrierList.Count).CopyTo(data, currentIndex);
@@ -167,7 +167,7 @@ public override byte[] GetBytes()
167167

168168
return bytes;
169169
}
170-
170+
171171
public override byte GetPacketId()
172172
{
173173
return PacketGetGameInformationHost.PacketId;

Source/PacketSetChargingPileSlave.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public PacketSetChargingPileSlave(byte[] bytes)
5353

5454
public override byte[] GetBytes()
5555
{
56-
var data = new byte[8];
56+
var data = new byte[0];
5757

5858
var header = Packet.GeneratePacketHeader(PacketSetChargingPileSlave.PacketId, data);
5959

0 commit comments

Comments
 (0)