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
bc878146
Commit
bc878146
authored
5 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup
parent
8dcacb14
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
parse.py
+0
-1
0 additions, 1 deletion
parse.py
strategy.py
+10
-36
10 additions, 36 deletions
strategy.py
with
10 additions
and
37 deletions
parse.py
+
0
−
1
View file @
bc878146
...
...
@@ -12,7 +12,6 @@ MIN_COLUMN_SAT = 130
MIN_COLUMN_VAL
=
120
COLUMN_VSHIFT
=
[
1
,
1
,
1
,
0
,
0
,
0
,
0
]
#COLUMN_VSHIFT = [2, 2, 1, 1, 0, 0, 0]
RED
,
PINK
,
GREEN
,
BLUE
,
YELLOW
,
NOBLOCK
=
range
(
6
)
BOMB_OFFSET
=
NOBLOCK
+
1
...
...
This diff is collapsed.
Click to expand it.
strategy.py
+
10
−
36
View file @
bc878146
...
...
@@ -11,10 +11,10 @@ GET = ((GRAB,), (SWAP, GRAB), (GRAB, SWAP, DROP, SWAP, GRAB))
PUT
=
((
DROP
,),
(
DROP
,
SWAP
),
(
DROP
,
SWAP
,
GRAB
,
SWAP
,
DROP
))
MIN_BASIC_GROUP_SIZE
=
4
MIN_BOMB_GROUP_SIZE
=
2
FIND_GROUPS_DEPTH
=
4
FRAG_DEPTH
=
4
FIND_GROUPS_DEPTH
=
3
FRAG_DEPTH
=
3
COLSIZE_PRIO
=
5
COLSIZE_P
RIO_HIGH
=
7
COLSIZE_P
ANIC
=
7
COLSIZE_MAX
=
8
BOMB_POINTS
=
2
MIN_ROWS
=
2
...
...
@@ -31,8 +31,6 @@ class State:
skip
=
self
.
colskip
(
self
.
exa
)
i
=
(
skip
+
1
)
*
COLUMNS
+
self
.
exa
return
i
<
len
(
self
.
blocks
)
and
self
.
blocks
[
i
]
==
NOBLOCK
#return any(len(col) > 1 and col[1] == NOBLOCK
# for col in map(tuple, self.iter_columns()))
def
iter_columns
(
self
):
nrows
=
self
.
nrows
()
...
...
@@ -60,11 +58,6 @@ class State:
for
col
in
range
(
COLUMNS
):
yield
self
.
nrows
()
-
self
.
colskip
(
col
)
#def highest_column(self):
# for i, block in enumerate(self.blocks):
# if block != NOBLOCK:
# return self.nrows() - i // COLUMNS
def
empty_column_score
(
self
):
skip
=
0
for
i
,
block
in
enumerate
(
self
.
blocks
):
...
...
@@ -82,23 +75,13 @@ class State:
return
score
def
score
(
self
,
points
,
moves
,
prev
):
#colsizes = list(self.colsizes())
#mincol = min(colsizes)
#maxcol = max(colsizes)
#colsize_score = maxcol, colsizes.count(maxcol) #, -mincol
#colsize_score = tuple(sorted(colsizes, reverse=True))
#if prev.nrows() >= 6:
# return colsize_score, -points, frag, len(moves)
#colsize_score = maxcol, self.empty_column_score()
frag
=
self
.
fragmentation
()
colsize_score
=
self
.
empty_column_score
()
#return -points, frag + colsize_score, len(moves)
frag
+=
colsize_score
prev_colsize
=
max
(
prev
.
colsizes
())
if
prev_colsize
>=
COLSIZE_P
RIO_HIGH
:
if
prev_colsize
>=
COLSIZE_P
ANIC
:
return
colsize_score
,
len
(
moves
),
-
points
,
frag
elif
prev_colsize
>=
COLSIZE_PRIO
:
return
-
points
,
colsize_score
,
frag
,
len
(
moves
)
...
...
@@ -106,10 +89,6 @@ class State:
return
-
points
,
frag
,
colsize_score
,
len
(
moves
)
def
score_moves
(
self
):
# clear exploding blocks before computing colsize
#prev = self.copy()
#prev.score_points()
for
moves
in
self
.
gen_moves
():
try
:
points
,
newstate
=
self
.
simulate
(
moves
)
...
...
@@ -147,9 +126,6 @@ class State:
s
=
self
.
copy
()
points
=
0
#if not moves:
# return s.score_points(), s
# avoid swapping/grabbing currently exploding items
#unmoveable = s.find_unmovable_blocks()
...
...
@@ -228,15 +204,18 @@ class State:
def
fragmentation
(
self
,
depth
=
FRAG_DEPTH
):
"""
Minimize the sum of dist(i,j)
for
all blocks i,j of the same color.
Prioritize horitont
al distance to avoid column stacking.
Minimize the sum of dist(i,j)
between
all blocks i,j of the same color.
Magnify vertic
al distance
s
to avoid column stacking.
"""
def
dist
(
i
,
j
):
yi
,
xi
=
divmod
(
i
,
COLUMNS
)
yj
,
xj
=
divmod
(
j
,
COLUMNS
)
# for blocks in the same group, only count vertical distance so that
# groups are spread out horizontally
if
groups
[
i
]
==
groups
[
j
]:
return
abs
(
yj
-
yi
)
#return abs(xj - xi) * 2 + abs(yj - yi) - 1
return
abs
(
xj
-
xi
)
+
abs
(
yj
-
yi
)
*
2
-
1
colors
=
{}
...
...
@@ -345,7 +324,6 @@ def moves_to_keys(moves):
if
__name__
==
'
__main__
'
:
import
sys
from
PIL
import
Image
#from pprint import pprint
board
=
Image
.
open
(
'
screens/board%d.png
'
%
int
(
sys
.
argv
[
1
])).
convert
(
'
HSV
'
)
state
=
State
.
detect
(
board
)
...
...
@@ -371,7 +349,3 @@ if __name__ == '__main__':
for
score
,
moves
in
sorted
(
state
.
score_moves
()):
print
(
'
move %18s:
'
%
moves_to_keys
(
moves
),
score
)
#print('moves:', moves_to_keys(moves), moves)
#print('score:', score)
#print('\nmoves:', moves_to_keys(state.solve()))
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