Commit 679eff42 authored by LAIRD Timothy's avatar LAIRD Timothy

Merge branch 'generation' into 'dev'

Merge generation > dev

See merge request !2
parents d83cb1ce 46774d6e
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "networld.h" #include "networld.h"
#include "player.h" #include "player.h"
#include "controlpanel.h" #include "controlpanel.h"
#include "randomMap.h"
// Program attributes // Program attributes
//------------------- //-------------------
...@@ -29,20 +30,27 @@ bool game_end; ...@@ -29,20 +30,27 @@ bool game_end;
int main(int nbArg, char ** arg) int main(int nbArg, char ** arg)
{ {
int n = 5;
NetWorld * world= NetWorld_new(n);
world = Random_map(world, n);
//Node_set(&(world->nodes[0]), (Vector2){1.4f, 1.28f}, ORANGE);
printf("positionX %f\n", world->nodes[0].position.x);
printf("positionY %f\n", world->nodes[0].position.y);
printf("positionX %f\n", world->nodes[1].position.x);
printf("positionY %f\n", world->nodes[1].position.y);
printf("distXY %f\n", dist(world->nodes[0], world->nodes[1]));
// Game Initialization // Game Initialization
//-------------------- //--------------------
game_end= false; game_end= false;
int playerCount = 3;
NetWorld * world= NetWorld_new(4, playerCount); //NetWorld_connect(world, 0, 1);
Node_set( &(world->nodes[0]), (Vector2){1.4f, 1.28f}, RED ); //NetWorld_connect(world, 1, 2);
Node_set( &(world->nodes[1]), (Vector2){21.0f, 22.8f}, MAGENTA ); //NetWorld_biconnect(world, 2, 0);
Node_set( &(world->nodes[2]), (Vector2){18.4f, -12.2f}, GRAY );
Node_set( &(world->nodes[3]), (Vector2){10.0f, -10.0f}, GRAY );
NetWorld_biconnect(world, 0, 1);
NetWorld_biconnect(world, 1, 2);
NetWorld_biconnect(world, 2, 0);
Panel * panel= Panel_new(); Panel * panel= Panel_new();
Panel_initialize(panel, world); Panel_initialize(panel, world);
...@@ -59,8 +67,10 @@ int main(int nbArg, char ** arg) ...@@ -59,8 +67,10 @@ int main(int nbArg, char ** arg)
InitWindow(screenWidth, screenHeight, "NetWorld basic viewer"); InitWindow(screenWidth, screenHeight, "NetWorld basic viewer");
SetTargetFPS(targetFPS); SetTargetFPS(targetFPS);
// Some verificcations // Some verificcations
//-------------------- //--------------------
/*
puts("world variable:"); puts("world variable:");
NetWorld_print(world); NetWorld_print(world);
puts("world expected:\n[10.4, 12.8]\n[110.4, 52.8]\n[384.5, 422.2]"); puts("world expected:\n[10.4, 12.8]\n[110.4, 52.8]\n[384.5, 422.2]");
...@@ -68,6 +78,7 @@ int main(int nbArg, char ** arg) ...@@ -68,6 +78,7 @@ int main(int nbArg, char ** arg)
Vector2 position= {1.f, 1.f}; Vector2 position= {1.f, 1.f};
position= Panel_pixelFromPosition( panel, &position ); position= Panel_pixelFromPosition( panel, &position );
printf("[%.2f,%.2f]\n", position.x, position.y); printf("[%.2f,%.2f]\n", position.x, position.y);
*/
// Main game loop // Main game loop
world->currentPlayer = 0; world->currentPlayer = 0;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// Constructor / Destructor // Constructor / Destructor
void Node_construct(Node * self) void Node_construct(Node * self)
{ {
Node_set( self, (Vector2){0.f, 0.f}, GRAY ); Node_set( self, (Vector2){0.f, 0.f}, GRAY, "" );
self->card= 0; self->card= 0;
self->edges= Edge_newArray( 0 ); self->edges= Edge_newArray( 0 );
self->name= malloc( sizeof(char)*32 ); self->name= malloc( sizeof(char)*32 );
...@@ -90,10 +90,11 @@ void Node_resize( Node * self, int card ) ...@@ -90,10 +90,11 @@ void Node_resize( Node * self, int card )
self->card= card; self->card= card;
} }
void Node_set( Node * self, Vector2 position, Color color ) void Node_set( Node * self, Vector2 position, Color color, char * name )
{ {
self->position= position; self->position= position;
self->color= color; self->color= color;
self->name = name;
} }
int Node_connect( Node * self, Node * target ) int Node_connect( Node * self, Node * target )
......
...@@ -108,7 +108,10 @@ void Node_set( ...@@ -108,7 +108,10 @@ void Node_set(
//! position //! position
Vector2 position, Vector2 position,
//! color //! color
Color color Color color,
//!
char * name
); );
/** /**
......
#include "randomMap.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <string.h>
#include "networld.h"
#include "controlpanel.h"
#include "raylib.h"
double randfrom(double min, double max)
{
double range = (max - min);
double div = RAND_MAX / range;
return min + (rand() / div);
}
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)
{
int i ;
float randomX, randomY;
/* Intializes random number generator */
srand (time ( NULL));
/* Print 5 random numbers from -15.00 to 15.00 */
for( i = 0 ; i < nbNode ; i++ ) {
double randomX = randfrom(-15.0, 15.0);
double randomY = randfrom(-15.0, 15.0);
char * name;
name= malloc(sizeof(int));
sprintf(name, "name : %d", i);
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
for( int i = 0; i <nbNode-1 ; i++){
for( int j = i+1; j <nbNode ; j++){
int compteurPointDansLeCercle = 0;
float xm = 0.5*(world->nodes[i].position.x + world->nodes[j].position.x);
float ym = 0.5*(world->nodes[i].position.y + world->nodes[j].position.y);
float distCenterOfij = sqrt((xm - world->nodes[i].position.x)*(xm - world->nodes[i].position.x) + (ym - world->nodes[i].position.y)*(ym - world->nodes[i].position.y));
printf("xm : %f\n", xm);
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 ++;
}
}
printf("compteurPointDansLeCercle : %i\n", compteurPointDansLeCercle);
if(compteurPointDansLeCercle == 0){
NetWorld_connect(world, i, j);
}
}
}
return world;
}
\ No newline at end of file
#include "raylib.h"
#include "networld.h"
NetWorld * Random_map(NetWorld * world, int nbNode);
double randfrom(double min, double max);
double dist(Node node1, Node node2);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment