MCPcopy Create free account
hub / github.com/catabriga/graphwar / run

Method run

src/Graphwar/ComputerPlayer.java:292–443  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

290 }
291
292 public void run()
293 {
294 int gameMode = graphwar.getGameData().getGameMode();
295
296 EvolvableFunction[] functions = this.functions[this.getCurrentTurnSoldierIndex()];
297
298 double totalPoints = 0;
299
300 generationLoop:
301 for(int k=0; processingFunction && graphwar.getGameData().getGameState()==Constants.GAME && ((k<numGenerations && (graphwar.getGameData().getRemainingTime()) > 5000) || (over9000)); k++)
302 {
303
304 if(graphwar.getGameData().getCurrentTurnPlayer() == this)
305 {
306 functions = this.functions[this.currentTurnSoldier];
307 }
308 else
309 {
310 int nextTurnSoldier = this.getCurrentTurnSoldierIndex();
311
312 if(nextTurnSoldier == -1)
313 {
314 return;
315 }
316 else
317 {
318 functions = this.functions[nextTurnSoldier];
319 }
320 }
321
322 EvolvableFunction[] newFunctions = new EvolvableFunction[numFunctions];
323
324 totalPoints = getTotalPoints(functions);
325
326 for(int i=0; i<Constants.NUM_FUNCTIONS_UNCHANGED_TURN_AI; i++)
327 {
328 //newFunctions[i] = functions[getFunctionToReproduce(functions, totalPoints)];
329 newFunctions[i] = functions[i];
330 }
331
332 for(int i=Constants.NUM_FUNCTIONS_UNCHANGED_TURN_AI; i<Constants.NUM_FUNCTIONS_UNCHANGED_TURN_AI+Constants.NUM_FUNCTION_MUTATED_AI; i++)
333 {
334 newFunctions[i] = new EvolvableFunction();
335
336 int funcToMutate = getFunctionToReproduce(functions, totalPoints);
337 //int funcToMutate = 0;
338 newFunctions[i].function = new PolishNotationFunction(functions[funcToMutate].function, gameMode);
339 newFunctions[i].angle = functions[funcToMutate].angle;
340
341 if(gameMode==Constants.SND_ODE)
342 {
343 if(random.nextBoolean())
344 {
345 if(random.nextBoolean())
346 {
347 functions[i].angle = Math.PI*random.nextDouble()-Math.PI/2;
348 }
349 else

Callers

nothing calls this directly

Calls 10

getTotalPointsMethod · 0.95
evaluateFunctionMethod · 0.95
sendFunctionMethod · 0.95
getGameDataMethod · 0.80
getRemainingTimeMethod · 0.80
getCurrentTurnPlayerMethod · 0.80
getGameModeMethod · 0.45
getGameStateMethod · 0.45

Tested by

no test coverage detected