restructure and add server/client example
This commit is contained in:
55
shared/inc/values/Dna.hpp
Normal file
55
shared/inc/values/Dna.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef DNA_H
|
||||
#define DNA_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <array>
|
||||
|
||||
#include "values/mrand.hpp"
|
||||
|
||||
#define MAX_DEPTH 8
|
||||
#define MAX_POSIBLE_DEPTH 11
|
||||
static_assert(MAX_DEPTH <= MAX_POSIBLE_DEPTH);
|
||||
|
||||
struct Branch
|
||||
{
|
||||
uint8_t colorR;
|
||||
uint8_t colorG;
|
||||
uint8_t colorB;
|
||||
int8_t colorR_change;
|
||||
int8_t colorG_change;
|
||||
int8_t colorB_change;
|
||||
uint8_t colorVar;
|
||||
|
||||
uint8_t size;
|
||||
uint8_t sizeParent;
|
||||
uint8_t sizeLevel;
|
||||
uint8_t sizeChange;
|
||||
uint8_t sizeVar;
|
||||
|
||||
uint8_t length;
|
||||
uint8_t lengthVar;
|
||||
|
||||
uint8_t branchCount;
|
||||
uint8_t branchAngleVar;
|
||||
};
|
||||
|
||||
struct Dna
|
||||
{
|
||||
uint128 mountenSeed;
|
||||
uint128 starSeed;
|
||||
uint128 branchSeed;
|
||||
|
||||
uint8_t moonX;
|
||||
uint8_t moonY;
|
||||
uint8_t moonSize;
|
||||
uint8_t colorSet;
|
||||
Branch branches[MAX_DEPTH];
|
||||
};
|
||||
namespace DNA
|
||||
{
|
||||
void newDna(Dna *dna, uint128 *state);
|
||||
void makeChild(Dna *p1, Dna *p2, Dna *c, uint128 *state);
|
||||
void clone(Dna *p1, Dna *c, uint128 *state);
|
||||
void mutate(Dna *dna, uint32_t num, uint128 *state);
|
||||
}
|
||||
#endif /* DNA_H */
|
48
shared/inc/values/DnaManager.hpp
Normal file
48
shared/inc/values/DnaManager.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "values/Dna.hpp"
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#define NUM_PER_GEN 10
|
||||
#define NUM_OF_MUT 1
|
||||
|
||||
enum Liked
|
||||
{
|
||||
tbd,
|
||||
yes,
|
||||
no
|
||||
};
|
||||
|
||||
struct UiUnit
|
||||
{
|
||||
Dna *dna;
|
||||
Liked liked;
|
||||
int index;
|
||||
};
|
||||
|
||||
struct NetUnit
|
||||
{
|
||||
uint32_t hash;
|
||||
uint32_t index;
|
||||
Liked liked;
|
||||
};
|
||||
|
||||
static_assert(12 == sizeof(NetUnit));
|
||||
|
||||
struct DnaManagerData
|
||||
{
|
||||
int generation;
|
||||
uint128 randSeed;
|
||||
uint128 id;
|
||||
int queued;
|
||||
int showed;
|
||||
std::vector<Dna> vector;
|
||||
std::vector<int> liked;
|
||||
std::vector<int> disliked;
|
||||
};
|
||||
|
||||
namespace DnaManager
|
||||
{
|
||||
UiUnit next(DnaManagerData *data);
|
||||
bool like(UiUnit unit, DnaManagerData *data);
|
||||
void newGen(DnaManagerData *data);
|
||||
};
|
16
shared/inc/values/mrand.hpp
Normal file
16
shared/inc/values/mrand.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
struct uint128
|
||||
{
|
||||
uint32_t a;
|
||||
uint32_t b;
|
||||
uint32_t c;
|
||||
uint32_t d;
|
||||
};
|
||||
|
||||
namespace mrand
|
||||
{
|
||||
uint128 getState(unsigned long long seed);
|
||||
float getFloat(uint128 *state);
|
||||
int getValue(int min, int max, uint128 *state);
|
||||
}
|
Reference in New Issue
Block a user