Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exapunks-hackmatch-bot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
exapunks-hackmatch-bot
Commits
d37e7b76
Commit
d37e7b76
authored
5 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Add -q option, document score computation
parent
3975c688
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bot.py
+30
-20
30 additions, 20 deletions
bot.py
strategy.py
+24
-15
24 additions, 15 deletions
strategy.py
with
54 additions
and
35 deletions
bot.py
+
30
−
20
View file @
d37e7b76
...
@@ -24,6 +24,9 @@ def save_screenshot(win):
...
@@ -24,6 +24,9 @@ def save_screenshot(win):
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
import
sys
verbose
=
'
-q
'
not
in
sys
.
argv
[
1
:]
try
:
try
:
win
=
get_exapunks_window
()
win
=
get_exapunks_window
()
focus_window
(
win
)
focus_window
(
win
)
...
@@ -32,54 +35,61 @@ if __name__ == '__main__':
...
@@ -32,54 +35,61 @@ if __name__ == '__main__':
solutions
=
deque
([],
maxlen
=
3
)
solutions
=
deque
([],
maxlen
=
3
)
def
vprint
(
*
args
,
**
kwargs
):
if
verbose
:
print
(
*
args
,
**
kwargs
)
def
vprint_state
(
state
):
if
verbose
:
state
.
print
()
while
True
:
while
True
:
try
:
try
:
board
=
screenshot_board
(
win
)
board
=
screenshot_board
(
win
)
state
=
State
.
detect
(
board
)
state
=
State
.
detect
(
board
)
print
(
'
\033
c
'
,
end
=
''
)
vprint
(
'
\033
c
'
,
'
parsed:
'
,
sep
=
''
)
print
(
'
parsed:
'
)
vprint_state
(
state
)
state
.
print
()
vprint
()
print
()
start
=
time
.
time
()
start
=
time
.
time
()
solution
=
state
.
solve
()
solution
=
state
.
solve
()
end
=
time
.
time
()
end
=
time
.
time
()
print
(
'
thought for
'
,
round
((
end
-
start
)
*
1000
,
1
),
'
milliseconds
'
)
v
print
(
'
thought for
'
,
round
((
end
-
start
)
*
1000
,
1
),
'
milliseconds
'
)
except
(
TypeError
,
AssertionError
):
except
(
TypeError
,
AssertionError
):
print
(
'
\r
error during parsing, wait for a bit...
'
,
end
=
''
)
v
print
(
'
\r
error during parsing, wait for a bit...
'
,
end
=
''
)
time
.
sleep
(
0.05
)
time
.
sleep
(
0.05
0
)
continue
continue
except
error
.
BadMatch
:
except
error
.
BadMatch
:
print
(
'
\r
EXAPUNKS window lost, wait for a bit...
'
,
end
=
''
)
v
print
(
'
\r
EXAPUNKS window lost, wait for a bit...
'
,
end
=
''
)
time
.
sleep
(
0.5
)
time
.
sleep
(
0.5
00
)
continue
continue
if
len
(
solutions
)
==
3
and
solution
.
loops
(
solutions
.
popleft
()):
if
len
(
solutions
)
==
3
and
solution
.
loops
(
solutions
.
popleft
()):
print
(
'
\r
loop detected, wait for a bit...
'
,
end
=
''
)
v
print
(
'
\r
loop detected, wait for a bit...
'
,
end
=
''
)
time
.
sleep
(
0.03
)
time
.
sleep
(
0.03
)
elif
solution
.
moves
:
elif
solution
.
moves
:
print
(
'
moves:
'
,
solution
.
keys
())
v
print
(
'
moves:
'
,
solution
.
keys
())
print
(
'
score:
'
,
solution
.
score
)
v
print
(
'
score:
'
,
solution
.
score
)
if
solutions
:
if
solutions
:
print
(
'
prev score:
'
,
solutions
[
-
1
].
score
)
v
print
(
'
prev score:
'
,
solutions
[
-
1
].
score
)
print
()
v
print
()
print
(
'
target after moves:
'
)
v
print
(
'
target after moves:
'
)
solution
.
newstate
.
print
(
)
vprint_state
(
solution
.
newstate
)
press_keys
(
win
,
solution
.
keys
())
press_keys
(
win
,
solution
.
keys
())
keys_delay
=
len
(
solution
.
moves
)
*
2
*
KEY_DELAY
keys_delay
=
len
(
solution
.
moves
)
*
2
*
KEY_DELAY
moves_delay
=
max
(
0
,
solution
.
delay
()
-
keys_delay
)
moves_delay
=
max
(
0
,
solution
.
delay
()
-
keys_delay
)
print
(
'
wait for
'
,
moves_delay
,
'
ms
'
)
v
print
(
'
wait for
'
,
moves_delay
,
'
ms
'
)
time
.
sleep
(
moves_delay
/
1000
)
time
.
sleep
(
moves_delay
/
1000
)
elif
state
.
nrows
()
-
2
<=
MAX_SPEED_ROWS
:
elif
state
.
nrows
()
-
2
<=
MAX_SPEED_ROWS
:
print
(
'
no moves, speed up
'
)
v
print
(
'
no moves, speed up
'
)
press_keys
(
win
,
'
l
'
)
press_keys
(
win
,
'
l
'
)
time
.
sleep
(
0.03
)
time
.
sleep
(
0.03
0
)
else
:
else
:
print
(
'
no moves
'
)
v
print
(
'
no moves
'
)
solutions
.
append
(
solution
)
solutions
.
append
(
solution
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
...
...
This diff is collapsed.
Click to expand it.
strategy.py
+
24
−
15
View file @
d37e7b76
...
@@ -25,7 +25,7 @@ POINTS_DEPTH = 3
...
@@ -25,7 +25,7 @@ POINTS_DEPTH = 3
FRAG_DEPTH
=
5
FRAG_DEPTH
=
5
DEFRAG_PRIO
=
4
DEFRAG_PRIO
=
4
COLSIZE_PRIO
=
5
COLSIZE_PRIO
=
5
COLSIZE_PANIC
=
7
COLSIZE_PANIC
=
8
COLSIZE_MAX
=
9
COLSIZE_MAX
=
9
BOMB_POINTS
=
1
BOMB_POINTS
=
1
MIN_ROWS
=
2
MIN_ROWS
=
2
...
@@ -90,21 +90,30 @@ class State:
...
@@ -90,21 +90,30 @@ class State:
def
score
(
self
,
points
,
moves
,
prev
):
def
score
(
self
,
points
,
moves
,
prev
):
prev_colsize
=
prev
.
nrows
()
-
2
prev_colsize
=
prev
.
nrows
()
-
2
#if prev_colsize >= COLSIZE_PANIC:
delay
=
moves_delay
(
moves
)
# holes = self.holes()
# frag = self.fragmentation()
# Don't care about defragging for few rows, just score points quickly.
# return holes, moves_delay(moves), -points, frag
# This saves computation time which in turn makes for nice combos when
if
prev_colsize
>=
COLSIZE_PRIO
:
# the bot speeds around throwing blocks on top of each other.
holes
=
self
.
holes
()
if
prev_colsize
<
DEFRAG_PRIO
:
frag
=
self
.
fragmentation
()
return
-
points
,
delay
return
-
points
,
holes
,
frag
,
moves_delay
(
moves
)
elif
prev_colsize
>=
DEFRAG_PRIO
:
holes
=
self
.
holes
()
holes
=
self
.
holes
()
frag
=
self
.
fragmentation
()
frag
=
self
.
fragmentation
()
# When rows start stacking up, start defragmenting colors to make
# opportunities for scoring points.
if
prev_colsize
<
COLSIZE_PRIO
:
return
-
points
,
frag
,
holes
,
delay
# When they stack higher, start moving blocks down into holes before
# continuing to defragment.
if
prev_colsize
<
COLSIZE_PANIC
:
panic
=
int
(
self
.
causes_panic
())
panic
=
int
(
self
.
causes_panic
())
return
-
points
,
panic
,
frag
,
holes
,
moves_delay
(
moves
)
return
panic
,
-
points
,
holes
,
frag
,
delay
else
:
return
-
points
,
moves_delay
(
moves
)
# Column heights are getting out of hand, just move shit DOWN.
return
holes
,
delay
,
-
points
,
frag
def
solutions
(
self
):
def
solutions
(
self
):
for
moves
in
self
.
gen_moves
():
for
moves
in
self
.
gen_moves
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment