-
Notifications
You must be signed in to change notification settings - Fork 0
/
movie.py
39 lines (32 loc) · 973 Bytes
/
movie.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
# -*- coding: utf-8 -*-
import re
import junknes
COMMAND_SOFTRESET = (1<<0)
COMMAND_HARDRESET = (1<<1)
def fm2_read(in_):
"""input行のみを読む。形式チェックなどはほぼなし"""
BUTTON_MAP = {
"R" : junknes.JUNKNES_JOY_R,
"L" : junknes.JUNKNES_JOY_L,
"D" : junknes.JUNKNES_JOY_D,
"U" : junknes.JUNKNES_JOY_U,
"T" : junknes.JUNKNES_JOY_T,
"S" : junknes.JUNKNES_JOY_S,
"B" : junknes.JUNKNES_JOY_B,
"A" : junknes.JUNKNES_JOY_A,
"." : 0
}
RE_FRAME = re.compile(r"^\|(\d+)\|([RLDUTSBA.]{8})\|([RLDUTSBA.]{8})\|\|$")
def inp(str_):
value = 0
for c in str_:
value |= BUTTON_MAP[c]
return value
movie_ = []
for line in in_:
m = RE_FRAME.match(line)
if not m : continue
cmd = int(m.group(1))
inputs = (inp(m.group(2)), inp(m.group(3)))
movie_.append((cmd, inputs))
return movie_