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

Commit b4f36e2

Browse files
authored
Merge pull request #63 from THU-ASTA/develop
Develop
2 parents a711c5f + b037009 commit b4f36e2

File tree

5 files changed

+78
-32
lines changed

5 files changed

+78
-32
lines changed

Config.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
vehicles:
2+
A:
3+
locator:
4+
hue:
5+
item1: 100
6+
item2: 150
7+
saturation:
8+
item1: 100
9+
item2: 255
10+
value:
11+
item1: 100
12+
item2: 255
13+
minArea: 4
14+
showMask: true
15+
serialPort: ''
16+
baudrate: 115200
17+
B:
18+
locator:
19+
hue:
20+
item1: 0
21+
item2: 50
22+
saturation:
23+
item1: 200
24+
item2: 255
25+
value:
26+
item1: 100
27+
item2: 255
28+
minArea: 4
29+
showMask: false
30+
serialPort: ''
31+
baudrate: 115200
32+
camera: 0

Source/MainWindow.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public partial class MainWindow : Form
3333
Locator = new LocatorConfigType
3434
{
3535
Hue = (100, 150),
36-
Saturation = (200, 255),
36+
Saturation = (100, 255),
3737
Value = (100, 255),
3838
MinArea = 4M
3939
},
@@ -49,7 +49,7 @@ public partial class MainWindow : Form
4949
Locator = new LocatorConfigType
5050
{
5151
Hue = (0, 50),
52-
Saturation = (200, 255),
52+
Saturation = (120, 255),
5353
Value = (100, 255),
5454
MinArea = 4M
5555
},
@@ -446,8 +446,7 @@ private void Communicate()
446446

447447

448448
// Send default packet.
449-
// Only send if the serial port is not writing and the count of orders is not zero.
450-
if (this._serialPortDict[camp].BytesToWrite == 0 && this._game.OrderList.Count > 0)
449+
if (this._serialPortDict[camp].BytesToWrite == 0)
451450
{
452451
// Get the order in delivery list.
453452
var orderInDeliveryList = new List<Order>();
@@ -459,14 +458,17 @@ private void Communicate()
459458
}
460459
}
461460

461+
// If the order list is empty, the latestPendingOrder will be null, which won't be added to the bytes of PacketGetStatusHost
462+
Order latestPendingOrder = (this._game.OrderList.Count > 0 ? this._game.OrderList[this._game.OrderList.Count] : null);
463+
462464
var packet = new PacketGetStatusHost(
463465
gameStatus: this._game.GameState,
464466
gameTime: this._game.GameTime.GetValueOrDefault(0),
465467
score: (double)this._game.Score[camp],
466468
vehiclePosition: this._game.Vehicle[camp].Position.GetValueOrDefault(new Dot(0, 0)),
467469
remainingDistance: this._game.Vehicle[camp].RemainingDistance,
468470
orderInDeliveryList: orderInDeliveryList,
469-
latestPendingOrder: this._game.OrderList[this._game.OrderList.Count - 1]
471+
latestPendingOrder: latestPendingOrder
470472
);
471473

472474
var bytesToWrite = packet.GetBytes();

Source/Order.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public OrderStatusType Status
8989
private long? _departureTime = null;
9090
private Dot _destinationPosition;
9191
private long _generationTime;
92-
private int _id = Utility.GenerateUniqueId();
92+
private int _id;
9393
private OrderStatusType _status = OrderStatusType.Ungenerated;
9494

9595
#endregion
@@ -128,19 +128,21 @@ public static Order GenerateRandomOrder(
128128
}
129129

