/
expansion_management.py
64 lines (57 loc) · 2.05 KB
/
expansion_management.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sys
from base_ai import BaseAI
import random
from command import MoveCommand
from command import LandCommand
from command import ExchangeResourcesCommand
from command import DropMilitarsCommand
from command import ExchangeResourcesCommand
from model import Base
from model import Coord
from model import Plane
from model.Base import FullView
from random import choice
from path import get_path
from path import distance
from path import is_near
from path import evaluation
from metier import load_unit
from metier import need_democracy
from metier import bring_democracy
from metier import conquer
import context
class ExpansionManagement:
def __init__(self, base_ai):
self.planes_id = set()
self.base_ai = base_ai
def assign(self, plane):
self.planes_id.add(plane.id())
def release(self, plane):
return self.planes_id.remove(plane.id())
def think(self):
self.move()
def move(self):
ls_bases = self.base_ai.all_bases.values()
fuel_rate = 0.31
fuel_rate = 0.0
next_order = []
planes = filter(lambda k: k in self.base_ai.my_planes, self.planes_id)
planes = map(lambda id: self.base_ai.my_planes[id], planes)
for p in planes:
if is_near(p.position(), self.base_ai.country.position(), 0.8) and \
need_democracy(p, fuel_rate):
load_unit(self.base_ai.game, p, self.base_ai.country, fuel_rate)
else:
next_order += [p]
mili_plane = filter(lambda p: p.militaryInHold() > 0, next_order)
rand_plane = filter(lambda p: p.militaryInHold() == 0, next_order)
rank = {}
bs = ls_bases[:]
# random.shuffle(mili_plane)
# random.shuffle(rand_plane)
for p in mili_plane:
bring_democracy(self.base_ai.game, p, ls_bases, fuel_rate)
for p in rand_plane:
if random.random() < 0.1:
load_unit(self.base_ai.game, p, self.base_ai.country, fuel_rate)
# bring_democracy(self.base_ai.game, p, bs[:], fuel_rate)