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
a8f3eb0d
Commit
a8f3eb0d
authored
Apr 11, 2020
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor group updates
parent
47fcb032
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
29 deletions
+32
-29
strategy.py
strategy.py
+32
-29
No files found.
strategy.py
View file @
a8f3eb0d
...
@@ -122,67 +122,65 @@ class State:
...
@@ -122,67 +122,65 @@ class State:
assert
row
<
s
.
nrows
assert
row
<
s
.
nrows
i
=
row
*
COLUMNS
+
s
.
exa
i
=
row
*
COLUMNS
+
s
.
exa
if
not
s
.
locked
(
i
):
if
not
s
.
locked
(
i
):
s
.
held
=
s
.
blocks
[
i
]
s
.
blocks
[
i
]
=
NOBLOCK
s
.
colskip
[
s
.
exa
]
+=
1
s
.
colskip
[
s
.
exa
]
+=
1
s
.
ungroup
(
i
)
s
.
held
=
s
.
remove
(
i
)
elif
move
==
DROP
:
elif
move
==
DROP
:
if
s
.
held
!=
NOBLOCK
:
if
s
.
held
!=
NOBLOCK
:
row
=
s
.
colskip
[
s
.
exa
]
row
=
s
.
colskip
[
s
.
exa
]
assert
row
>
0
assert
row
>
0
i
=
(
row
-
1
)
*
COLUMNS
+
s
.
exa
i
=
(
row
-
1
)
*
COLUMNS
+
s
.
exa
s
.
blocks
[
i
]
=
s
.
held
s
.
held
=
NOBLOCK
s
.
colskip
[
s
.
exa
]
-=
1
s
.
colskip
[
s
.
exa
]
-=
1
s
.
regroup
(
i
)
s
.
place
(
i
,
s
.
held
)
s
.
held
=
NOBLOCK
elif
move
==
SWAP
:
elif
move
==
SWAP
:
assert
not
s
.
colbusy
(
s
.
exa
)
assert
not
s
.
colbusy
(
s
.
exa
)
row
=
s
.
colskip
[
s
.
exa
]
row
=
s
.
colskip
[
s
.
exa
]
i
=
row
*
COLUMNS
+
s
.
exa
i
=
row
*
COLUMNS
+
s
.
exa
j
=
i
+
COLUMNS
j
=
i
+
COLUMNS
if
j
<
len
(
s
.
blocks
)
and
not
s
.
locked
(
i
)
and
not
s
.
locked
(
j
):
if
j
<
len
(
s
.
blocks
)
and
not
s
.
locked
(
i
)
and
not
s
.
locked
(
j
):
bi
=
s
.
blocks
[
i
]
bi
=
s
.
blocks
[
i
]
bj
=
s
.
blocks
[
j
]
bj
=
s
.
blocks
[
j
]
assert
bi
!=
NOBLOCK
assert
bj
!=
NOBLOCK
if
bi
!=
bj
:
if
bi
!=
bj
:
s
.
blocks
[
i
]
=
NOBLOCK
s
.
blocks
[
i
]
=
NOBLOCK
s
.
blocks
[
j
]
=
NOBLOCK
s
.
blocks
[
j
]
=
NOBLOCK
s
.
ungroup
(
i
)
visited
=
set
()
s
.
ungroup
(
j
)
s
.
ungroup
(
i
,
visited
)
s
.
blocks
[
j
]
=
bi
s
.
ungroup
(
j
,
visited
)
s
.
regroup
(
j
)
s
.
place
(
j
,
bi
)
s
.
blocks
[
i
]
=
bj
s
.
place
(
i
,
bj
)
s
.
regroup
(
i
)
return
s
return
s
def
ungroup
(
self
,
i
):
def
remove
(
self
,
i
):
block
=
self
.
blocks
[
i
]
assert
block
!=
NOBLOCK
self
.
blocks
[
i
]
=
NOBLOCK
self
.
ungroup
(
i
,
set
())
return
block
def
ungroup
(
self
,
i
,
visited
):
assert
self
.
blocks
[
i
]
==
NOBLOCK
assert
self
.
blocks
[
i
]
==
NOBLOCK
visited
=
set
()
oldid
=
self
.
groups
[
i
]
oldid
=
self
.
groups
[
i
]
for
nb
in
neighbors
(
i
,
self
.
blocks
):
for
nb
in
neighbors
(
i
,
self
.
blocks
):
if
self
.
groups
[
nb
]
==
oldid
:
if
self
.
groups
[
nb
]
==
oldid
:
newgroup
=
self
.
scan_group
(
nb
,
visited
)
self
.
create_group
(
nb
,
visited
)
if
newgroup
:
self
.
maxgroup
=
newid
=
self
.
maxgroup
+
1
for
j
in
newgroup
:
self
.
groups
[
j
]
=
newid
self
.
groupsizes
[
j
]
=
len
(
newgroup
)
self
.
groups
[
i
]
=
0
self
.
groups
[
i
]
=
0
self
.
groupsizes
[
i
]
=
0
self
.
groupsizes
[
i
]
=
0
def
regroup
(
self
,
i
):
def
place
(
self
,
i
,
block
):
assert
self
.
blocks
[
i
]
!=
NOBLOCK
assert
block
!=
NOBLOCK
self
.
maxgroup
=
newid
=
self
.
maxgroup
+
1
assert
self
.
blocks
[
i
]
==
NOBLOCK
newgroup
=
self
.
scan_group
(
i
,
set
())
self
.
blocks
[
i
]
=
block
for
j
in
newgroup
:
self
.
create_group
(
i
,
set
())
self
.
groups
[
j
]
=
newid
self
.
groupsizes
[
j
]
=
len
(
newgroup
)
def
scan
_group
(
self
,
start
,
visited
):
def
create
_group
(
self
,
start
,
visited
):
def
scan
(
i
):
def
scan
(
i
):
if
i
not
in
visited
:
if
i
not
in
visited
:
yield
i
yield
i
...
@@ -192,7 +190,12 @@ class State:
...
@@ -192,7 +190,12 @@ class State:
yield
from
scan
(
nb
)
yield
from
scan
(
nb
)
block
=
self
.
blocks
[
start
]
block
=
self
.
blocks
[
start
]
return
tuple
(
scan
(
start
))
group
=
tuple
(
scan
(
start
))
if
group
:
self
.
maxgroup
=
newid
=
self
.
maxgroup
+
1
for
j
in
group
:
self
.
groups
[
j
]
=
newid
self
.
groupsizes
[
j
]
=
len
(
group
)
def
fragmentation
(
self
):
def
fragmentation
(
self
):
"""
"""
...
...
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