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
409354ab
Commit
409354ab
authored
5 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Remove some unused code, format to PEP8
parent
213ebb76
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bot.py
+2
-2
2 additions, 2 deletions
bot.py
strategy.py
+5
-68
5 additions, 68 deletions
strategy.py
with
7 additions
and
70 deletions
bot.py
+
2
−
2
View file @
409354ab
...
...
@@ -6,7 +6,7 @@ from itertools import count
from
Xlib
import
error
from
detection
import
NOBLOCK
from
interaction
import
get_exapunks_window
,
focus_window
,
screenshot_board
,
\
press_keys
,
listen_keys
,
KEY_DELAY
press_keys
,
listen_keys
from
strategy
import
State
...
...
@@ -60,7 +60,7 @@ if __name__ == '__main__':
newstate
=
state
.
solve
()
end
=
time
.
time
()
vprint
(
'
thought for
'
,
round
((
end
-
start
)
*
1000
,
1
),
'
ms
'
)
except
(
TypeError
,
AssertionError
)
as
e
:
except
(
TypeError
,
AssertionError
):
vprint
(
'
\r
error during parsing, wait for a bit...
'
,
end
=
''
)
time
.
sleep
(
0.050
)
continue
...
...
This diff is collapsed.
Click to expand it.
strategy.py
+
5
−
68
View file @
409354ab
...
...
@@ -4,8 +4,7 @@ from collections import deque
from
contextlib
import
redirect_stdout
from
itertools
import
combinations
,
islice
from
detection
import
COLUMNS
,
NOBLOCK
,
detect_blocks
,
detect_exa
,
\
detect_held
,
print_board
,
is_basic
,
is_bomb
,
\
bomb_to_basic
detect_held
,
print_board
,
is_basic
,
is_bomb
GRAB
,
DROP
,
SWAP
,
LEFT
,
RIGHT
,
SPEED
=
range
(
6
)
...
...
@@ -75,7 +74,8 @@ class State:
return
cls
(
blocks
,
exa
,
held
)
def
copy
(
self
):
return
State
(
list
(
self
.
blocks
),
self
.
exa
,
self
.
held
,
list
(
self
.
colskip
))
return
self
.
__class__
(
list
(
self
.
blocks
),
self
.
exa
,
self
.
held
,
list
(
self
.
colskip
))
def
causes_panic
(
self
):
return
self
.
max_colsize
()
>=
COLSIZE_PANIC
...
...
@@ -99,61 +99,9 @@ class State:
score
+=
row
-
start_row
+
1
return
score
def
score
(
self
,
points
,
moves
,
prev
):
prev_colsize
=
prev
.
nrows
-
2
#delay = moves_delay(moves)
delay
=
len
(
moves
)
# Don't care about defragging for few rows, just score points quickly.
# This saves computation time which in turn makes for nice combos when
# the bot speeds around throwing blocks on top of each other.
if
prev_colsize
<
DEFRAG_PRIO
:
return
-
points
,
delay
holes
=
self
.
holes
()
frag
=
0
if
points
else
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
())
return
panic
,
-
points
,
holes
,
frag
,
delay
# Column heights are getting out of hand, just move shit DOWN.
return
holes
,
delay
,
-
points
,
frag
def
find_unmovable_blocks
(
self
):
unmoveable
=
set
()
bombed
=
set
()
for
block
,
group
in
self
.
find_groups
():
if
is_basic
(
block
)
and
len
(
group
)
>=
MIN_BASIC_GROUP_SIZE
:
for
i
in
group
:
unmoveable
.
add
(
i
)
elif
is_bomb
(
block
)
and
len
(
group
)
>=
MIN_BOMB_GROUP_SIZE
:
bombed
.
add
(
bomb_to_basic
(
block
))
for
i
in
group
:
unmoveable
.
add
(
i
)
for
i
,
block
in
enumerate
(
self
.
blocks
):
if
block
in
bombed
:
unmoveable
.
add
(
i
)
return
unmoveable
def
move
(
self
,
moves
):
s
=
self
.
copy
()
if
moves
else
self
s
.
moves
=
moves
# avoid swapping/grabbing currently exploding items
#unmoveable = s.find_unmovable_blocks()
s
.
placed
=
set
()
s
.
grabbed
=
{}
...
...
@@ -169,7 +117,6 @@ class State:
row
=
s
.
colskip
[
s
.
exa
]
assert
row
<
s
.
nrows
i
=
row
*
COLUMNS
+
s
.
exa
#assert i not in unmoveable
s
.
held
=
s
.
blocks
[
i
]
s
.
blocks
[
i
]
=
NOBLOCK
s
.
grabbed
[
i
]
=
s
.
held
...
...
@@ -188,8 +135,6 @@ class State:
i
=
row
*
COLUMNS
+
s
.
exa
j
=
i
+
COLUMNS
assert
j
<
len
(
s
.
blocks
)
#assert i not in unmoveable
#assert j not in unmoveable
bi
=
s
.
blocks
[
i
]
bj
=
s
.
blocks
[
j
]
if
bi
!=
bj
:
...
...
@@ -301,11 +246,6 @@ class State:
return
-
points
def
has_explosion
(
self
):
return
any
(
is_bomb
(
block
)
and
any
(
self
.
blocks
[
j
]
==
block
for
j
in
self
.
neighbors
(
i
))
for
i
,
block
in
enumerate
(
self
.
blocks
))
def
gen_moves
(
self
):
yield
()
...
...
@@ -378,7 +318,8 @@ class State:
return
cls
.
holes
,
cls
.
nmoves
,
cls
.
points
,
cls
.
fragmentation
if
colsize
>=
COLSIZE_PRIO
:
return
cls
.
causes_panic
,
cls
.
points
,
cls
.
holes
,
cls
.
fragmentation
,
cls
.
nmoves
return
cls
.
causes_panic
,
cls
.
points
,
cls
.
holes
,
\
cls
.
fragmentation
,
cls
.
nmoves
return
cls
.
points
,
cls
.
fragmentation
,
cls
.
holes
,
cls
.
nmoves
...
...
@@ -446,7 +387,3 @@ if __name__ == '__main__':
print
(
'
target after move:
'
)
newstate
.
print
()
print
()
#for solution in sorted(state.solutions()):
# print('move %18s:' % solution.keys(), solution.score)
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