Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Concurrent;
- using System.Linq;
- using System.Threading.Tasks;
- namespace rocket_bot
- {
- public partial class Bot
- {
- public Rocket GetNextMove(Rocket rocket)
- {
- var allMoves = new ConcurrentBag<Tuple<Turn, double>>();
- var currentTasks = new Task[threadsCount];
- for (var i = 0; i < threadsCount; i++)
- {
- currentTasks[i] = new Task(() =>
- {
- var random = new Random();
- var bestMove = SearchBestMove(rocket, this.random, iterationsCount / threadsCount);
- allMoves.Add(bestMove);
- });
- currentTasks[i].Start();
- }
- Task.WaitAll(currentTasks);
- var finalSearch = allMoves.OrderBy(w => w.Item2).First();
- return rocket.Move(finalSearch.Item1, level);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment