Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions NeuralNetwork/NeuralNetwork/LifeGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ char LifeGame::getXY(int X, int Y)
return (this->_field->getXY(X, Y));
}

vector<int> LifeGame::getResult()
{
vector<int> res(this->deadPlayers.size());
for (auto it = this->deadPlayers.begin(); it != this->deadPlayers.end(); ++it)
{
res[(*it)->_player->getID()] = (*it)->lastStep;
}
return res;
}

bool LifeGame::checkMove(int new_x, int new_y)
{
if (new_x > 0 && new_y > 0)
Expand Down
1 change: 1 addition & 0 deletions NeuralNetwork/NeuralNetwork/LifeGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class LifeGame
void initializeAllWithRnd(float a, float b);
void echo(bool value); // 1 - print 0 - don't print
char getXY(int X, int Y);
vector<int> getResult();
bool checkMove(int new_x, int new_y);

void step();
Expand Down
8 changes: 3 additions & 5 deletions NeuralNetwork/NeuralNetwork/NeuralNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ NeuralNetwork::~NeuralNetwork()
}
}

float * NeuralNetwork::getData(const string & ID)
vector<float> NeuralNetwork::getData(const string & ID)
{
Layer* layer = this->layers.find(ID)->second;
int n = (*layer).getSize();

if (n == 0)
return nullptr;

float* mas = new float[n];
vector<float> mas(n);
//float* mas = new float[n];

for (int i = 0; i < n; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion NeuralNetwork/NeuralNetwork/NeuralNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class NeuralNetwork
bool setLayerWeights(const string& ID, float value);
bool setActivationFunction(const string& ID, float(*f)(float));

float* getData(const string& ID);
vector<float> getData(const string& ID);

Layer* getLayer(const string& ID);

Expand Down
9 changes: 4 additions & 5 deletions NeuralNetwork/NeuralNetwork/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

float partFunction(float x)
{
if (x <= -0.25f)
if (x <= -0.5f)
return -1.0f;
if (x >= 0.25f)
if (x >= 0.5f)
return 1.0f;
else
return 0.0f;
Expand Down Expand Up @@ -212,9 +212,9 @@ void Player::activateNeuro(float * input)

this->neuro->activateLayer("sigmoid");

this->neuro->activatonFunction("output");
//this->neuro->activatonFunction("output");

float* output = (this->neuro->getData("output")); // output size = 2
vector<float> output = this->neuro->getData("sigmoid"); // output size = 2

int tmp_x = paramToInt(output[0]) + this->pos_x;
int tmp_y = paramToInt(output[1]) + this->pos_y;
Expand All @@ -225,7 +225,6 @@ void Player::activateNeuro(float * input)
this->pos_y = tmp_y;
}

delete[] output;
}

void Player::mutate(float a, float b)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
-0.72557657957 -0.40614634752
-0.36994007230 -0.77179467678
0.54482358694 0.66125631332
-1.18516445160 0.60362786055
0.19229166210 -0.28935742378
-1.75342512131 -0.07786682248
-0.58532649279 -1.16547143459
0.97608643770 -0.67785531282
0.63559800386 -0.60164779425
-0.32269579172 -0.71746587753
-0.97859632969 -0.15166762471
0.02242569253 -1.99261903763
-0.78190171719 0.46248430014
0.49818855524 0.67419129610
-1.38197875023 0.24851255119
0.10724135488 0.79875230789
0.50927275419 -1.73625540733
0.50397294760 0.82367759943
-1.91731619835 0.07602580637
0.89469015598 -1.65551042557
-1.14460301399 -1.91602575779
0.62713122368 -1.20222771168
0.84740078449 -1.15262115002
-0.76024019718 -0.38859438896
-0.08274416625 -0.73493307829
0.30916801095 0.60584396124
-0.97917473316 -0.99655014277
0.58235430717 -0.51539474726
-0.55282199383 -1.48869013786
-1.33806550503 0.82382029295
-0.93287909031 -0.79204231501
-0.79855328798 -0.99974471331
-0.12330394983 -1.77908039093
0.45447856188 -1.57397055626
0.23765815794 -0.69727629423
0.45790418983 -0.85875916481
-1.75754427910 -0.60978728533
-1.00911426544 -0.57517397404
-1.31637191772 -1.87753391266
0.22551876307 0.56240743399
-0.47627705336 -1.86317455769
-1.08057796955 -0.10497000068
-1.25448429585 -1.96512079239
-1.51364541054 -1.83087491989
-1.90684139729 -0.65523403883
-0.70537197590 -1.52377331257
-1.29761123657 -0.79503589869
0.26874101162 -1.60347783566
-1.66487693787 -0.59635877609
0.87664616108 -0.94734191895
-1.90675556660 -0.53596884012
-0.45646676421 0.51447242498
-0.05934403092 -1.40204560757
0.31129336357 -1.58941233158
0.70505338907 0.71017605066
-0.13439214230 -1.93271124363
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-0.36973053217 0.59947794676 -0.86793744564 0.58711421490 0.34405353665 -0.59677964449 0.23377805948 0.63076764345 -0.46215364337 0.64657652378 -0.78857016563 0.68019890785 -0.68718338013 0.84952348471 0.91254925728 -0.58837294579 0.07401360571 -0.99978798628 -0.27824229002 -0.03501671553 -0.06565977633 -0.75092375278 0.42006489635 -0.19380262494 -0.67729419470 -0.48383027315 0.53636884689 -0.02129899152
-0.38158595562 0.64221733809 0.73140627146 -0.89090090990 -0.19622737169 0.92640286684 0.94302469492 -0.58939993382 0.83151811361 0.18626318872 0.78558588028 -0.61475694180 0.96997630596 0.62224692106 -0.91112124920 0.59692269564 -0.70123046637 0.30491036177 0.25174102187 0.20664876699 0.68286305666 -0.08615478128 0.80601316690 -0.54013293982 0.98236566782 0.62613892555 0.87440675497 -0.75444698334
0.15783229470 0.46279016137 -0.55345791578 -0.23921290040 -0.11647964269 -0.59725099802 0.52365428209 0.50187969208 0.31353425980 0.94694560766 -0.64770060778 0.89565402269 -0.80774110556 0.35525262356 -0.69884228706 -0.11344311386 -0.56604969501 -0.82142806053 0.44858062267 -0.70860803127 0.58448469639 -0.26654914021 0.77053117752 -0.39888793230 0.26253929734 0.01810504496 -0.25985768437 0.79144543409
-0.02025397494 -0.12750647962 0.17374344170 0.09104421735 -0.14548155665 0.13206493855 -0.01872201636 -0.15412047505 0.13743197918 0.01311114896 -0.16439943016 -0.08945652843 0.05281800777 -0.01736357622 0.07308960706 -0.18953117728 0.15039911866 0.08961533755 0.02733595483 -0.06643521786 0.00362970331 0.17473039031 0.14773546159 -0.08584979922 -0.02391219512 -0.00221586111 -0.17483648658 0.14668773115
-0.03982288763 0.07808629423 -0.01766825467 -0.06336390972 0.04941292852 -0.14169839025 0.18534943461 0.15650586784 0.17476214468 -0.07998546958 -0.12498512864 0.16632147133 -0.07429192215 0.19985730946 0.16884917021 0.01551082637 -0.11661223322 0.00596169150 -0.19680880010 -0.15757358074 0.09318022430 0.09697260708 0.13913060725 0.08429864049 -0.07476017624 -0.14715807140 -0.07911434025 -0.09981153905
-0.73140108585 -0.18128134310 -0.24050323665 0.60270053148 -0.67094528675 0.61664646864 -0.30583459139 0.59350514412 -0.58802527189 0.80383610725 -0.69534903765 0.81384938955 0.76442700624 0.45988741517 0.67517226934 0.85727781057 0.84357953072 -0.91476011276 -0.54776138067 -0.68183416128 0.86500459909 0.57652527094 0.19584746659 -0.37079766393 0.68227463961 -0.81707042456 0.44720923901 0.33439898491
-0.15187828243 0.09229380637 -0.00257935189 -0.13449221849 -0.02118024603 0.10919152200 0.00417439314 0.05270624906 -0.11781196296 0.13849808276 0.08128109574 0.11358596385 0.12022089958 -0.09942422807 -0.00857584458 -0.01881923154 -0.07830753922 -0.07282365113 0.07364641875 0.04961930215 -0.06395774335 0.07867963612 -0.15074716508 0.07392071933 -0.06739383191 -0.11685746163 0.01265097409 -0.14716385305
-0.07418517023 -0.03729342669 -0.19300910830 -0.06686466187 0.13288897276 -0.04228108376 -0.05625942722 0.01486224774 -0.06194628775 0.18658722937 0.01157756895 -0.08990583569 -0.15549661219 0.18971662223 0.10646916926 -0.16192892194 -0.18323212862 -0.00511173811 0.00803370774 -0.18284311891 -0.15642628074 -0.04170976579 0.05066880211 0.03760647029 -0.06403997540 -0.17397107184 0.19678744674 0.00508671813
0.18438491225 -0.05940401182 0.19384798408 -0.16870231926 0.10068305582 0.17678380013 0.11537411064 0.00294313300 -0.14333179593 0.13307307661 0.02632713504 0.06687033921 0.16555689275 -0.04158123583 -0.01195319742 -0.07008554041 0.08135925233 -0.11772824079 -0.01561072469 0.03522622958 0.02718740702 0.06009895727 0.04958850890 0.02575608715 -0.19268545508 -0.05885015801 -0.08872704208 -0.09153474867
-0.11188304424 0.18971151114 0.15596373379 0.06184137613 -0.09218712896 0.15880951285 0.13389416039 -0.14347277582 -0.06900326908 0.13253481686 0.14859828353 0.10270562023 -0.10133572668 0.09426362813 -0.08059603721 -0.08624926209 0.05372596532 -0.14232073724 -0.01586335897 -0.07251894474 0.05971630663 -0.16448253393 -0.02727313526 0.11382339150 0.07747456431 0.09837758541 0.10600065440 -0.15742579103
-0.05408127233 0.06513681263 -0.11222590506 -0.04227430746 -0.05324415863 -0.14341424406 0.01756284386 -0.19199293852 0.01202782150 -0.19216321409 0.02764029801 -0.16590695083 0.18195784092 -0.04220211878 0.11414195597 0.10763295740 -0.15654619038 0.12332488596 -0.08840542287 -0.13014636934 0.18493619561 -0.03742296249 -0.18746300042 -0.03933567181 0.13539664447 -0.11380755901 -0.00863376167 -0.10237548500
-0.15741553903 -0.10168852657 0.17228828371 0.07863883674 -0.06329447031 -0.16302466393 -0.00260299793 0.01537345350 0.05586158857 0.12757800519 0.01527035888 -0.18293571472 -0.14052282274 -0.06633287668 -0.09465920925 -0.13552451134 -0.08361063898 -0.17002743483 0.00850624777 0.12935590744 -0.07867908478 0.04793708026 -0.08200079203 0.03623574972 -0.14051364362 0.04288348556 0.12579677999 0.14207379520
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
0.84850394726 0.54447954893
0.18077912927 -0.46775090694
0.18750473857 0.24129742384
-1.18516445160 0.60362786055
0.19229166210 -0.28935742378
0.81479763985 -0.13418117166
-0.49571675062 -1.11198866367
0.35243910551 0.44407421350
-1.10759198666 0.13096280396
-0.68522387743 -1.59267818928
-0.97859632969 -0.15166762471
-0.04674031213 -0.06437162310
-0.78190171719 0.46248430014
0.49818855524 0.67419129610
-1.38197875023 0.24851255119
-1.91425549984 -1.94214677811
0.00466748513 -0.07990094274
0.82022666931 -0.80422240496
0.78273588419 -0.37542298436
-0.41129338741 -0.92066723108
-1.14460301399 -1.91602575779
-1.68509554863 -1.53499996662
-0.82508271933 0.90257191658
0.29412892461 -0.45091140270
-0.08274416625 -0.73493307829
0.30916801095 0.60584396124
-0.79933214188 -0.92620187998
-0.67604005337 -0.86511319876
-0.55282199383 -1.48869013786
-1.33806550503 0.82382029295
-0.93287909031 -0.79204231501
-0.79855328798 -0.99974471331
-0.12330394983 -1.77908039093
-0.18734696507 -0.68596726656
0.79529213905 0.11040164530
-1.05346035957 -1.82430791855
-1.43282771111 -1.37845826149
-1.00911426544 -0.57517397404
-1.31637191772 -1.87753391266
0.22551876307 0.56240743399
-0.11033470929 0.58037948608
0.72517007589 -0.06812343001
-1.25448429585 -1.96512079239
-1.51364541054 -1.83087491989
-1.90684139729 -0.65523403883
-0.70537197590 -1.52377331257
-1.29761123657 -0.79503589869
0.26874101162 -1.60347783566
0.90732210875 0.83232426643
-1.75887799263 -1.36176300049
-1.90675556660 -0.53596884012
-0.45646676421 0.51447242498
-0.06104682386 0.67738342285
0.31129336357 -1.58941233158
-1.12890195847 0.37683039904
-0.13439214230 -1.93271124363
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-0.36973053217 0.59947794676 -0.86793744564 0.58711421490 0.34405353665 -0.59677964449 0.23377805948 0.63076764345 -0.46215364337 0.64657652378 -0.78857016563 0.68019890785 -0.68718338013 0.84952348471 0.91254925728 -0.58837294579 0.07401360571 -0.99978798628 -0.27824229002 -0.03501671553 -0.06565977633 -0.75092375278 0.42006489635 -0.19380262494 -0.67729419470 -0.48383027315 0.53636884689 -0.02129899152
-0.79299306870 -0.23062452674 -0.25029277802 0.56816661358 -0.93247961998 0.09776661545 0.89846479893 0.81578874588 -0.43782067299 -0.08472426981 0.87201523781 0.10938736051 0.78513801098 -0.80813735723 -0.45005890727 -0.86553174257 0.14640317857 -0.34216964245 -0.19704891741 0.92956548929 0.92524790764 -0.22041150928 -0.14710965753 -0.12993064523 -0.58742105961 -0.55798602104 -0.53959494829 0.74785876274
0.15783229470 0.46279016137 -0.55345791578 -0.23921290040 -0.11647964269 -0.59725099802 0.52365428209 0.50187969208 0.31353425980 0.94694560766 -0.64770060778 0.89565402269 -0.80774110556 0.35525262356 -0.69884228706 -0.11344311386 -0.56604969501 -0.82142806053 0.44858062267 -0.70860803127 0.58448469639 -0.26654914021 0.77053117752 -0.39888793230 0.26253929734 0.01810504496 -0.25985768437 0.79144543409
0.06873693317 -0.16427475214 0.01422033273 -0.13086344302 -0.11683374643 -0.18078704178 0.05475123599 -0.08494130522 -0.03724271059 -0.13001354039 0.11961603165 -0.09708122909 -0.08131416142 0.19562697411 0.06451602280 -0.04556246847 -0.16742092371 0.10050830245 -0.07844925672 0.09351625293 -0.01620135643 0.19954691827 -0.02670445293 0.17666064203 -0.01316694170 0.03706429526 0.05100888014 0.18185466528
0.99642014503 -0.42868033051 -0.60571175814 0.32690957189 -0.27604436874 0.10390478373 0.13244803250 -0.92646670341 0.74865078926 -0.57555991411 0.85003930330 0.84483242035 -0.38034352660 0.58821880817 0.67331546545 -0.91658467054 0.28238132596 0.35177034140 0.12143133581 -0.80319356918 -0.04914867878 0.14775536954 0.04584767669 0.76029461622 -0.23614701629 -0.64379960299 0.13913436234 -0.89029252529
-0.73140108585 -0.18128134310 -0.24050323665 0.60270053148 -0.67094528675 0.61664646864 -0.30583459139 0.59350514412 -0.58802527189 0.80383610725 -0.69534903765 0.81384938955 0.76442700624 0.45988741517 0.67517226934 0.85727781057 0.84357953072 -0.91476011276 -0.54776138067 -0.68183416128 0.86500459909 0.57652527094 0.19584746659 -0.37079766393 0.68227463961 -0.81707042456 0.44720923901 0.33439898491
-0.15187828243 0.09229380637 -0.00257935189 -0.13449221849 -0.02118024603 0.10919152200 0.00417439314 0.05270624906 -0.11781196296 0.13849808276 0.08128109574 0.11358596385 0.12022089958 -0.09942422807 -0.00857584458 -0.01881923154 -0.07830753922 -0.07282365113 0.07364641875 0.04961930215 -0.06395774335 0.07867963612 -0.15074716508 0.07392071933 -0.06739383191 -0.11685746163 0.01265097409 -0.14716385305
0.18453267217 0.10176143050 0.16431467235 0.10324993730 -0.00682878308 0.15209646523 -0.11679937690 0.02747481503 -0.03207992390 -0.04954764247 0.02638608404 0.01743670925 0.06517786533 -0.15782059729 -0.18951313198 0.08201754838 -0.08132551610 0.13429300487 -0.16745649278 0.06896813214 0.19374312460 -0.16368842125 -0.07738216966 0.00530706486 -0.03693070263 0.02025382593 0.00156172831 0.16746686399
0.17613610625 0.06654926389 0.13375245035 -0.13708268106 -0.18471701443 0.18273679912 -0.11920930445 0.10100778937 0.09906219691 0.19952309132 0.14628712833 0.09852022678 -0.12513446808 -0.17172311246 0.09733323753 0.01941599324 0.05040989071 -0.02040884085 0.18628785014 0.17790514231 -0.19088746607 -0.08932547271 -0.02548219450 -0.11074806005 -0.09413211793 -0.11280904710 -0.12237159163 -0.13375355303
0.16856546700 0.18327009678 -0.08965478837 0.15536621213 -0.01395557355 0.11332013458 0.02999859862 -0.01680222154 0.05065923557 -0.12016289681 0.15380419791 0.00240294170 0.13946889341 0.14001318812 0.11994133890 0.18516933918 0.04559151083 0.08047540486 0.04173139483 -0.08143686503 0.14721435308 -0.14047375321 -0.01828250475 -0.13068959117 -0.03507445753 -0.08487580717 -0.02712112665 -0.11203888059
0.12314139307 -0.02478526160 -0.01188601367 0.09549932927 0.02285283990 0.16054052114 0.04773806781 -0.02943749540 -0.04761998728 -0.13705217838 -0.07649653405 -0.14529609680 0.19630056620 0.04843864962 -0.06609395891 0.18291296065 0.12117855251 0.06518803537 0.17188990116 0.03572027013 0.00769444183 -0.08869940788 0.07314161956 0.02002328262 0.04405522719 -0.05955605954 0.16450323164 -0.04595652595
-0.15741553903 -0.10168852657 0.17228828371 0.07863883674 -0.06329447031 -0.16302466393 -0.00260299793 0.01537345350 0.05586158857 0.12757800519 0.01527035888 -0.18293571472 -0.14052282274 -0.06633287668 -0.09465920925 -0.13552451134 -0.08361063898 -0.17002743483 0.00850624777 0.12935590744 -0.07867908478 0.04793708026 -0.08200079203 0.03623574972 -0.14051364362 0.04288348556 0.12579677999 0.14207379520
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
-0.72557657957 -0.40614634752
-0.36994007230 -0.77179467678
0.54482358694 0.66125631332
-1.18516445160 0.60362786055
0.19229166210 -0.28935742378
0.81479763985 -0.13418117166
-0.49571675062 -1.11198866367
0.35243910551 0.44407421350
-1.10759198666 0.13096280396
-0.32269579172 -0.71746587753
-0.97859632969 -0.15166762471
-0.04674031213 -0.06437162310
-0.78190171719 0.46248430014
0.49818855524 0.67419129610
-1.38197875023 0.24851255119
-1.91425549984 -1.94214677811
0.50927275419 -1.73625540733
0.50397294760 0.82367759943
0.78273588419 -0.37542298436
-0.41129338741 -0.92066723108
-1.14460301399 -1.91602575779
0.21300297976 -1.81829798222
-1.11847698689 -0.68426817656
0.29412892461 -0.45091140270
-0.08274416625 -0.73493307829
0.30916801095 0.60584396124
-0.79933214188 -0.92620187998
-0.67604005337 -0.86511319876
0.10471227765 -0.99183839560
0.04748635367 -0.98766791821
0.83867520094 -1.22834658623
0.42154788971 -0.92872446775
-1.11650478840 -1.72806942463
-0.18734696507 -0.68596726656
0.98674309254 -1.43744444847
-1.05346035957 -1.82430791855
-1.43282771111 -1.37845826149
-0.99770987034 0.49665865302
-0.94316536188 -0.44816532731
-0.65998065472 -1.91676521301
-1.46612870693 -0.81314557791
-0.40269783139 -1.56849920750
-1.57373428345 -1.69930315018
-1.63856422901 -1.59266173840
-0.71024322510 0.89822936058
-1.81898069382 -0.76668244600
0.14721588790 -1.70641863346
0.33364710212 -0.79052972794
0.90732210875 0.83232426643
-0.37773668766 0.18230673671
-0.20985427499 -0.88042598963
-0.63976234198 -0.55460107327
-1.26887774467 0.44946801662
0.17659169436 -0.55301088095
0.62445342541 -0.81522792578
-0.54445606470 -1.65574288368
Loading