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 / Register
Toggle navigation
Open sidebar
Vytor Calixto
Enchente
Commits
9a1ac183
Commit
9a1ac183
authored
Apr 22, 2017
by
Vytor Calixto
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Criado tabuleiro do jogo e feita a leitura
parent
06e90a94
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
3 deletions
+91
-3
Makefile
Makefile
+11
-2
board.c
board.c
+55
-0
board.h
board.h
+15
-0
main.c
main.c
+10
-1
No files found.
Makefile
View file @
9a1ac183
all
:
gcc main.c
-o
main
CFLAGS
=
-std
=
c99
-O2
-W
-Wall
-g
.PHONY
:
all clean
all
:
main
main
:
main.c board.o
$(CC)
$(CFLAGS)
-o
$@
$^
clean
:
$(RM)
*
.o
board.c
0 → 100644
View file @
9a1ac183
#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
0 → 100644
View file @
9a1ac183
#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
main.c
View file @
9a1ac183
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "board.h"
int
main
()
{
Board
b
=
createBoard
();
if
(
!
readBoard
(
b
))
{
puts
(
"Erro na leitura do tabuleiro"
);
return
-
1
;
}
printBoard
(
b
);
int
main
(
int
argc
,
char
const
*
argv
[])
{
printf
(
"Ler o tabuleiro (em matriz?)
\n
"
);
printf
(
"Enquanto pilha não vazia:
\n
"
);
printf
(
"
\t
Pega os adjacentes do grupo (retorna os pesos dos filhos = montar o grafo)
\n
"
);
...
...
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