Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
adc2018-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
adc2018
adc2018-system
Commits
a6a84d6f
Commit
a6a84d6f
authored
Aug 25, 2018
by
royus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed algorythm (unfinished)
parent
51ae9171
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
68 deletions
+98
-68
solver.c
source/solver.c
+98
-68
tags.lock
source/tags.lock
+0
-0
No files found.
source/solver.c
View file @
a6a84d6f
/* solver.c */
/* solver.c */
/* Last Change: 2018/07/16 (Mon) 10:05:50. */
/* Last Change: 2018/08/26 (Sun) 05:04:28. */
#define MAX_ATTEMPS lines*10
#include<stdio.h>
#include<stdio.h>
/* #include<stdlib.h> */
#include<stdlib.h>
#include<string.h>
#include<string.h>
/* #include<limits.h> */
/* #include<limits.h> */
/* #include<math.h> */
/* #include<math.h> */
/* #include<time.h> */
#include<time.h>
int
board
[
8
][
72
][
72
]
=
{};
int
board
[
8
][
72
][
72
]
=
{};
int
avail
[
8
][
72
][
72
]
=
{};
int
avail
[
8
][
72
][
72
]
=
{};
//start=3,path=2,avail=1,nonavail=0,goal=-1
int
connected
[
8
*
72
*
72
/
2
+
1
]
=
{};
int
depth
,
height
,
width
;
int
depth
,
height
,
width
;
int
lines
;
int
lines
;
int
searchorder
[
6
];
//z,y,x
//z,y,x
void
reset
(
void
){
int
i
,
j
,
k
;
for
(
i
=
0
;
i
<
depth
;
i
++
)
for
(
j
=
0
;
j
<
height
;
j
++
)
for
(
k
=
0
;
k
<
width
;
k
++
)
board
[
i
][
j
][
k
]
=
0
;
return
;
}
void
read
(
void
){
void
read
(
void
){
int
x
,
y
,
z
,
i
;
int
x
,
y
,
z
,
i
;
char
c
,
str
[
8
];
char
c
,
str
[
8
];
...
@@ -78,35 +73,48 @@ void read(void){
...
@@ -78,35 +73,48 @@ void read(void){
return
;
return
;
}
}
int
order
(
int
num
){
//1-lines -> 1-lines
int
randline
(
void
){
//1-lines -> 1-lines
return
num
;
return
rand
()
%
lines
+
1
;
}
}
int
connected
(
int
line
){
void
shuffle
(
int
array
[]){
int
i
,
j
,
k
;
for
(
int
i
=
0
;
i
<
6
;
i
++
){
for
(
i
=
0
;
i
<
depth
;
i
++
)
int
j
=
rand
()
%
6
;
for
(
j
=
0
;
j
<
height
;
j
++
)
int
t
=
array
[
i
];
for
(
k
=
0
;
k
<
width
;
k
++
)
array
[
i
]
=
array
[
j
];
if
(
board
[
i
][
j
][
k
]
==
line
)
array
[
j
]
=
t
;
return
1
;
}
return
0
;
}
}
int
available
(
int
startx
,
int
starty
,
int
startz
){
int
available
(
int
startx
,
int
starty
,
int
startz
){
if
(
avail
[
startz
][
starty
][
startx
]
==-
1
)
if
(
avail
[
startz
][
starty
][
startx
]
==-
1
)
//goal
return
1
;
if
(
startx
>
0
&&
available
(
startx
-
1
,
starty
,
startz
))
return
1
;
if
(
starty
>
0
&&
available
(
startx
,
starty
-
1
,
startz
))
return
1
;
if
(
startz
>
0
&&
available
(
startx
,
starty
,
startz
-
1
))
return
1
;
if
(
startx
<
depth
&&
available
(
startx
+
1
,
starty
,
startz
))
return
1
;
if
(
starty
<
height
&&
available
(
startx
,
starty
+
1
,
startz
))
return
1
;
if
(
startz
<
width
&&
available
(
startx
,
starty
,
startz
+
1
))
return
1
;
return
1
;
if
(
avail
[
startz
][
starty
][
startx
]
==
2
)
//visited
return
0
;
avail
[
startz
][
starty
][
startx
]
=
2
;
shuffle
(
searchorder
);
int
i
;
for
(
i
=
0
;
i
<
6
;
i
++
)
switch
(
searchorder
[
i
]){
case
0
:
if
(
startx
>
0
&&
available
(
startx
-
1
,
starty
,
startz
))
return
1
;
case
1
:
if
(
starty
>
0
&&
available
(
startx
,
starty
-
1
,
startz
))
return
1
;
case
2
:
if
(
startz
>
0
&&
available
(
startx
,
starty
,
startz
-
1
))
return
1
;
case
3
:
if
(
startx
<
depth
&&
available
(
startx
+
1
,
starty
,
startz
))
return
1
;
case
4
:
if
(
starty
<
height
&&
available
(
startx
,
starty
+
1
,
startz
))
return
1
;
case
5
:
if
(
startz
<
width
&&
available
(
startx
,
starty
,
startz
+
1
))
return
1
;
}
return
0
;
return
0
;
}
}
...
@@ -116,28 +124,35 @@ int connectable(int linea,int lineb){
...
@@ -116,28 +124,35 @@ int connectable(int linea,int lineb){
for
(
i
=
0
;
i
<
depth
;
i
++
)
for
(
i
=
0
;
i
<
depth
;
i
++
)
for
(
j
=
0
;
j
<
height
;
j
++
)
for
(
j
=
0
;
j
<
height
;
j
++
)
for
(
k
=
0
;
k
<
width
;
k
++
)
for
(
k
=
0
;
k
<
width
;
k
++
)
if
(
board
[
i
][
j
][
k
]
==-
linea
)
if
(
board
[
i
][
j
][
k
]
==-
linea
)
{
if
(
notfound
){
if
(
notfound
){
notfound
=
0
;
notfound
=
0
;
avail
[
i
][
j
][
k
]
=
1
;
startz
=
i
;
startz
=
i
;
starty
=
j
;
starty
=
j
;
startx
=
k
;
startx
=
k
;
}
else
avail
[
startz
][
starty
][
startx
]
=
3
;
avail
[
i
][
j
][
k
]
=-
1
;
}
else
{
else
if
(
board
[
i
][
j
][
k
]
==
0
||
board
[
i
][
j
][
k
]
==
lineb
||
board
[
i
][
j
][
k
]
==
linea
)
avail
[
i
][
j
][
k
]
=-
1
;
//goal
avail
[
i
][
j
][
k
]
=
1
;
}
else
}
else
if
(
board
[
i
][
j
][
k
]
==
0
||
board
[
i
][
j
][
k
]
==
lineb
||
board
[
i
][
j
][
k
]
==
linea
){
avail
[
i
][
j
][
k
]
=
0
;
avail
[
i
][
j
][
k
]
=
1
;
}
else
{
avail
[
i
][
j
][
k
]
=
0
;
}
if
(
startx
==-
1
||
starty
==-
1
||
startz
==-
1
){
if
(
startx
==-
1
||
starty
==-
1
||
startz
==-
1
){
printf
(
"Error
!
\n
"
);
printf
(
"Error
: Line %d
\n
"
,
linea
);
return
0
;
return
0
;
}
}
return
available
(
startx
,
starty
,
startz
);
return
available
(
startx
,
starty
,
startz
);
}
}
void
actuallyconnect
(
int
num
){
void
connect
(
int
num
){
//REQUIRED
int
i
,
j
,
k
;
for
(
i
=
0
;
i
<
depth
;
i
++
)
for
(
j
=
0
;
j
<
height
;
j
++
)
for
(
k
=
0
;
k
<
width
;
k
++
)
if
(
avail
[
i
][
j
][
k
]
==
2
)
board
[
i
][
j
][
k
]
=
num
;
return
;
return
;
}
}
...
@@ -151,25 +166,35 @@ void delete(int line){
...
@@ -151,25 +166,35 @@ void delete(int line){
return
;
return
;
}
}
void
connect
(
int
num
){
int
solve
(
void
){
//return 1 when solved, 0 when cannot
int
i
;
int
i
,
j
,
linea
,
lineb
;
if
(
connectable
(
order
(
num
),
0
))
for
(
i
=
0
;
i
<
MAX_ATTEMPS
;
i
++
){
actuallyconnect
(
order
(
num
));
linea
=
randline
();
else
if
(
connected
[
linea
])
for
(
i
=
num
-
1
;
i
>=
1
;
i
--
)
continue
;
if
(
connectable
(
order
(
num
),
order
(
i
))){
if
(
connectable
(
linea
,
0
)){
delete
(
order
(
i
));
connect
(
linea
);
actuallyconnect
(
order
(
num
));
connected
[
linea
]
=
1
;
connect
(
i
);
connected
[
0
]
++
;
if
(
connected
[
0
]
==
lines
)
return
1
;
}
else
{
for
(
j
=
0
;
j
<
lines
*
2
;
j
++
){
lineb
=
randline
();
if
(
connectable
(
linea
,
lineb
)){
delete
(
lineb
);
connect
(
linea
);
connected
[
linea
]
=
1
;
connected
[
lineb
]
=
0
;
break
;
}
if
(
j
==
MAX_ATTEMPS
/
2
-
1
)
return
0
;
}
}
return
;
}
}
}
return
0
;
void
solve
(
void
){
int
i
;
for
(
i
=
1
;
i
<=
lines
;
i
++
)
connect
(
i
);
return
;
}
}
void
write
(
void
){
void
write
(
void
){
...
@@ -193,10 +218,15 @@ void write(void){
...
@@ -193,10 +218,15 @@ void write(void){
}
}
int
main
(
void
){
int
main
(
void
){
/* reset(); */
int
i
;
srand
((
unsigned
)
time
(
NULL
));
read
();
read
();
solve
();
for
(
i
=
0
;
i
<
6
;
i
++
)
write
();
searchorder
[
i
]
=
i
;
if
(
solve
())
write
();
else
printf
(
"Cannot solve!
\n
"
);
return
0
;
return
0
;
}
}
source/tags.lock
0 → 100644
View file @
a6a84d6f
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