130130
/// <summary>
131-
/// Construct an Order object.
131+
/// Constructs an Order object.
132132
/// </summary>
133133
/// <param name="departurePosition">The departure position</param>
134134
/// <param name="destinationPosition">The destination position</param>
135135
/// <param name="generationTime">The generation time</param>
136136
/// <param name="deliveryTimeLimit">The delivery time limit</param>
137-
/// <param name="commission">The commission.</param>
137+
/// <param name="commission">The commission</param>
138+
/// <param name="id">The id</param>
138139
public Order(
139140
Dot departurePosition,
140141
Dot destinationPosition,
141142
long generationTime,
142143
long deliveryTimeLimit,
143-
int commission
144+
int commission,
145+
int? id = null
144146
)
145147
{
146148
// Validate the delivery time limit
@@ -154,6 +156,7 @@ int commission
154156
this._generationTime = generationTime;
155157
this._deliveryTimeLimit = deliveryTimeLimit;
156158
this._commission = commission;
159+
this._id = id.GetValueOrDefault(Utility.GenerateUniqueId());
157160
}
158161

159162
/// <summary>

Source/PacketGetStatusHost.cs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ public PacketGetStatusHost(byte[] bytes)
129129

130130
public override byte[] GetBytes()
131131
{
132+
// Used to judge whether the lastest pending order is null, if not, the length of byte array will be added with 32;
133+
bool lastestPendingOrderIsNull = (this._latestPendingOrder == null);
134+
132135
var data = new byte[
133136
1 + 8 + 8 + 8 + 4 +
134-
(4 + 28 * this._orderInDeliveryList.Count) + 28
137+
(4 + 32 * this._orderInDeliveryList.Count) + 32 * Convert.ToInt32(!lastestPendingOrderIsNull)
135138
];
136139

137140
int index = 0;
@@ -208,32 +211,37 @@ public override byte[] GetBytes()
208211
}
209212
#endregion
210213

214+
211215
#region The latest pending order.
212-
#region The departure position.
213-
// The x.
214-
BitConverter.GetBytes(this._latestPendingOrder.DeparturePosition.X).CopyTo(data, index);
215-
index += 4;
216-
// The y.
217-
BitConverter.GetBytes(this._latestPendingOrder.DeparturePosition.Y).CopyTo(data, index);
218-
index += 4;
219-
#endregion
216+
if (!lastestPendingOrderIsNull)
217+
{
218+
#region The departure position.
220219

221-
#region The destination position.
222-
// The x.
223-
BitConverter.GetBytes(this._latestPendingOrder.DestinationPosition.X).CopyTo(data, index);
224-
index += 4;
225-
// The y.
226-
BitConverter.GetBytes(this._latestPendingOrder.DestinationPosition.Y).CopyTo(data, index);
227-
index += 4;
228-
#endregion
220+
// The x.
221+
BitConverter.GetBytes(this._latestPendingOrder.DeparturePosition.X).CopyTo(data, index);
222+
index += 4;
223+
// The y.
224+
BitConverter.GetBytes(this._latestPendingOrder.DeparturePosition.Y).CopyTo(data, index);
225+
index += 4;
226+
#endregion
229227

230-
// The delivery time limit.
231-
BitConverter.GetBytes(this._latestPendingOrder.DeliveryTimeLimit).CopyTo(data, index);
232-
index += 8;
228+
#region The destination position.
229+
// The x.
230+
BitConverter.GetBytes(this._latestPendingOrder.DestinationPosition.X).CopyTo(data, index);
231+
index += 4;
232+
// The y.
233+
BitConverter.GetBytes(this._latestPendingOrder.DestinationPosition.Y).CopyTo(data, index);
234+
index += 4;
235+
#endregion
233236

234-
// The order ID.
235-
BitConverter.GetBytes(this._latestPendingOrder.Id).CopyTo(data, index);
236-
index += 4;
237+
// The delivery time limit.
238+
BitConverter.GetBytes(this._latestPendingOrder.DeliveryTimeLimit).CopyTo(data, index);
239+
index += 8;
240+
241+
// The order ID.
242+
BitConverter.GetBytes(this._latestPendingOrder.Id).CopyTo(data, index);
243+
index += 4;
244+
}
237245
#endregion
238246

239247
// Generate the header.

Source/Utility.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static long SystemTime
2929

3030
#region Private fields.
3131

32+
// Note that static local variables are not permitted in C#.
3233
private static int _lastUniqueId = 0;
3334

3435
#endregion

0 commit comments

Comments
 (0)