anchor.diff:      RequiredHouses[HT] := 0;
   
     UpdateCityStats();
  -  UpdateBasicHouses(GA_PLANNER);
  +  UpdateBasicHouses(aTick, False);
     UpdateWareBalance();
   
     // Consideration of corn delay - only remove all required houses, builder will find the right one if they are not removed
  
positive.code:       Houses[HT] := Planner.PlannedHouses[HT].Calculated; // Consider only placed or planned houses (not destroyed houses - plans will remain in CityPlanner)
        HousesCnt := HousesCnt + Houses[HT];
      end;
      if GA_PLANNER then  // Short info for Genetic algorithm planner
      begin
        Citizens[ut_Worker] := fSetup.WorkerCount;
        Citizens[ut_Serf] := HousesCnt*2;
        CitizensCnt := Citizens[ut_Serf] + Citizens[ut_Worker];
        WarriorsCnt := 100;
      end;
    end;
  end;
  
  
  // Basic house requirements
  procedure TKMCityPredictor.UpdateBasicHouses(aInitialization: Boolean = False);
  const
    INN_TIME_LIMIT = 60 * 10 * 14; // ~ 14 minutes from start
    SCHOOL_PRODUCTION = 3; // Amount of gold which requires school (in 1 minute) - in ideal case it requires only 3.5 in real there is not sometimes gold so it must be lower
    FIRST_MARKETPLACE = 10 * 60 * 80;
    SECOND_MARKETPLACE = 10 * 60 * 180;
  begin
    // 1 Storehouse
    RequiredHouses[htStore] := 1 - fCityStats.Houses[htStore];
    // 1 Barracks (build only when we have or produce axe / armors)
    RequiredHouses[htBarracks] := Byte(aInitialization OR (gHands[fOwner].Stats.GetWareBalance(wt_Warfare) > 0)) - fCityStats.Houses[htBarracks];
    // Schools (at least 1 + WarriorsPerMinute criterium)
    RequiredHouses[htSchool] := Max( 0,  Max(1, Byte(  (fCityStats.Houses[htBarracks] > 0) OR aInitialization ) * (Round(fMaxSoldiersInMin / SCHOOL_PRODUCTION))) - fCityStats.Houses[htSchool]  );
    // Inn (at least 1 after INN_TIME_LIMIT + CitizensCnt criterium)
    RequiredHouses[htInn] := Max(0, Ceil(  Byte( (gGame.GameTickCount > INN_TIME_LIMIT) OR aInitialization ) * fCityStats.CitizensCnt / 80  ) - fCityStats.Houses[htInn]);
    // Marketplace - 1. after FIRST_MARKETPLACE; 2. after SECOND_MARKETPLACE
    RequiredHouses[htMarketplace] := Byte( aInitialization OR (gGame.GameTickCount > FIRST_MARKETPLACE) ) + Byte( aInitialization OR (gGame.GameTickCount > SECOND_MARKETPLACE) ) - fCityStats.Houses[htMarketplace];
  end;
  
  
  // City initialization, estimation of maximal possible production and restriction by peace time and loc properties
  procedure TKMCityPredictor.CityInitialization(aGoldMineCnt, aIronMineCnt, aFieldCnt, aBuildCnt: Integer);
  
    procedure AddCitizens(aUT: TKMUnitType; aCnt: Word; aOverride: Boolean = False);
    begin
      fCityStats.CitizensCnt := fCityStats.CitizensCnt - fCityStats.Citizens[aUT] * Byte(aOverride) + aCnt;
      fCityStats.Citizens[aUT] := fCityStats.Citizens[aUT] * Byte(not aOverride) + aCnt;
    end;
    procedure AddWarriors(aUT: TKMUnitType; aCnt: Word; aOverride: Boolean = False);
    begin
      fCityStats.WarriorsCnt := fCityStats.WarriorsCnt - fCityStats.Warriors[aUT] * Byte(aOverride) + aCnt;
      fCityStats.Warriors[aUT] := fCityStats.Warriors[aUT] * Byte(not aOverride) + aCnt;
    end;
    procedure AddHouses(aHT: TKMHouseType; aCnt: Word; aOverride: Boolean = False);
    begin
      fCityStats.HousesCnt := fCityStats.HousesCnt - fCityStats.Houses[aHT] * Byte(aOverride) + aCnt;
      fCityStats.Houses[aHT] := fCityStats.Houses[aHT] * Byte(not aOverride) + aCnt;
    end;
  
  const
    IRON_WARFARE: set of TKMWareType = [wt_MetalShield, wt_MetalArmor, wt_Sword, wt_Hallebard, wt_Arbalet];
    STANDARD_WARFARE: array[0..3] of TKMWareType = (wt_Axe, wt_Pike, wt_Bow, wt_Shield);
    MIN_WOOD_PRODUCTION = 1;
    MAX_WOOD_PRODUCTION = 4;
    SCALE_MIN_PEACE_TIME = 50;
    SCALE_MAX_PEACE_TIME = 90;
    SCALE_PEACE_FACTOR = 1.0 / ((SCALE_MAX_PEACE_TIME - SCALE_MIN_PEACE_TIME)*1.0);
  var
  
negative.code: procedure TKMCityPredictor.UpdateState(aTick: Cardinal);
    function UpdateFarmHistory(): Boolean;
    const
      CORN_DELAY = 10 * 60 * 6; // Delay 6 minutes or use array ProductionLag from KM_ResWares
    var
      I, K, Cnt: Integer;
    begin
  