public Protocol.Move HandleMove(Protocol.MoveRequest request) { Move firstOption = HandleMoveOldStyle(request); return(firstOption); }
public Protocol.Move HandleMove(Protocol.MoveRequest request) { var start = DateTime.Now; Move firstOption = HandleMoveOldStyle(request); //Move secondOption = HandleMoveNewStyle(request); Console.Error.WriteLine((DateTime.Now - start).TotalMilliseconds + " total board count: " + BoardCount); BoardCount = 0; //EVERYTHING IS BROKEN return(firstOption); }
private Move HandleMoveOldStyle(Protocol.MoveRequest request) { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); m_AllowedMoves = request.AllowedMoves; DateTime start = DateTime.Now; var validMoves = new List <Move>(); foreach (var location in GetMyLocations(request.Board)) { validMoves.AddRange(GetPossibleToLocations(request.Board, location).Select <BoardLocation, Move>(l => CreateMove(request.Board, location, l)).Where(m => m.From != m.To).Where(m => request.AllowedMoves.Contains(m.Type))); } int amountOfMoves = validMoves.Count(); SetEnemyValues(request.Board); //.AsParallel() var printableValidMoves = validMoves.Select(m => GetPrintableMoveWithDanger(request.Board, m, (request.AllowedMoves.Count() == 1))).ToList().OrderBy(m => m.Danger - m.Value).ToList(); var MovesForSecondStep = printableValidMoves.Take(14).ToList(); var combinedMoves = new List <PrintableMove>(); if (request.AllowedMoves.Count() == 1) { // var listForNextStep = printableValidMoves.Take(20); foreach (var firstMove in printableValidMoves) { if (stopWatch.Elapsed > TimeSpan.FromSeconds(2)) { break; } //Board resultBoard = GetNewBoard(request.Board, firstMove.InnerMove); CalculateSecondMove(combinedMoves, firstMove); } } int milliseconds = (int)Math.Ceiling((DateTime.Now - start).TotalMilliseconds); Console.Error.WriteLine("moves: " + amountOfMoves.ToString() + " Time(milliseconds): " + milliseconds.ToString()); if (request.AllowedMoves.Count() == 1) { combinedMoves = combinedMoves.OrderBy(m => m.Danger - m.Value).ToList(); return(combinedMoves.First().InnerMove); } else { return(printableValidMoves.First().InnerMove); } }
private Move HandleMoveOldStyle(Protocol.MoveRequest request) { bool onlyAttackMove = request.AllowedMoves.Count() == 1; var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); m_AllowedMoves = request.AllowedMoves; DateTime start = DateTime.Now; GameState.CalculateGameState(request.Board, myColor); var validMoves = new List <Move>(); foreach (var location in GameState.myLocations) { validMoves.AddRange(GameState.myPossibleToLocations[location].Select <BoardLocation, Move>(l => CreateMove(request.Board, location, l)).Where(m => m.From != m.To).Where(m => request.AllowedMoves.Contains(m.Type))); } SetEnemyValues(request.Board); if (!onlyAttackMove) { validMoves.Add(new Move(MoveType.Pass, null, null)); } //.AsParallel() if (debug) { Console.WriteLine("\nfirstmoves: "); } var printableValidMoves = validMoves.Select(m => GetPrintableMoveWithDanger(request.Board, m, request.AllowedMoves)).ToList(); if (!onlyAttackMove) { printableValidMoves = printableValidMoves.OrderBy(m => m.Danger - m.Value).ToList(); } else { printableValidMoves = printableValidMoves.OrderBy(m => m.Value).ToList(); } var combinedMoves = new List <PrintableMove>(); if (onlyAttackMove) { // var listForNextStep = printableValidMoves.Take(20); foreach (var firstMove in printableValidMoves) { if (stopWatch.Elapsed > TimeSpan.FromSeconds(2)) { break; } //Board resultBoard = GetNewBoard(request.Board, firstMove.InnerMove); CalculateSecondMove(combinedMoves, firstMove); } } int milliseconds = (int)Math.Ceiling((DateTime.Now - start).TotalMilliseconds); if (request.AllowedMoves.Count() == 1) { Console.Error.WriteLine("moves: " + combinedMoves.Count.ToString() + " Time(milliseconds): " + milliseconds.ToString()); combinedMoves = combinedMoves.OrderBy(m => m.Danger - m.Value).ToList(); return(combinedMoves.First().InnerMove); } else { try { var firstMove = printableValidMoves.First(); var valueFirstMove = firstMove.Danger - firstMove.Value; var randomList = printableValidMoves.TakeWhile(m => (m.Danger - m.Value) == valueFirstMove).ToList(); return(randomList.OrderBy(x => Guid.NewGuid()).First().InnerMove); // return printableValidMoves.First().InnerMove; } catch { return(new Move(MoveType.Pass, null, null)); } } }