public void TestDontStealWhenWeCant() { const string message = "P 0 0 1 1 1#0\n" + "P 0 11 0 44 5#1\n" + "P 12 9 2 10 5#2\n" + "F 2 45 2 1 12 12\n" + "go\n"; PlanetWars pw = new PlanetWars(message); StealAdviser adviser = new StealAdviser(pw); List<MovesSet> moves = adviser.RunAll(); Assert.AreEqual(0, moves.Count); }
public void TestStealShipsNumber() { const string message = "P 0 0 1 10 1#0\n" + "P 0 11 0 44 5#1\n" + "P 12 9 2 0 0#2\n" + "F 2 45 2 1 12 12\n" + "go\n"; PlanetWars pw = new PlanetWars(message); StealAdviser adviser = new StealAdviser(pw); List<MovesSet> moves = adviser.RunAll(); Assert.AreEqual(1, moves.Count); Assert.AreEqual(1, moves[0].GetMoves().Count); Assert.AreEqual(1, moves[0].GetMove(0).DestinationID); Assert.AreEqual(7, moves[0].GetMove(0).NumShips); Assert.AreEqual(2, moves[0].GetMove(0).TurnsBefore); }
private void InitLastMove() { lastMove = new Dictionary<string, int>(7); FirstMoveAdviser firstMoveAdviser = new FirstMoveAdviser(Context); DefendAdviser defendAdviser = new DefendAdviser(Context); InvadeAdviser invadeAdviser = new InvadeAdviser(Context); AttackAdviser attackAdviser = new AttackAdviser(Context); SupplyAdviser supplyAdviser = new SupplyAdviser(Context); StealAdviser stealAdviser = new StealAdviser(Context); AntiCrisisAdviser antiCrisiAdviser = new AntiCrisisAdviser(Context); lastMove.Add(firstMoveAdviser.GetAdviserName(), 0); lastMove.Add(defendAdviser.GetAdviserName(), 0); lastMove.Add(invadeAdviser.GetAdviserName(), 0); lastMove.Add(attackAdviser.GetAdviserName(), 0); lastMove.Add(supplyAdviser.GetAdviserName(), 0); lastMove.Add(stealAdviser.GetAdviserName(), 0); lastMove.Add(antiCrisiAdviser.GetAdviserName(), 0); }
public void TestSteal() { const string message = "P 0 0 1 1 0#0\n" + "P 2 2 1 10 5#1\n" + "P 3 3 0 10 3#2\n" + "P 4 4 0 10 5#3\n" + "P 5 5 0 10 4#4\n" + "P 6 6 2 10 4#5\n" + "F 2 12 5 2 4 2\n" + "F 2 12 5 3 4 2\n" + "F 2 12 5 4 4 2\n"; PlanetWars pw = new PlanetWars(message); StealAdviser adviser = new StealAdviser(pw); List<MovesSet> moves = adviser.RunAll(); Assert.AreEqual(2, moves.Count); Assert.AreEqual(1, moves[1].GetMoves().Count); Assert.AreEqual(3, moves[1].GetMove(0).DestinationID); }
public void DoTurn() { try { if (turn == 1) { FirstMoveAdviser firstMoveAdviser = new FirstMoveAdviser(Context); FirstMoveAdviser.CheckTime checkTime = CheckTime; firstMoveAdviser.CheckTimeFunc = checkTime; RunAdviser(firstMoveAdviser); return; } if (Context.MyPlanets().Count == 0) return; DefendAdviser defendAdviser = new DefendAdviser(Context); InvadeAdviser invadeAdviser = new InvadeAdviser(Context); AttackAdviser attackAdviser = new AttackAdviser(Context); StealAdviser stealAdviser = new StealAdviser(Context); //AntiCrisisAdviser antiCrisisAdviser = new AntiCrisisAdviser(Context); RunAdviser(defendAdviser); if (!CheckTime()) return; Config.AttackSendMoreThanEnemyCanDefend = true; Config.UseSectorsForFront = true; if (Context.MyFutureProduction < Context.EnemyFutureProduction || ((Context.MyFutureProduction == Context.EnemyFutureProduction) && (Context.MyTotalShipCount < Context.EnemyTotalShipCount))) { if (turn - lastMove[attackAdviser.GetAdviserName()] > Config.IdleTurns && turn - lastMove[invadeAdviser.GetAdviserName()] > Config.IdleTurns && turn - lastMove[stealAdviser.GetAdviserName()] > Config.IdleTurns) { //Config.UseSectorsForFront = false; //Config.AttackSendMoreThanEnemyCanDefend = false; #if LOG Logger.Log("UseSectorsForFront = false"); #endif //antiCrisisAdviser.Attack = Context.MyTotalShipCount < Context.EnemyTotalShipCount; //RunAdviser(antiCrisisAdviser); //if (!CheckTime()) return; } } RunAdviser(stealAdviser); if (!CheckTime()) return; Config.InvadeSendMoreThanEnemyCanDefend = true;//(Context.MyProduction > Context.EnemyProduction*Config.DoInvadeKoef); RunAdviser(invadeAdviser); if (!CheckTime()) return; RunAdviser(attackAdviser); if (!CheckTime()) return; } finally { try { if (turn == 1) { MakeMoves(setList); setList.Clear(); } else { SelectAndMakeMoves(); if (CheckTime()) { //try { SupplyAdviser supplyAdviser = new SupplyAdviser(Context); RunAdviser(supplyAdviser); if (CheckTime()) { MakeMoves(setList); setList.Clear(); } } //catch { //Logger.Log("exception: " + e.Message); } } } } finally { Context.FinishTurn(); } } }