Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GameOfLife
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
clemo
GameOfLife
Commits
3115b9e8
Commit
3115b9e8
authored
3 years ago
by
clemo
Browse files
Options
Downloads
Patches
Plain Diff
long int, comments
Signed-off-by:
clemo
<
clemo@cbcode.at
>
parent
8e280da7
No related branches found
No related tags found
No related merge requests found
Pipeline
#4551
passed
3 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cli.c
+3
-4
3 additions, 4 deletions
src/cli.c
src/gol.c
+1
-6
1 addition, 6 deletions
src/gol.c
test/test.c
+12
-1
12 additions, 1 deletion
test/test.c
with
16 additions
and
11 deletions
src/cli.c
+
3
−
4
View file @
3115b9e8
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
#include
"./gol.h"
#include
"./gol.h"
#include
<stdio.h>
#include
<stdio.h>
#include
<unistd.h>
#include
<unistd.h>
const
unsigned
int
ROUNDS
=
10
;
void
print_colmn
(
unsigned
int
value
)
void
print_colmn
(
unsigned
int
value
)
{
{
printf
(
"%d"
,
value
);
printf
(
"%d"
,
value
);
...
@@ -22,15 +21,15 @@ int main(int argc, char **argv)
...
@@ -22,15 +21,15 @@ int main(int argc, char **argv)
game
->
current
[
1
]
=
51
;
game
->
current
[
1
]
=
51
;
game
->
current
[
2
]
=
1271
;
game
->
current
[
2
]
=
1271
;
game
->
current
[
5
]
=
51
;
game
->
current
[
5
]
=
51
;
unsigned
int
round
=
0
;
unsigned
long
int
round
=
0
;
while
(
1
)
while
(
1
)
{
{
printf
(
"round: %d
\n
"
,
round
++
);
printf
(
"round: %
l
d
\n
"
,
round
++
);
gol_each
(
game
,
&
print_colmn
,
&
print_row
);
gol_each
(
game
,
&
print_colmn
,
&
print_row
);
gol_tick
(
game
);
gol_tick
(
game
);
printf
(
"
\033
[%dA"
,
height
+
1
);
printf
(
"
\033
[%dA"
,
height
+
1
);
printf
(
"
\033
[%dD"
,
width
);
printf
(
"
\033
[%dD"
,
width
);
usleep
(
200000
);
//
usleep(200000);
}
}
gol_free
(
game
);
gol_free
(
game
);
}
}
This diff is collapsed.
Click to expand it.
src/gol.c
+
1
−
6
View file @
3115b9e8
...
@@ -36,14 +36,9 @@ void gol_free(gol_t *g)
...
@@ -36,14 +36,9 @@ void gol_free(gol_t *g)
free
(
g
);
free
(
g
);
}
}
int
pMod
(
int
x
,
int
y
)
{
return
(
x
+
y
)
%
y
;
}
int
getCell
(
gol_t
*
g
,
int
cell
)
int
getCell
(
gol_t
*
g
,
int
cell
)
{
{
cell
=
pMod
(
cell
,
g
->
width
*
g
->
height
);
cell
=
cell
%
(
g
->
width
*
g
->
height
);
div_t
d
=
div
(
cell
,
8
);
div_t
d
=
div
(
cell
,
8
);
return
g
->
current
[
d
.
quot
]
&
(
1
<<
(
d
.
rem
))
?
1
:
0
;
return
g
->
current
[
d
.
quot
]
&
(
1
<<
(
d
.
rem
))
?
1
:
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
test/test.c
+
12
−
1
View file @
3115b9e8
...
@@ -15,7 +15,18 @@ void print_row(unsigned int line)
...
@@ -15,7 +15,18 @@ void print_row(unsigned int line)
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
gol_t
*
game
=
gol_setup
(
5
,
15
);
gol_t
*
game
=
gol_setup
(
5
,
15
);
//set walker
/*
# set walker
# split by 5 (width)
00000
001 #128
00
01010
0 #20
1100
0000 #3
*/
game
->
current
[
0
]
=
128
;
game
->
current
[
0
]
=
128
;
game
->
current
[
1
]
=
20
;
game
->
current
[
1
]
=
20
;
game
->
current
[
2
]
=
3
;
game
->
current
[
2
]
=
3
;
...
...
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