Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NetWorld
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LAIRD Timothy
NetWorld
Commits
f6ac9d3d
Commit
f6ac9d3d
authored
Apr 12, 2021
by
Timothy LAIRD
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix + elimination player w/o node
parent
679eff42
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
69 deletions
+57
-69
CMakeLists.txt
CMakeLists.txt
+1
-1
main-viewer.c
src/main-viewer.c
+15
-34
player.c
src/player.c
+20
-15
random-map.c
src/random-map.c
+8
-19
random-map.h
src/random-map.h
+13
-0
No files found.
CMakeLists.txt
View file @
f6ac9d3d
...
...
@@ -18,7 +18,7 @@ include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src)
include_directories
(
${
PROJECT_SOURCE_DIR
}
/dpd/include
)
link_directories
(
${
PROJECT_SOURCE_DIR
}
/dpd
)
add_executable
(
nw-viewer src/main-viewer.c src/networld.c src/controlpanel.c src/entity.c src/player.c
)
add_executable
(
nw-viewer src/main-viewer.c src/networld.c src/controlpanel.c src/entity.c src/player.c
src/random-map.c
)
target_link_libraries
(
nw-viewer raylib pthread dl rt X11 m
)
#without cmake package...
...
...
src/main-viewer.c
View file @
f6ac9d3d
...
...
@@ -14,7 +14,7 @@
#include "networld.h"
#include "player.h"
#include "controlpanel.h"
#include "random
M
ap.h"
#include "random
-m
ap.h"
// Program attributes
//-------------------
...
...
@@ -30,9 +30,10 @@ bool game_end;
int
main
(
int
nbArg
,
char
**
arg
)
{
int
n
=
5
;
NetWorld
*
world
=
NetWorld_new
(
n
);
world
=
Random_map
(
world
,
n
);
int
nodeCount
=
5
;
int
playerCount
=
3
;
NetWorld
*
world
=
NetWorld_new
(
nodeCount
,
playerCount
);
Random_map
(
world
);
//Node_set(&(world->nodes[0]), (Vector2){1.4f, 1.28f}, ORANGE);
...
...
@@ -46,11 +47,6 @@ int main(int nbArg, char ** arg)
// Game Initialization
//--------------------
game_end
=
false
;
//NetWorld_connect(world, 0, 1);
//NetWorld_connect(world, 1, 2);
//NetWorld_biconnect(world, 2, 0);
Panel
*
panel
=
Panel_new
();
Panel_initialize
(
panel
,
world
);
...
...
@@ -60,26 +56,11 @@ int main(int nbArg, char ** arg)
for
(
int
index
=
0
;
index
<
world
->
size
;
index
++
){
Player_add_Node
(
&
(
players
[
index
%
playerCount
]),
&
(
world
->
nodes
[
index
]));
}
Player_remove_Node
(
&
(
players
[
0
]),
&
(
world
->
nodes
[
3
]));
Player_add_Node
(
&
(
players
[
1
]),
&
(
world
->
nodes
[
3
]));
// Raylib Initialization
//----------------------
InitWindow
(
screenWidth
,
screenHeight
,
"NetWorld basic viewer"
);
SetTargetFPS
(
targetFPS
);
// Some verificcations
//--------------------
/*
puts("world variable:");
NetWorld_print(world);
puts("world expected:\n[10.4, 12.8]\n[110.4, 52.8]\n[384.5, 422.2]");
Panel_print(panel);
Vector2 position= {1.f, 1.f};
position= Panel_pixelFromPosition( panel, &position );
printf("[%.2f,%.2f]\n", position.x, position.y);
*/
// Main game loop
world
->
currentPlayer
=
0
;
Player_start_turn
(
&
(
players
[
world
->
currentPlayer
]));
...
...
@@ -109,6 +90,7 @@ void game_update(NetWorld * world, Player * players)
{
Player
*
currentPlayer
=
&
(
players
[
world
->
currentPlayer
]);
int
playerCount
=
world
->
playerCount
;
Player
*
newPlayers
=
malloc
(
sizeof
(
Player
));
switch
(
currentPlayer
->
turnPhase
){
case
1
:
if
(
currentPlayer
->
soldiers
>
0
){
...
...
@@ -178,16 +160,15 @@ void game_update(NetWorld * world, Player * players)
}
}
break
;
case
-
1
:
Player_end_turn
(
currentPlayer
);
printf
(
"Turn ended
\n
"
);
world
->
currentPlayer
=
(
world
->
currentPlayer
+
1
)
%
playerCount
;
printf
(
"Player changed
\n
"
);
Player_start_turn
(
&
(
players
[
world
->
currentPlayer
]));
printf
(
"Turn started
\n
"
);
printf
(
"Recrutement phase
\n
"
);
break
;
default:
;
}
if
(
currentPlayer
->
turnPhase
==
-
1
){
Player_end_turn
(
currentPlayer
);
printf
(
"Turn ended
\n
"
);
world
->
currentPlayer
=
(
world
->
currentPlayer
+
1
)
%
playerCount
;
printf
(
"Player changed
\n
"
);
Player_start_turn
(
&
(
players
[
world
->
currentPlayer
]));
printf
(
"Turn started
\n
"
);
printf
(
"Recrutement phase
\n
"
);
}
}
src/player.c
View file @
f6ac9d3d
...
...
@@ -54,18 +54,18 @@ void Player_add_Node( Player * self, Node * node )
void
Player_remove_Node
(
Player
*
self
,
Node
*
node
)
{
Node
**
newNodes
=
malloc
(
sizeof
(
Node
*
)
*
(
self
->
nodeCount
-
1
));
bool
nodeFound
=
false
;
for
(
int
i
=
0
;
i
<
self
->
nodeCount
-
1
;
i
++
)
{
if
(
nodeFound
||
self
->
nodes
[
i
]
==
node
){
self
->
nodes
[
i
]
=
self
->
nodes
[
i
+
1
];
if
(
!
nodeFound
&&
self
->
nodes
[
i
]
==
node
){
nodeFound
=
true
;
}
if
(
nodeFound
){
newNodes
[
i
]
=
self
->
nodes
[
i
+
1
];
}
else
{
newNodes
[
i
]
=
self
->
nodes
[
i
];
}
}
Node
**
newNodes
=
malloc
(
sizeof
(
Node
*
)
*
(
self
->
nodeCount
-
1
));
for
(
int
i
=
0
;
i
<
self
->
nodeCount
-
1
;
i
++
)
{
newNodes
[
i
]
=
self
->
nodes
[
i
];
}
free
(
self
->
nodes
);
...
...
@@ -75,14 +75,19 @@ void Player_remove_Node( Player * self, Node * node )
}
void
Player_start_turn
(
Player
*
self
){
int
totalSoldierCount
=
0
;
for
(
int
nodeIndex
=
0
;
nodeIndex
<
self
->
nodeCount
;
nodeIndex
++
){
totalSoldierCount
+=
self
->
nodes
[
nodeIndex
]
->
soldiers
;
if
(
self
->
nodeCount
==
0
){
self
->
turnPhase
=
-
1
;
}
else
{
int
totalSoldierCount
=
0
;
for
(
int
nodeIndex
=
0
;
nodeIndex
<
self
->
nodeCount
;
nodeIndex
++
){
totalSoldierCount
+=
self
->
nodes
[
nodeIndex
]
->
soldiers
;
}
self
->
soldiers
=
fmax
(
1
,
totalSoldierCount
/
3
);
self
->
turnPhase
=
1
;
printf
(
"Current player : %i
\n
"
,
self
->
ID
);
printf
(
"Current player soldiers : %i
\n
"
,
self
->
soldiers
);
}
self
->
soldiers
=
fmax
(
1
,
totalSoldierCount
/
3
);
self
->
turnPhase
=
1
;
printf
(
"Current player : %i
\n
"
,
self
->
ID
);
printf
(
"Current player soldiers : %i
\n
"
,
self
->
soldiers
);
}
void
Player_end_turn
(
Player
*
self
){
...
...
src/random
M
ap.c
→
src/random
-m
ap.c
View file @
f6ac9d3d
#include "randomMap.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include "networld.h"
#include "controlpanel.h"
#include "random-map.h"
#include "raylib.h"
...
...
@@ -21,14 +22,14 @@ double randfrom(double min, double max)
double
dist
(
Node
node1
,
Node
node2
){
return
(
sqrt
(
(
node2
.
position
.
x
-
node1
.
position
.
x
)
*
(
node2
.
position
.
x
-
node1
.
position
.
x
)
+
(
node2
.
position
.
y
-
node1
.
position
.
y
)
*
(
node2
.
position
.
y
-
node1
.
position
.
y
)
));
}
NetWorld
*
Random_map
(
NetWorld
*
world
,
int
nbNode
)
void
Random_map
(
NetWorld
*
world
)
{
int
i
;
int
nbNode
=
world
->
size
;
float
randomX
,
randomY
;
/* Intializes random number generator */
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
/* Print 5 random numbers from -15.00 to 15.00 */
for
(
i
=
0
;
i
<
nbNode
;
i
++
)
{
for
(
i
nt
i
=
0
;
i
<
nbNode
;
i
++
)
{
double
randomX
=
randfrom
(
-
15
.
0
,
15
.
0
);
double
randomY
=
randfrom
(
-
15
.
0
,
15
.
0
);
char
*
name
;
...
...
@@ -37,15 +38,8 @@ NetWorld * Random_map(NetWorld * world, int nbNode)
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
,
name
);
printf
(
"%f
\n
"
,
randomX
);
printf
(
"%f
\n
"
,
randomY
);
/* if(i!= nbNode-1){
NetWorld_connect(world, i, i+1);
}
else{
NetWorld_connect(world, i, 0);
} */
}
//Gabriel graph sort
//Gabriel graph sort
for
(
int
i
=
0
;
i
<
nbNode
-
1
;
i
++
){
for
(
int
j
=
i
+
1
;
j
<
nbNode
;
j
++
){
int
compteurPointDansLeCercle
=
0
;
...
...
@@ -56,11 +50,7 @@ NetWorld * Random_map(NetWorld * world, int nbNode)
printf
(
"ym : %f
\n
"
,
ym
);
printf
(
"distCenterOfij : %f
\n
"
,
distCenterOfij
);
printf
(
"dist %d%d : %f
\n
"
,
i
,
j
,
dist
((
world
->
nodes
[
i
]),
world
->
nodes
[
j
]));
//printf("dist sqrt : %f\n", sqrt(dist((world->nodes[i]),world->nodes[p])*dist((world->nodes[i]),world->nodes[p]) + dist((world->nodes[j]),world->nodes[p])*dist((world->nodes[j]),world->nodes[p])));
for
(
int
k
=
0
;
k
<
nbNode
;
k
++
){
/* if((xm - distCenterOfij < world->nodes[k].position.x < xm + distCenterOfij) && (ym - distCenterOfij < world->nodes[k].position.y < ym + distCenterOfij) ){
compteurPointDansLeCercle ++;
} */
printf
(
" dist center - Node k %f
\n
"
,
sqrt
((
world
->
nodes
[
k
].
position
.
x
-
xm
)
*
(
world
->
nodes
[
k
].
position
.
x
-
xm
)
+
(
world
->
nodes
[
k
].
position
.
y
-
ym
)
*
(
world
->
nodes
[
k
].
position
.
y
-
ym
)));
if
(
sqrt
((
world
->
nodes
[
k
].
position
.
x
-
xm
)
*
(
world
->
nodes
[
k
].
position
.
x
-
xm
)
+
(
world
->
nodes
[
k
].
position
.
y
-
ym
)
*
(
world
->
nodes
[
k
].
position
.
y
-
ym
))
<
distCenterOfij
-
0
.
05
){
compteurPointDansLeCercle
++
;
...
...
@@ -68,11 +58,10 @@ NetWorld * Random_map(NetWorld * world, int nbNode)
}
printf
(
"compteurPointDansLeCercle : %i
\n
"
,
compteurPointDansLeCercle
);
if
(
compteurPointDansLeCercle
==
0
){
NetWorld_connect
(
world
,
i
,
j
);
NetWorld_
bi
connect
(
world
,
i
,
j
);
}
}
}
return
world
;
}
\ No newline at end of file
src/random
M
ap.h
→
src/random
-m
ap.h
View file @
f6ac9d3d
#ifndef RANDOMMAP_H
#define RANDOMMAP_H
#include "raylib.h"
#include "networld.h"
NetWorld
*
Random_map
(
NetWorld
*
world
,
int
nbNode
);
void
Random_map
(
NetWorld
*
world
);
double
randfrom
(
double
min
,
double
max
);
double
dist
(
Node
node1
,
Node
node2
);
\ No newline at end of file
double
dist
(
Node
node1
,
Node
node2
);
#endif
\ No newline at end of file
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