Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prog-1
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
Package Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
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
Pedro Folloni Pesserl
prog-1
Commits
7290c8da
Commit
7290c8da
authored
2 years ago
by
Pedro Folloni Pesserl
Browse files
Options
Downloads
Patches
Plain Diff
begin mundo.c
parent
c413adfd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
t1/libconjunto.c
+3
-1
3 additions, 1 deletion
t1/libconjunto.c
t1/makefile
+2
-2
2 additions, 2 deletions
t1/makefile
t1/mundo.c
+100
-0
100 additions, 0 deletions
t1/mundo.c
with
105 additions
and
3 deletions
t1/libconjunto.c
+
3
−
1
View file @
7290c8da
...
...
@@ -183,8 +183,10 @@ conjunto_t *cria_subcjt_cjt(conjunto_t *c, int n) {
return
NULL
;
conjunto_t
*
disponiveis
;
if
(
!
(
disponiveis
=
copia_cjt
(
c
))
)
if
(
!
(
disponiveis
=
copia_cjt
(
c
))
)
{
free
(
sub
);
return
NULL
;
}
int
i
;
int
aleat
;
...
...
This diff is collapsed.
Click to expand it.
t1/makefile
+
2
−
2
View file @
7290c8da
...
...
@@ -11,8 +11,8 @@ CC = gcc
mundo
:
mundo.o libconjunto.o liblef.o libfila.o
$(
CC
)
-o
mundo mundo.o libconjunto.o liblef.o libfila.o
$(
LDFLAGS
)
teste
:
teste.o liblef.o
$(
CC
)
-o
teste teste.o liblef.o
$(
LDFLAGS
)
teste
:
teste.o liblef.o
libconjunto.o libfila.o
$(
CC
)
-o
teste teste.o liblef.o
libconjunto.o libfila.o
$(
LDFLAGS
)
libconjunto.o
:
libconjunto.c
$(
CC
)
-c
$(
CFLAGS
)
libconjunto.c
...
...
This diff is collapsed.
Click to expand it.
t1/mundo.c
+
100
−
0
View file @
7290c8da
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
#include
<math.h>
#include
"libconjunto.h"
#include
"libfila.h"
#include
"liblef.h"
#define CHEGADA 0
#define SAIDA 1
#define MISSAO 2
#define FIM 3
typedef
struct
{
int
id
;
int
paciencia
;
int
idade
;
int
exp
;
conjunto_t
*
habilidades_do_heroi
;
}
heroi_t
;
typedef
struct
{
int
id
;
int
lotacao_max
;
conjunto_t
*
herois_no_local
;
fila_t
*
fila
;
int
localizacaox
;
int
localizacaoy
;
}
local_t
;
typedef
struct
{
int
tempo_atual
;
heroi_t
*
herois
;
local_t
*
locais
;
conjunto_t
*
habilidades
;
int
n_herois
;
int
n_locais
;
int
n_tamanho_mundo
;
/* o mundo é um quadrado */
}
mundo_t
;
/* retorna um inteiro aleatório entre a e b (inclusive) */
int
aleat
(
int
a
,
int
b
)
{
return
rand
()
%
b
+
1
+
a
;
}
/* retorna a distancia euclidiana entre duas coordenadas em double */
double
distancia
(
coordenada_t
loc1
,
coordenada_t
loc2
)
{
int
soma
=
(
loc2
.
x
-
loc1
.
x
)
*
(
loc2
.
x
-
loc1
.
x
)
+
(
loc2
.
y
-
loc1
.
y
)
*
(
loc2
.
y
-
loc1
.
y
);
oreturn
sqrt
((
double
)
soma
);
}
heroi_t
*
inicializa_heroi
(
int
id
,
conjunto_t
*
conjunto_de_habilidades
)
{
heroi_t
*
h
;
if
(
!
(
h
=
malloc
(
sizeof
(
heroi_t
)))
)
return
NULL
;
if
(
!
(
h
->
habilidades_do_heroi
=
cria_subcjt_cjt
(
conjunto_de_habilidades
,
aleat
(
2
,
5
)))
)
{
free
(
h
);
return
NULL
;
}
h
->
id
=
id
;
h
->
paciencia
=
aleat
(
0
,
100
);
h
->
idade
=
aleat
(
18
,
100
);
h
->
exp
=
0
;
return
h
;
}
local_t
*
inicializa_local
(
int
id
,
int
tamanho_mundo
)
{
local_t
*
l
;
if
(
!
(
l
=
malloc
(
sizeof
(
local_t
)))
)
return
NULL
;
l
->
localizacaox
=
aleat
(
0
,
tamanho_mundo
-
1
);
l
->
localizacaoy
=
aleat
(
0
,
tamanho_mundo
-
1
);
/* TODO: terminar essa função */
return
l
;
}
mundo_t
*
inicializa_mundo
()
{
mundo_t
*
m
;
if
(
!
(
m
=
malloc
(
sizeof
(
mundo_t
)))
)
return
NULL
;
m
->
tempo_atual
=
0
;
if
(
!
(
m
->
habilidades
=
cria_cjt
())
)
{
free
(
m
);
return
NULL
;
}
/* TODO: terminar essa função */
return
m
;
}
int
main
()
{
srand
(
0
);
return
0
;
}
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