Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Vytor Calixto
Enchente
Commits
58db672c
Commit
58db672c
authored
Apr 22, 2017
by
Vytor Calixto
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do inglês pro português
parent
5ac29a06
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
79 additions
and
75 deletions
+79
-75
Makefile
Makefile
+1
-1
board.c
board.c
+0
-55
board.h
board.h
+0
-15
filha.c
filha.c
+1
-0
main.c
main.c
+4
-4
tabuleiro.c
tabuleiro.c
+55
-0
tabuleiro.h
tabuleiro.h
+18
-0
No files found.
Makefile
View file @
58db672c
...
...
@@ -4,7 +4,7 @@ CFLAGS = -std=c99 -O2 -W -Wall -g
all
:
main
main
:
main.c
board
.o
main
:
main.c
tabuleiro.o filha
.o
$(CC)
$(CFLAGS)
-o
$@
$^
clean
:
...
...
board.c
deleted
100644 → 0
View file @
5ac29a06
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "board.h"
struct
Cell
{
// Cor da célula
int
color
;
// Se a célula já foi visitada
bool
visited
;
};
struct
Board
{
int
x
,
y
,
colors
;
Cell
*
cells
;
};
Board
createBoard
()
{
Board
b
=
malloc
(
sizeof
(
struct
Board
));
if
(
!
b
)
return
NULL
;
b
->
x
=
b
->
y
=
b
->
colors
=
0
;
return
b
;
}
int
readBoard
(
Board
b
)
{
int
x
,
y
,
colors
;
scanf
(
"%d %d %d"
,
&
x
,
&
y
,
&
colors
);
b
->
x
=
x
;
b
->
y
=
y
;
b
->
colors
=
colors
;
// Aloca um único array em vez de um "array de arrays"
b
->
cells
=
malloc
(
sizeof
(
struct
Cell
)
*
x
*
y
);
if
(
b
->
cells
==
NULL
)
return
0
;
for
(
int
i
=
0
;
i
<
x
;
++
i
)
for
(
int
j
=
0
;
j
<
y
;
++
j
)
{
// Para acessar uma matrix [X][Y] em um vetor fazemos i*Y + j
Cell
c
=
malloc
(
sizeof
(
struct
Cell
));
c
->
visited
=
false
;
scanf
(
"%d"
,
&
(
c
->
color
));
b
->
cells
[
i
*
y
+
j
]
=
c
;
}
return
1
;
}
void
printBoard
(
Board
b
)
{
printf
(
"%d "
,
b
->
x
);
printf
(
"%d "
,
b
->
y
);
printf
(
"%d
\n
"
,
b
->
colors
);
for
(
int
i
=
0
;
i
<
b
->
x
;
++
i
)
{
for
(
int
j
=
0
;
j
<
b
->
y
;
++
j
)
printf
(
"%d "
,
b
->
cells
[
i
*
b
->
y
+
j
]
->
color
);
puts
(
""
);
}
return
;
}
board.h
deleted
100644 → 0
View file @
5ac29a06
#ifndef _BOARD_
#define _BOARD_
#include <stdbool.h>
typedef
struct
Cell
*
Cell
;
typedef
struct
Board
*
Board
;
Board
createBoard
();
int
readBoard
(
Board
b
);
void
printBoard
(
Board
b
);
#endif
filha.c
View file @
58db672c
#include "filha.h"
#include <stdbool.h>
#include <stdlib.h>
struct
No
{
void
*
conteudo
;
...
...
main.c
View file @
58db672c
...
...
@@ -2,15 +2,15 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "
board
.h"
#include "
tabuleiro
.h"
int
main
()
{
Board
b
=
createBoard
();
if
(
!
readBoard
(
b
))
{
Tblr
t
=
criaTblr
();
if
(
!
leTblr
(
t
))
{
puts
(
"Erro na leitura do tabuleiro"
);
return
-
1
;
}
pri
ntBoard
(
b
);
im
pri
meTblr
(
t
);
printf
(
"Ler o tabuleiro (em matriz?)
\n
"
);
printf
(
"Enquanto pilha não vazia:
\n
"
);
...
...
tabuleiro.c
0 → 100644
View file @
58db672c
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "tabuleiro.h"
struct
Celula
{
// Cor da célula
int
cor
;
// Se a célula já foi visitada
bool
visitada
;
};
struct
Tblr
{
int
x
,
y
,
cores
;
Celula
*
celulas
;
};
Tblr
criaTblr
()
{
Tblr
t
=
malloc
(
sizeof
(
struct
Tblr
));
if
(
!
t
)
return
NULL
;
t
->
x
=
t
->
y
=
t
->
cores
=
0
;
return
t
;
}
bool
leTblr
(
Tblr
t
)
{
int
x
,
y
,
cores
;
scanf
(
"%d %d %d"
,
&
x
,
&
y
,
&
cores
);
t
->
x
=
x
;
t
->
y
=
y
;
t
->
cores
=
cores
;
// Aloca um único array em vez de um "array de arrays"
t
->
celulas
=
malloc
(
sizeof
(
struct
Celula
)
*
x
*
y
);
if
(
t
->
celulas
==
NULL
)
return
false
;
for
(
int
i
=
0
;
i
<
x
;
++
i
)
for
(
int
j
=
0
;
j
<
y
;
++
j
)
{
// Para acessar uma matrix [X][Y] em um vetor fazemos i*Y + j
Celula
c
=
malloc
(
sizeof
(
struct
Celula
));
c
->
visitada
=
false
;
scanf
(
"%d"
,
&
(
c
->
cor
));
t
->
celulas
[
i
*
y
+
j
]
=
c
;
}
return
true
;
}
void
imprimeTblr
(
Tblr
t
)
{
printf
(
"%d "
,
t
->
x
);
printf
(
"%d "
,
t
->
y
);
printf
(
"%d
\n
"
,
t
->
cores
);
for
(
int
i
=
0
;
i
<
t
->
x
;
++
i
)
{
for
(
int
j
=
0
;
j
<
t
->
y
;
++
j
)
printf
(
"%d "
,
t
->
celulas
[
i
*
t
->
y
+
j
]
->
cor
);
puts
(
""
);
}
return
;
}
tabuleiro.h
0 → 100644
View file @
58db672c
#ifndef _BOARD_
#define _BOARD_
#include <stdbool.h>
typedef
struct
Celula
*
Celula
;
typedef
struct
Tblr
*
Tblr
;
// Cria um tabuleiro vazio e retorna
Tblr
criaTblr
();
// Faz a leitura do jogo para o tabuleiro
bool
leTblr
(
Tblr
t
);
// Imprime o tabuleiro
void
imprimeTblr
(
Tblr
t
);
#endif
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