Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LO21_Pin_Noir_Boucher_Bouri_Detree
CellulutLO21
Commits
4b8a0359
Commit
4b8a0359
authored
Apr 17, 2021
by
Eugene Pin
Browse files
Implémentation neighbourhood
parent
31fe2326
Pipeline
#76528
passed with stages
in 16 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/neighbourhood.hpp
0 → 100644
View file @
4b8a0359
/**
\file neighborhood.hpp
\date 17/04/2021
\author Eugene Pin
\version 1
\brief Neighborhood
Cette classe représente le voisinage d'une cellule.
**/
#ifndef NEIGHBOURHOOD_HPP
#define NEIGHBOURHOOD_HPP
#include
<vector>
#include
<utility>
using
namespace
std
;
class
Coord
;
class
State
;
/**
\struct Neighbor
\brief Représente une coordonnée avec un état
Cette structure représente une coordonnée de format (x, y) et un état.\n
Cette strucuture permet d'identifier un voisin d'une cellule. coord correspond à la position relative par rapport à la cellule.
struct Neighbor
{
pair<Coord, State>
};
**/
class
Neighborhood
{
//std::vector<Neighbor> neighborPositions;
vector
<
pair
<
Coord
,
State
>
>
neighborPositions
;
public:
//! \brief Retourne le nombre de voisin ayant la classe définit en paramètre
//! \return Le nombre de voisin
unsigned
int
getNb
(
State
state
);
//! \brief Retourne l'état de la cellule voisine située à la coordonnée relative entrée en paramètre
//! \return L'état de la cellule
State
getAt
(
Coord
c
);
void
setNeighborPositions
(
Coord
c
,
State
s
)
{
neighborPositions
.
push_back
(
make_pair
(
c
,
s
));
}
};
#endif // NEIGHBOURHOOD_HPP
\ No newline at end of file
src/neighbourhood.cpp
0 → 100644
View file @
4b8a0359
#include
"neighbourhood.hpp"
unsigned
int
Neighborhood
::
getNb
(
State
state
)
{
unsigned
int
res
=
0
;
std
::
vector
<
pair
<
Coord
,
State
>
>::
iterator
it
;
for
(
it
=
neighborPositions
.
begin
();
it
!=
neighborPositions
.
end
();
++
it
)
{
if
(
it
->
second
==
state
)
{
res
++
;
}
}
return
res
;
}
State
Neighborhood
::
getAt
(
Coord
c
)
{
std
::
vector
<
pair
<
Coord
,
State
>
>::
iterator
it
;
for
(
it
=
neighborPositions
.
begin
();
it
!=
neighborPositions
.
end
();
++
it
)
{
if
(
it
->
first
==
c
)
{
return
it
->
second
;
}
}
return
ERROR
;
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment