void MainLogicLoop(){ //TODO lock the camera //lockCamera(&processHandle); //read the data at these pointers, now that offsets have been added and we have a static address ReadPlayer(&Enemy, processHandle, EnemyId); ReadPlayer(&Player, processHandle, PlayerId); //log distance in memory AppendDistance(distance(&Player, &Enemy)); //start the neural network threads WakeThread(defense_mind_input); WakeThread(attack_mind_input); ResetVJoyController(); //begin reading enemy state, and handle w logic and subroutines char attackImminent = EnemyStateProcessing(&Player, &Enemy); WaitForThread(defense_mind_input); guiPrint(LocationDetection",1:Defense Neural Network detected %d, and Attack %d", DefenseChoice, AttackChoice); #if DebuggingPacifyDef DefenseChoice = 0; #endif //defense mind makes choice to defend or not(ex backstab metagame decisions). //handles actually backstab checks, plus looks at info from obveous direct attacks from aboutToBeHit if (attackImminent == ImminentHit || inActiveDodgeSubroutine() || (DefenseChoice>0)){ dodge(&Player, &Enemy, &iReport, attackImminent, DefenseChoice); } WaitForThread(attack_mind_input); guiPrint(LocationDetection",2:Attack Neural Network decided %d", AttackChoice); #if DebuggingPacifyAtk AttackChoice = 0; #endif //attack mind make choice about IF to attack or not, and how to attack //enter when we either have a Attack neural net action or a attackImminent action if (inActiveAttackSubroutine() || attackImminent != ImminentHit || (AttackChoice && DefenseChoice<=0)){ attack(&Player, &Enemy, &iReport, attackImminent, AttackChoice); } //unset neural network desisions DefenseChoice = 0; AttackChoice = 0; //handle subroutine safe exits SafelyExitSubroutines(); guiPrint(LocationDetection",5:Current Subroutine States ={%d,%d,%d,%d}", subroutine_states[0], subroutine_states[1], subroutine_states[2], subroutine_states[3]); //send this struct to the driver (only 1 call for setting all controls, much faster) guiPrint(LocationJoystick",0:AxisX:%d\nAxisY:%d\nButtons:0x%x", iReport.wAxisX, iReport.wAxisY, iReport.lButtons); UpdateVJD(iInterface, (PVOID)&iReport); //SetForegroundWindow(h); //SetFocus(h); }
//have random attacks. if it doesnt get hit, sucess. if it gets hit, fail. void getTrainingDataforAttack(void) { FILE* fpatk = fopen("E:/Code Workspace/Dark Souls AI C/Neural Nets/attack_training_data.train", "a"); unsigned int trainingLinesCountAtk = 0; SetupandLoad(); //float distanceStorage[50];//every 100 ms, LENGTH*100 is memory length float poiseEnemy; float weaponPoiseDamage; float enemyStaminaEstimate;//use the last_animation_ids_enemy to estimate enemy stamina while (listening){ ReadPlayer(&Player, processHandle, LocationMemoryPlayer); ReadPlayer(&Enemy, processHandle, LocationMemoryEnemy); AppendDistance(distance(&Player, &Enemy)); AppendAnimationTypeEnemy(Enemy.animationType_id); if (isAttackAnimation(Player.animationType_id)){ int startingHp = Player.hp; while (isAttackAnimation(Player.animationType_id)){ ReadPlayer(&Player, processHandle, LocationMemoryPlayer); } float result = 0; //bad outcome if (startingHp != Player.hp){ result = -1; } //good outcome else{ result = 1; } trainingLinesCountAtk++; /*fprintf(fpatk, "%f %f %f\n", (float)stateBuffer[3]->animation_id, (float)stateBuffer[2]->animation_id, result );*/ //save //printf("result:%f, SelfAnimation %f, EnmyAnimation %f\n", result, (float)stateBuffer[2]->animation_id, (float)stateBuffer[3]->animation_id); } } fprintf(fpatk, "## = %d\n", trainingLinesCountAtk); fclose(fpatk); }