forked from harrischristiansen/generals-bot
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDirectives.py
More file actions
74 lines (56 loc) · 2.57 KB
/
Directives.py
File metadata and controls
74 lines (56 loc) · 2.57 KB
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
65
66
67
68
69
70
71
72
73
"""
@ Travis Drake (EklipZ) eklipz.io - tdrake0x45 at gmail)
April 2017
Generals.io Automated Client - https://github.com/harrischristiansen/generals-bot
EklipZ bot - Tries to play generals lol
"""
import logbook
from enum import Enum
class Timings(object):
def __init__(self, cycleTurns, quickExpandSplitTurns, splitTurns, launchTiming, offsetTurns, recalcTurn, disallowEnemyGather):
self.cycleTurns: int = cycleTurns
self.quickExpandTurns: int = quickExpandSplitTurns
self.splitTurns: int = splitTurns
self.offsetTurns: int = offsetTurns
self.launchTiming: int = launchTiming
self.nextRecalcTurn: int = recalcTurn
self.disallowEnemyGather: bool = disallowEnemyGather
self.is_early_flank_launch: bool = False
def should_recalculate(self, turn):
return turn == self.nextRecalcTurn
def in_quick_expand_split(self, turn):
adjustedTurn = self.get_turn_in_cycle(turn)
return adjustedTurn <= self.quickExpandTurns
def in_gather_split(self, turn):
adjustedTurn = self.get_turn_in_cycle(turn)
return self.quickExpandTurns < adjustedTurn < self.splitTurns
def in_expand_split(self, turn):
adjustedTurn = self.get_turn_in_cycle(turn)
return adjustedTurn >= self.splitTurns
def in_launch_split(self, turn):
adjustedTurn = self.get_turn_in_cycle(turn)
return adjustedTurn >= self.launchTiming
def in_launch_timing(self, turn):
adjustedTurn = self.get_turn_in_cycle(turn)
return adjustedTurn >= self.launchTiming and adjustedTurn - self.launchTiming < 5
def get_turn_in_cycle(self, turn):
adjustedTurn = (turn + self.offsetTurns) % self.cycleTurns
return adjustedTurn
def get_turns_left_in_cycle(self, turn: int):
adjustedTurn = self.cycleTurns - (turn + self.offsetTurns) % self.cycleTurns
return adjustedTurn
def __str__(self):
return f"C{self.cycleTurns} Q{self.quickExpandTurns} G{self.splitTurns} L{self.launchTiming} Off{self.offsetTurns}"
class Directive():
def __init__(self, type = None):
self.type = type
# Return some number to indicate how important this move is. -1 or lower will not be made.
# This doesn't necessarily need to calculate a full move etc, and should be performant.
def get_priority(self):
return -1
# Returns the move to be made.
def get_move(self):
return None
# Doesn't necessarily need to recalculate if the directive is cycle-based etc.
def recalculate(self, turn):
return