-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoding.py
More file actions
100 lines (88 loc) · 3.35 KB
/
Copy pathEncoding.py
File metadata and controls
100 lines (88 loc) · 3.35 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from __future__ import annotations
from dataclasses import dataclass
from Calculator import CalculationResult
import Calculator
import Data
from Util import Direction
from typing import List, Tuple
def calculateEncoding(result: CalculationResult) -> EncodingData | None:
earlyTnt = result.earlyTnt
lateTnt = result.lateTnt
direction = result.direction
upaccelTnt = result.simulation.upaccelTnt
longRange = result.simulation.longRange
blue, purple = calculateUpaccelBits(upaccelTnt)
yellow = direction.direction + (8 if longRange else 0)
purple2 = direction.angle
block = Calculator.getPearlBlocker(result.simulation.getEnd()).asInt()
# encode as normal ftl
if earlyTnt <= Data.MAX_TNT/2 and lateTnt <= Data.MAX_TNT/2:
red, orange, pink = calculateBits(earlyTnt)
light_blue, lime, cyan = calculateBits(lateTnt)
magenta = 0
return EncodingData(purple, blue, cyan, light_blue, lime, yellow, orange, red, pink, magenta, purple2, block)
# variable bit = 1
if earlyTnt < lateTnt:
magenta = 1
# don't need to switch update order
redTntInUse = earlyTnt // 11 * 11
red, orange, pink = calculateBits(earlyTnt)
light_blue, lime, cyan = calculateBits(lateTnt - (Data.MAX_VARIABLE_TNT//2 - redTntInUse))
return EncodingData(purple, blue, cyan, light_blue, lime, yellow, orange, red, pink, magenta, purple2, block)
# variable bit = 2
if lateTnt < earlyTnt:
magenta = 2
# need to switch update order
redTntSingle = earlyTnt % 11
blueTntSingle = lateTnt % 11
earlyTnt = earlyTnt - redTntSingle
lateTnt = lateTnt - blueTntSingle
redTnt = Data.MAX_VARIABLE_TNT//2 - lateTnt
blueTnt = earlyTnt - redTnt
red, orange, pink = calculateBits(redTnt + redTntSingle)
light_blue, lime, cyan = calculateBits(blueTnt + blueTntSingle)
return EncodingData(purple, blue, cyan, light_blue, lime, yellow, orange, red, pink, magenta, purple2, block)
def calculateBits(tnt: int) -> Tuple[int, int, int]:
big = tnt // 418
tnt = tnt % 418
medium = tnt // 11
small = tnt % 11
return big, medium, small
def calculateUpaccelBits(tnt: int) -> Tuple[int, int]:
return tnt // 8, tnt % 8
def binary(n: int, values: List[int]) -> str:
out = ""
for value in values:
if (n >= value):
n -= value
out = out + "1"
else:
out = out + "0"
return out
@dataclass
class EncodingData:
purple: int
blue: int
cyan: int
light_blue: int
lime: int
yellow: int
orange: int
red: int
pink: int
magenta: int
purple2: int
block: str
def __str__(self) -> str:
return f"""purple: [{binary(self.purple, [4, 2, 1])[::-1]}]
blue: [{binary(self.blue, [2, 1])[::-1]}]
cyan: [{binary(self.cyan, [4, 4, 2, 1])[::-1]}]
light_blue: [{binary(self.light_blue, [4, 2, 1])[::-1]}]
lime: [{binary(self.lime, [11, 11, 8, 4, 2, 1])[::-1]}]
yellow: [{binary(self.yellow, [8, 4, 2, 1])}]
orange: [{binary(self.orange, [11, 11, 8, 4, 2, 1])[::-1]}]
red: [{binary(self.red, [4, 2, 1])[::-1]}]
pink: [{binary(self.pink, [4, 4, 2, 1])[::-1]}]
magenta: [{binary(self.magenta, [2, 1])[::-1]}]
purple: [{binary(self.purple2, [2, 1])[::-1]}]
place a block at: {self.block}"""