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
Show 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):
...
@@ -26,7 +26,7 @@ def find_window(name):
if
win
:
if
win
:
return
win
return
win
return
traverse
(
disp
lay
.
Display
()
.
screen
().
root
)
return
traverse
(
disp
.
screen
().
root
)
def
get_exapunks_window
():
def
get_exapunks_window
():
...
@@ -52,7 +52,8 @@ def screenshot_board(window):
...
@@ -52,7 +52,8 @@ def screenshot_board(window):
return
im
.
convert
(
'HSV'
)
return
im
.
convert
(
'HSV'
)
def
press_key
(
window
,
key
):
def
press_keys
(
window
,
keys
):
for
key
in
keys
:
keysym
=
XK
.
string_to_keysym
(
key
)
keysym
=
XK
.
string_to_keysym
(
key
)
keycode
=
disp
.
keysym_to_keycode
(
keysym
)
keycode
=
disp
.
keysym_to_keycode
(
keysym
)
...
@@ -72,17 +73,13 @@ if __name__ == '__main__':
...
@@ -72,17 +73,13 @@ if __name__ == '__main__':
old_focus
=
disp
.
get_input_focus
()
old_focus
=
disp
.
get_input_focus
()
disp
.
set_input_focus
(
win
,
X
.
RevertToParent
,
X
.
CurrentTime
)
disp
.
set_input_focus
(
win
,
X
.
RevertToParent
,
X
.
CurrentTime
)
def
press_keys
(
keys
):
#press_keys(win, 'aaaj')
for
key
in
keys
:
press_key
(
win
,
key
)
#press_keys('aaaj')
#while True:
#while True:
# press_keys('djkj' * 7)
# press_keys(
win,
'djkj' * 7)
# press_keys('ajkj' * 7)
# press_keys(
win,
'ajkj' * 7)
while
True
:
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
.
set_input_focus
(
old_focus
.
focus
,
X
.
RevertToParent
,
X
.
CurrentTime
)
disp
.
sync
()
disp
.
sync
()
parser.py
View file @
770a09bf
...
@@ -13,16 +13,17 @@ MIN_COLUMN_VAL = 120
...
@@ -13,16 +13,17 @@ MIN_COLUMN_VAL = 120
COLUMN_VSHIFT
=
[
-
2
,
-
2
,
-
1
,
-
1
,
0
,
0
,
0
]
COLUMN_VSHIFT
=
[
-
2
,
-
2
,
-
1
,
-
1
,
0
,
0
,
0
]
RED
,
PINK
,
GREEN
,
BLUE
,
YELLOW
,
NO
NE
=
range
(
6
)
RED
,
PINK
,
GREEN
,
BLUE
,
YELLOW
,
NO
BLOCK
=
range
(
6
)
BOMB_OFFSET
=
NO
NE
+
1
BOMB_OFFSET
=
NO
BLOCK
+
1
BASIC_HUES
=
[
248
,
224
,
118
,
158
,
26
]
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
HUE_TOLERANCE
=
5
DETECT_BASIC_X
=
9
DETECT_BASIC_X
=
9
DETECT_BASIC_Y
=
15
DETECT_BASIC_Y
=
15
DETECT_BOMB_X
=
2
5
DETECT_BOMB_X
=
2
2
DETECT_BOMB_Y
=
4
4
DETECT_BOMB_Y
=
4
5
MIN_BASIC_SAT
=
180
MIN_BASIC_SAT
=
180
MIN_BOMB_SAT
=
130
DETECT_EXA_X
=
30
DETECT_EXA_X
=
30
DETECT_EXA_Y
=
547
DETECT_EXA_Y
=
547
...
@@ -39,6 +40,19 @@ def is_hue(h, hexpect):
...
@@ -39,6 +40,19 @@ def is_hue(h, hexpect):
return
abs
(
h
-
hexpect
)
<=
HUE_TOLERANCE
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
detect_columns
(
board
):
def
saturated
(
x
,
y
):
def
saturated
(
x
,
y
):
h
,
s
,
v
=
board
.
getpixel
((
x
,
y
))
h
,
s
,
v
=
board
.
getpixel
((
x
,
y
))
...
@@ -55,11 +69,10 @@ def detect_columns(board):
...
@@ -55,11 +69,10 @@ def detect_columns(board):
def
detect_block_type
(
board
,
x
,
y
):
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
# check for basic blocks first, use saturation filter to avoid confusing
# green blocks with background
# green blocks with background
h
,
s
,
v
=
board
.
getpixel
((
x
+
DETECT_BASIC_X
,
y
+
DETECT_BASIC_Y
))
if
s
>=
MIN_BASIC_SAT
:
if
s
>=
MIN_BASIC_SAT
:
for
ty
,
hexpect
in
enumerate
(
BASIC_HUES
):
for
ty
,
hexpect
in
enumerate
(
BASIC_HUES
):
if
is_hue
(
h
,
hexpect
):
if
is_hue
(
h
,
hexpect
):
...
@@ -68,12 +81,13 @@ def detect_block_type(board, x, y):
...
@@ -68,12 +81,13 @@ def detect_block_type(board, x, y):
# if no basic block is detected, check another pixel for bomb contents
# if no basic block is detected, check another pixel for bomb contents
h
,
s
,
v
=
board
.
getpixel
((
x
+
DETECT_BOMB_X
,
h
,
s
,
v
=
board
.
getpixel
((
x
+
DETECT_BOMB_X
,
y
+
DETECT_BOMB_Y
))
y
+
DETECT_BOMB_Y
))
if
s
>=
MIN_BOMB_SAT
:
for
ty
,
hexpect
in
enumerate
(
BOMB_HUES
):
for
ty
,
hexpect
in
enumerate
(
BOMB_HUES
):
if
is_hue
(
h
,
hexpect
):
if
is_hue
(
h
,
hexpect
):
return
ty
+
BOMB_OFFSET
return
ty
+
BOMB_OFFSET
# no basic block or bomb -> empty slot
# no basic block or bomb -> empty slot
return
NO
NE
return
NO
BLOCK
def
detect_blocks
(
board
):
def
detect_blocks
(
board
):
...
@@ -101,7 +115,7 @@ def detect_held(board, exa):
...
@@ -101,7 +115,7 @@ def detect_held(board, exa):
if
not
is_hue
(
h
,
EXA_LIGHT_HUE
)
or
v
<
MIN_EXA_LIGHT_VAL
:
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
detect_block_type
(
board
,
exa
*
BLOCK_SIZE
,
DETECT_HELD_Y
)
return
NO
NE
return
NO
BLOCK
def
print_board
(
blocks
,
exa
,
held
):
def
print_board
(
blocks
,
exa
,
held
):
...
@@ -113,12 +127,12 @@ def print_board(blocks, exa, held):
...
@@ -113,12 +127,12 @@ def print_board(blocks, exa, held):
if
exa
is
not
None
:
if
exa
is
not
None
:
print
(
' '
*
exa
+
' |'
)
print
(
' '
*
exa
+
' |'
)
print
(
'
-'
*
exa
,
'('
,
'rpgby RPGBY'
[
held
],
')'
,
print
(
'
'
,
'-'
*
(
exa
-
1
)
,
'('
,
'rpgby RPGBY'
[
held
],
')'
,
'-'
*
(
COLUMNS
-
exa
-
1
),
sep
=
''
)
'-'
*
(
COLUMNS
-
exa
-
2
),
sep
=
''
)
if
__name__
==
'__main__'
:
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
=
get_exapunks_window
()
win
.
raise_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