-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
60 lines (51 loc) · 1.98 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using EscapeFromTheWoods;
namespace EscapeFromTheWoods
{
class Program
{
static async Task Main(string[] args)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
Console.WriteLine("Escape From The Woods");
// MongoDB connection string
string connectionString = "mongodb://localhost:27017";
DBwriter db = new DBwriter(connectionString);
string path = @"C:\Users\Ok\Desktop\HoGent\Specialisatie\Evals\EscapeFromTheWoods\EscapeGitTwee\bitmaps"; // Update the path as needed
// Create the maps
Map m1 = new Map(0, 500, 0, 500);
Map m2 = new Map(0, 200, 0, 200);
Map m3 = new Map(0, 400, 0, 400);
// parallel
var woodTasks = new List<Task<Wood>>
{
Task.Run(() => WoodBuilder.GetWood(10000, m1, path, db)),
Task.Run(() => WoodBuilder.GetWood(10000, m2, path, db)),
Task.Run(() => WoodBuilder.GetWood(10000, m3, path, db))
};
while (woodTasks.Count > 0)
{
Task<Wood> finishedTask = await Task.WhenAny(woodTasks);
woodTasks.Remove(finishedTask);
Wood wood = await finishedTask;
wood.PlaceMonkey("Alice", IDgenerator.GetMonkeyID());
wood.WriteWoodToDB();
await wood.Escape(); // Now awaiting the escape process here
}
stopwatch.Stop();
db.WriteLogRecord(new DBLogRecord
{
woodID = 0,
monkeyID = 0,
message = $"Time elapsed: {stopwatch.Elapsed}"
});
Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
Console.WriteLine("Program completed successfully.");
}
}
}