Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
exapunks-hackmatch-bot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
exapunks-hackmatch-bot
Commits
770a09bf
Commit
770a09bf
authored
Apr 04, 2020
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various cleanup
parent
de6182ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
34 deletions
+45
-34
interaction.py
interaction.py
+15
-18
parser.py
parser.py
+30
-16
No files found.
interaction.py
View file @
770a09bf
...
...
@@ -26,7 +26,7 @@ def find_window(name):
if
win
:
return
win
return
traverse
(
disp
lay
.
Display
()
.
screen
().
root
)
return
traverse
(
disp
.
screen
().
root
)
def
get_exapunks_window
():
...
...
@@ -52,17 +52,18 @@ def screenshot_board(window):
return
im
.
convert
(
'HSV'
)
def
press_key
(
window
,
key
):
keysym
=
XK
.
string_to_keysym
(
key
)
keycode
=
disp
.
keysym_to_keycode
(
keysym
)
def
press_keys
(
window
,
keys
):
for
key
in
keys
:
keysym
=
XK
.
string_to_keysym
(
key
)
keycode
=
disp
.
keysym_to_keycode
(
keysym
)
ext
.
xtest
.
fake_input
(
disp
,
X
.
KeyPress
,
keycode
)
disp
.
sync
()
time
.
sleep
(
KEY_DELAY
)
ext
.
xtest
.
fake_input
(
disp
,
X
.
KeyPress
,
keycode
)
disp
.
sync
()
time
.
sleep
(
KEY_DELAY
)
ext
.
xtest
.
fake_input
(
disp
,
X
.
KeyRelease
,
keycode
)
disp
.
sync
()
time
.
sleep
(
KEY_DELAY
)
ext
.
xtest
.
fake_input
(
disp
,
X
.
KeyRelease
,
keycode
)
disp
.
sync
()
time
.
sleep
(
KEY_DELAY
)
if
__name__
==
'__main__'
:
...
...
@@ -72,17 +73,13 @@ if __name__ == '__main__':
old_focus
=
disp
.
get_input_focus
()
disp
.
set_input_focus
(
win
,
X
.
RevertToParent
,
X
.
CurrentTime
)
def
press_keys
(
keys
):
for
key
in
keys
:
press_key
(
win
,
key
)
#press_keys('aaaj')
#press_keys(win, 'aaaj')
#while True:
# press_keys('djkj' * 7)
# press_keys('ajkj' * 7)
# press_keys(
win,
'djkj' * 7)
# press_keys(
win,
'ajkj' * 7)
while
True
:
press_key
(
win
,
'adjk'
[
randint
(
0
,
3
)])
press_key
s
(
win
,
'adjk'
[
randint
(
0
,
3
)])
disp
.
set_input_focus
(
old_focus
.
focus
,
X
.
RevertToParent
,
X
.
CurrentTime
)
disp
.
sync
()
parser.py
View file @
770a09bf
...
...
@@ -13,16 +13,17 @@ MIN_COLUMN_VAL = 120
COLUMN_VSHIFT
=
[
-
2
,
-
2
,
-
1
,
-
1
,
0
,
0
,
0
]
RED
,
PINK
,
GREEN
,
BLUE
,
YELLOW
,
NO
NE
=
range
(
6
)
BOMB_OFFSET
=
NO
NE
+
1
RED
,
PINK
,
GREEN
,
BLUE
,
YELLOW
,
NO
BLOCK
=
range
(
6
)
BOMB_OFFSET
=
NO
BLOCK
+
1
BASIC_HUES
=
[
248
,
224
,
118
,
158
,
26
]
BOMB_HUES
=
[
250
,
219
,
13
1
,
174
,
38
]
BOMB_HUES
=
[
250
,
219
,
13
2
,
174
,
38
]
HUE_TOLERANCE
=
5
DETECT_BASIC_X
=
9
DETECT_BASIC_Y
=
15
DETECT_BOMB_X
=
2
5
DETECT_BOMB_Y
=
4
4
DETECT_BOMB_X
=
2
2
DETECT_BOMB_Y
=
4
5
MIN_BASIC_SAT
=
180
MIN_BOMB_SAT
=
130
DETECT_EXA_X
=
30
DETECT_EXA_Y
=
547
...
...
@@ -39,6 +40,19 @@ def is_hue(h, hexpect):
return
abs
(
h
-
hexpect
)
<=
HUE_TOLERANCE
def
is_basic
(
block
):
return
RED
<=
block
<=
YELLOW
def
is_bomb
(
block
):
return
block
>
NOBLOCK
def
bomb_to_basic
(
block
):
assert
is_bomb
(
block
)
return
block
-
BOMB_OFFSET
def
detect_columns
(
board
):
def
saturated
(
x
,
y
):
h
,
s
,
v
=
board
.
getpixel
((
x
,
y
))
...
...
@@ -55,11 +69,10 @@ def detect_columns(board):
def
detect_block_type
(
board
,
x
,
y
):
h
,
s
,
v
=
board
.
getpixel
((
x
+
DETECT_BASIC_X
,
y
+
DETECT_BASIC_Y
))
# check for basic blocks first, use saturation filter to avoid confusing
# green blocks with background
h
,
s
,
v
=
board
.
getpixel
((
x
+
DETECT_BASIC_X
,
y
+
DETECT_BASIC_Y
))
if
s
>=
MIN_BASIC_SAT
:
for
ty
,
hexpect
in
enumerate
(
BASIC_HUES
):
if
is_hue
(
h
,
hexpect
):
...
...
@@ -68,12 +81,13 @@ def detect_block_type(board, x, y):
# if no basic block is detected, check another pixel for bomb contents
h
,
s
,
v
=
board
.
getpixel
((
x
+
DETECT_BOMB_X
,
y
+
DETECT_BOMB_Y
))
for
ty
,
hexpect
in
enumerate
(
BOMB_HUES
):
if
is_hue
(
h
,
hexpect
):
return
ty
+
BOMB_OFFSET
if
s
>=
MIN_BOMB_SAT
:
for
ty
,
hexpect
in
enumerate
(
BOMB_HUES
):
if
is_hue
(
h
,
hexpect
):
return
ty
+
BOMB_OFFSET
# no basic block or bomb -> empty slot
return
NO
NE
return
NO
BLOCK
def
detect_blocks
(
board
):
...
...
@@ -101,7 +115,7 @@ def detect_held(board, exa):
if
not
is_hue
(
h
,
EXA_LIGHT_HUE
)
or
v
<
MIN_EXA_LIGHT_VAL
:
return
detect_block_type
(
board
,
exa
*
BLOCK_SIZE
,
DETECT_HELD_Y
)
return
NO
NE
return
NO
BLOCK
def
print_board
(
blocks
,
exa
,
held
):
...
...
@@ -113,12 +127,12 @@ def print_board(blocks, exa, held):
if
exa
is
not
None
:
print
(
' '
*
exa
+
' |'
)
print
(
'
-'
*
exa
,
'('
,
'rpgby RPGBY'
[
held
],
')'
,
'-'
*
(
COLUMNS
-
exa
-
1
),
sep
=
''
)
print
(
'
'
,
'-'
*
(
exa
-
1
)
,
'('
,
'rpgby RPGBY'
[
held
],
')'
,
'-'
*
(
COLUMNS
-
exa
-
2
),
sep
=
''
)
if
__name__
==
'__main__'
:
from
iteraction
import
get_exapunks_window
,
screenshot_board
from
i
n
teraction
import
get_exapunks_window
,
screenshot_board
win
=
get_exapunks_window
()
win
.
raise_window
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment