{ A smarter Japan AI } const LAND = 0; const AIR = 1; const SEA = 2; const TRANSPORT = 9; NbrZones := GetZoneCount(); NbrUnits := GetUnitCount(); NbrNations := GetNationCount(); CurrentPlayer := GetCurrentPlayer(); Version( 4.0 ); US := -1; USSR := -1; Germany := -1; France := -1; China := -1; Mongolia := -1; For i := 0 to getnationcount() - 1 do begin name := getnationname(i); If name = 'United States' then US := i; If name = 'USSR' then USSR := i; If name = 'Germany' then Germany := i; If name = 'France' then France := i; If name = 'China' then China := i; if name = 'Mongolia' then Mongolia := i; end; {Diplomatics} like := - 100; friend := -1; points := 0; For i := 0 to NbrNations - 1 do begin stance := getnationstance(CurrentPlayer, i); npoints := 0; If isnationmajorpower(i) then npoints := 1; If ( (stance > like) OR (npoints > points) ) AND (stance < 100) AND (stance > -100) AND (npoints >= points) AND ( isnationactive(i) ) AND (i <> CurrentPlayer) then begin friend := i; points := npoints; like := getnationstance(CurrentPlayer, i); end; end; for i := 1 to getnationdiplomaticactions(CurrentPlayer) do If friend <> -1 then orderdiplomatic(friend, 3); MyCap := findzonename('Japan'); If getbraindata('FT') = '' then begin setbraindata('FT', '1'); For i := 0 to NbrUnits - 1 do If (getunitowner(i) = CurrentPlayer) AND (getunitforcecounttype(i, 14) > 0) then begin If getbraindata('s1') = '' then setbraindata('s1', IntToStr(getunitid(i))) else setbraindata('s2', IntToStr(getunitid(i))); end; end; transports := 0; for i := 0 to NbrUnits - 1 do If (getunitclass(i) = SEA) AND (getunitowner(i) = CurrentPlayer) then transports := transports + getunittransportroom(i); for i := 0 to getzoneunitcount(MyCap) - 1 do transports := transports - getunittransportweight(getzoneunit(MyCap, i)); transporst := transports + 5; tb := (0 - transports) div 2; If getzoneresources(MyCap) div 4 < tb then tb := getzoneresources(MyCap) div 4; if tb = 0 then tb := 1; danger := false; If getzoneforcecount(MyCap, false, true, false, true, true, true) >0 then danger := true; For i := 0 to Getzoneneighborcount(MyCap) - 1 do If getzoneforcecount(getzoneneighbor(mycap, i), false, true, false, true, true, true) > 0 then danger := true; Port := findzonename('Japan'); f := 5 * getzonefactories(Port); Troops := getzoneresources(Port) div 2; If Troops > f then Troops := f; If transports < 0 then orderbuildnavy(Port, 0, tb, 0, 0, 0, 0, 0) else orderbuildarmy(Port, Troops, 0, 0, 0); SetArray( RoutScore, NbrZones + 1); SetArray( Routing, NbrZones + 1); for i := 0 to NbrZones - 1 do begin RoutScore[i] := 0; Routing[i] := 0; end; for i := 0 to NbrZones - 1 do if ( GetZoneOwner( i ) = CurrentPlayer ) then begin nFact := GetZoneFactories( i ); if ( (nFact < 100) and ( (GetZoneResources( i ) > 30) OR ( (Getzoneresources(i) > 24) AND (nFact = 0) ) ) and ( nFact < GetZoneValue( i ) ) ) then OrderBuildFactory( i ) else if ( nFact > 0 ) then begin f := 5 * getzonefactories(i); Artillery := getzoneresources(i) div 2; If Artillery > f then Artillery := f; orderBuildArmy(i, Artillery / 2, 0, Artillery / 2, 0 ); end; rscore := nFact * 3 + getzonevalue(i); if (getzoneresources(i) > 30) AND (getzonefactories(i) = getzonevalue(i)) then rscore := 0; targ := i; island := true; for n := 0 to GetZoneNeighborCount( i ) - 1 do begin neighbor := GetZoneNeighbor( i, n ); if iszoneland(neighbor) then island := false; owner := getzoneowner(neighbor); okay := true; if (owner = -1) then begin owner := getcurrentplayer(); okay := false; end; nrscore := getzonefactories(neighbor) * 3 + getzonevalue(neighbor); if (getzoneresources(neighbor) > 30) AND (getzonefactories(neighbor) = getzonevalue(neighbor)) then nrscore := 0; if RoutScore[neighbor] > 0 then nrscore := RoutScore[neighbor]; if (nrscore >= rscore) and (Routing[neighbor] <> i) AND ( (getcurrentplayer() = owner) OR (getnationstance(getcurrentplayer(), owner) = 100) ) AND (okay) then begin rscore := nrscore; targ := neighbor; end; end; OrderAutoRouteResources( i, targ ); if island then orderautorouteresources(i, Port); Routing[i] := targ; RoutScore[i] := rscore; if getzoneresources(i) < 0 then begin orderautorouteresources(i, i); RoutScore[i] := 0; Routing[i] := i; end; end; setarray( AttackTroops, NbrZones ); For i := 0 to NbrZones - 1 do AttackTroops[i] := -1; zKorea := findzonename('Korea'); zGermany := findzonename('Germany'); zManchuria := findzonename('Manchuria'); zVladivostok := findzonename('Vladivostok'); zRussia := findzonename('Inner Russia'); zFrance := findzonename('Northern France'); zSA := findzonename('South Africa'); zSzechwan := findzonename('Szechwan'); zIndia := findzonename('India'); zKwangtung := findzonename('Kwangtung'); zHopeh := findzonename('Hopeh'); zBurma := findzonename('Burma'); zKweichow := findzonename('Kweichow'); zYunan := findzonename('Yunan'); if getbraindata('qdef') = '1' then setbraindata('qdef', '2'); for i := 0 to NbrUnits - 1 do begin if ( GetUnitOwner( i ) = CurrentPlayer ) then begin uc := GetUnitClass( i ); nCode := GetUnitID( i ); sCode := IntToStr( nCode ); uZone := getunitzone(i); if ( uc = LAND ) then begin If getbraindata(inttostr(getunitid(i))) = '' then If getbraindata('tab') = '' then begin setbraindata('tab', '1'); setbraindata(inttostr(getunitid(i)), 'a'); end else begin setbraindata('tab', ''); setbraindata(inttostr(getunitid(i)), 'b'); end; If getbraindata(inttostr(getunitid(i))) = 'a' then begin If AttackTroops[uZone] = -1 then AttackTroops[uZone] := i else orderunitmerge(i, AttackTroops[uZone]); end; if (getzoneowner(zSzechwan) <> CurrentPlayer) AND (uZone = zHopeh) then nTarget :=zSzechwan else if getzoneowner(zKorea) <> CurrentPlayer then nTarget := zKorea else if (uZone = zKwangtung) and ( (getbraindata('qdef') <> '2') OR (iszoneembattled(zKwangtung)) ) then begin nTarget := zKwangtung; setbraindata('qdef', '1'); end else if (getzoneowner(zManchuria) <> CurrentPlayer) OR (getzoneowner(zVladivostok) <> CurrentPlayer) then begin if getbraindata(inttostr(getunitid(i))) = 'b' then nTarget := zManchuria else nTarget := zVladivostok end else if (getzoneowner(zKwangtung) <> CurrentPlayer) AND (getbraindata(inttostr(getunitid(i))) = 'a' ) AND (getzoneowner(zKwangtung) <> Mongolia) then begin if (getzoneowner(zSzechwan) = CurrentPlayer) AND (getzoneowner(zKweichow) = CurrentPlayer) AND (getzoneowner(zYunan) = CurrentPlayer) then nTarget := zKwangtung else nTarget := zSzechwan; end else if (getbraindata(inttostr(getunitid(i))) = 'b') AND (isnationactive(USSR)) then begin dist := 99999999; for j := 0 to NbrZones - 1 do begin if iszoneland(j) then If (getnationstance(getzoneowner(j), currentplayer) = -100) AND (distance(uZone, j) < dist) then begin dist := distance(uZone, j); nTarget := j; end; end; end else if (isnationactive(USSR)) AND (getzoneforcecountattack(uZone, true, false, false, true, true, true) < getzoneforcecountdefense(zRussia, false, true, true, true, true, true)) then begin nTarget := -1; dist := 9999999; for j := 0 to getzoneneighborcount(zRussia) - 1 do begin tzone := getzoneneighbor(zRussia, j); ndist := distance(uZone, tzone); If (getzoneowner(getzoneneighbor(zRussia, j)) = USSR) AND (ndist < dist) then begin nTarget := tzone; dist := ndist; end; end; If nTarget = -1 then nTarget := findzonename('Lower Urals'); end else if isnationactive(USSR) then nTarget := zRussia else begin If (NOT isnationactive(Germany)) OR ((getbraindata(IntToStr(getunitid(i))) = 'a') OR ((getbraindata(IntToStr(getunitid(i))) = '') AND (random(1, 100) > 50))) then begin nTarget := FindClosestEnemyZone( GetUnitZone( i ), 20 ); setbraindata(IntToStr(getunitid(i)), 'a'); end else begin nTarget := zGermany; setbraindata(inttostr(getunitid(i)), 'g'); end end; neighbor := -1; dist := 9999999; If nTarget >= 0 then begin For j := 0 to getzoneneighborcount(uZone) - 1 do begin tZone := getzoneneighbor(uZone, j); ndist := distance(tZone, nTarget); If (iszoneland(tZone)) AND (ndist < dist) AND ((tZone <> zRussia) OR (nTarget = zRussia)) AND ( (getzoneowner(tZone) <> China) OR (tZone = zSzechwan) ) then begin neighbor := tZone; dist := ndist; end; end; end; if ( nTarget >= 0 ) AND (neighbor >= 0) then begin if ((getzoneowner(neighbor) = CurrentPlayer) OR (isnationalliedwith(CurrentPlayer, getzoneowner(neighbor)))) OR (getzoneowner(nTarget) = CurrentPlayer) then OrderUnitMove( i, nTarget ) else OrderUnitInvade( i, neighbor ); end; If (getzonename(uZone) = 'Japan') OR (getzonename(uZone) = 'Hokkaido') then orderunitmove(i, MyCap) end else if ( uc = AIR ) then begin if ((GetZoneOwner( GetUnitZone( i ) ) <> CurrentPlayer) AND (NOT iszoneallied(uZone))) AND (getunitbasezone(i) <> -1) then begin if GetZoneForceCount( GetUnitZone( i ), false, true, true, true, true, true ) = 0 then begin OrderUnitReturnToBase( i ); end; end else begin If getunitorder(i) <> 0 then begin orderunitreturntobase(i); end else begin If danger then begin orderunitrebase(i, MyCap); end else begin if isnationactive(China) then bigtarg := zSzechwan else if ((getbraindata('qdef') <> '2') OR (iszoneembattled(zKwangtung)) ) AND (getzoneowner(zKwangtung) = CurrentPlayer) then bigtarg := zKwangtung else if (iszoneenemy(zVladivostok)) OR (iszoneenemy(zBurma)) OR (iszoneenemy(zManchuria)) OR (getbraindata(IntToSTr(getunitid(i)) + 'rm') = '' ) then begin bigtarg := zManchuria; setbraindata(IntToStr(getunitid(i)) + 'rm', '1'); end else if getzoneowner(findzonename('Phillippines')) <> CurrentPlayer then bigtarg := findzonename('Phillippines') else if isnationactive(USSR) then bigtarg := zRussia else bigtarg := findzonename('England'); hitrussia := iszoneembattled(bigtarg); If bigtarg = findzonename('Phillippines') then hitrussia := true; If bigtarg = zSzechwan then hitrussia := true; If hitrussia then hitrussia := getunitrange(i) >= truedistance(uZone, bigtarg); If hitrussia then begin orderunitairstrike(i, bigtarg) end else begin dist := 999999; nTarget := -1; for j := 0 to NbrZones - 1 do begin ndist := distance(j, zKorea); If j <> bigtarg then if ndist < dist then if (getzoneforcecount(j, false, true, false, true, false, false) > 0) AND ( (getzoneforcecount(j, false, true, false, true, false, false) < 15) OR iszoneembattled(j) ) then if getzoneowner(j) <> -1 then if isnationmajorpower(getzoneowner(j)) then if truedistance(uZone, j) <= getunitrange(i) then begin nTarget := j; dist := ndist; end; end; If (nTarget <> -1) then begin if ((getbraindata('qdef') <> '2') OR (iszoneembattled(zKwangtung)) ) AND (getzoneowner(zKwangtung) = CurrentPlayer) then orderunitrebase(i, zKwangtung) else orderunitairstrike(i, nTarget); end else begin dist := 999999; nBase := -1; for j := 0 to NbrZones - 1 do if (( (iszoneallied(j)) AND ((isnationactive(France)) OR (NOT isnationactive(USSR)) )) OR (getzoneowner(j) = CurrentPlayer) ) AND (distance(j, bigtarg) < dist) then if truedistance(j, uZone) <= getunitrange(i) * 3 then begin dist := distance(j, bigtarg); nBase := j; end; If nBase <> -1 then begin orderunitrebase(i, nBase); end; end; end; end; end; end; end else if ( uc = SEA ) then begin Korea := -1; If isnationactive(US) then begin dist := 99999999; For k := 0 to NbrZones - 1 do If (distance(uZone, k) < dist) AND (getzoneowner(k) = US) then begin Korea := k; dist := distance(uZone, k); end; end; If Korea = -1 then Korea := findclosestenemyzone(uZone, 20); If getbraindata('nk') <> '4' then Korea := findzonename('Korea'); If uZone <> -1 then begin If getunitboardedcount(i) > 0 then begin If Iszoneneighbor(Korea, uZone) then begin orderunitdisembarkall(i, Korea); If getbraindata('nk') = '' then setbraindata('nk', '1'); If getbraindata('nk') = '1' then setbraindata('nk', '2'); If getbraindata('nk') = '2' then setbraindata('nk', '3'); If getbraindata('nk') = '3' then setbraindata('nk', '4'); end else begin dist := 99999; czone := -1; for j := 0 to getzoneneighborcount(Korea) - 1 do If NOT iszoneland(getzoneneighbor(Korea, j)) then If truedistance(getzoneneighbor(Korea, j), uZone) < dist then begin dist := truedistance(getzoneneighbor(Korea, j), uZone); czone := getzoneneighbor(Korea, j); end; orderunitmove(i, czone); end; end else begin If Iszoneneighbor(MyCap, uZone) then begin If getzoneforcecount(MyCap, true, false, false, true, false, false) > 5 then orderunitembarkall(i, MyCap) end else begin orderunitmove(i, getzoneneighbor(MyCap, 0)); end; end; end; end; end; end;