Diff
Not logged in

Differences From Artifact [fc45f9bc575c213e]:

To Artifact [5e89251084030d6c]:


325 Game current_game; 325 Game current_game; 326 SubSolver sub_solver; 326 SubSolver sub_solver; 327 327 328 enum {Tentative, Tentative_Stuck, Fixed}; 328 enum {Tentative, Tentative_Stuck, Fixed}; 329 string plan; 329 string plan; 330 int plan_state; 330 int plan_state; 331 int replan_limit; 331 int replan_limit; > 332 bool lambda_getter; 332 333 333 this(in Game g) 334 this(in Game g) 334 { 335 { 335 current_game = g.clone(); 336 current_game = g.clone(); 336 plan = ""; 337 plan = ""; 337 plan_state = Tentative; 338 plan_state = Tentative; 338 replan_limit = PredictFuture; 339 replan_limit = PredictFuture; ................................................................................................................................................................................ 353 return 'A'; 354 return 'A'; 354 355 355 // Make enough prediction. 356 // Make enough prediction. 356 while( plan_state==Tentative && plan.length<replan_limit ) 357 while( plan_state==Tentative && plan.length<replan_limit ) 357 single_step_predict(); 358 single_step_predict(); 358 359 359 // If the future is bad, correct. 360 // If the future is bad, correct. 360 if( plan_state==Tentative_Stuck && plan.length<replan_limit ) | 361 if( plan_state==Tentative_Stuck && plan.length<replan_limit && ! 361 replan(); 362 replan(); 362 363 363 // Follow the predicted plan. 364 // Follow the predicted plan. 364 if( plan.empty ) 365 if( plan.empty ) 365 return 'A'; 366 return 'A'; 366 stderr.writeln(plan, " ", plan_state); 367 stderr.writeln(plan, " ", plan_state); 367 char c = plan[0]; 368 char c = plan[0]; 368 plan = plan[1..$]; 369 plan = plan[1..$]; > 370 int b_lambda = current_game.map.collected_lambda; 369 current_game.command(c); 371 current_game.command(c); > 372 int a_lambda = current_game.map.collected_lambda; > 373 if(b_lambda < a_lambda) lambda_getter = false; 370 return c; 374 return c; 371 } 375 } 372 376 373 void force(char c) 377 void force(char c) 374 { 378 { 375 if(plan.length>0 && plan[0]==c) 379 if(plan.length>0 && plan[0]==c) 376 { 380 { ................................................................................................................................................................................ 406 410 407 void replan() 411 void replan() 408 { 412 { 409 stderr.writeln("replan!"); 413 stderr.writeln("replan!"); 410 // Try to replace every step of the plan by another move. 414 // Try to replace every step of the plan by another move. 411 Game g = current_game.clone(); 415 Game g = current_game.clone(); 412 Tuple!(SubSolver, string, int) cand = tuple(sub_solver, plan, Te 416 Tuple!(SubSolver, string, int) cand = tuple(sub_solver, plan, Te > 417 writeln(cand, " ", cand[0].g.map.collected_lambda); 413 bool tiebreak_by_turn = false; 418 bool tiebreak_by_turn = false; 414 for(int i=0; i<plan.length; ++i) { 419 for(int i=0; i<plan.length; ++i) { 415 foreach(string prefix; RandomChoicePattern) 420 foreach(string prefix; RandomChoicePattern) 416 if(prefix[0] != plan[i]) { 421 if(prefix[0] != plan[i]) { 417 Tuple!(SubSolver, string, int) r = try_p 422 Tuple!(SubSolver, string, int) r = try_p 418 r[1] = plan[0..i] ~ prefix ~ r[1]; 423 r[1] = plan[0..i] ~ prefix ~ r[1]; 419 bool better = false, tbt=false; 424 bool better = false, tbt=false; ................................................................................................................................................................................ 425 else if(!cand[0].g.cleared && !r[0].g.cl 430 else if(!cand[0].g.cleared && !r[0].g.cl 426 if(cand[0].g.map.collected_lambd 431 if(cand[0].g.map.collected_lambd 427 better = true; 432 better = true; 428 else if(cand[0].g.map.collected_ 433 else if(cand[0].g.map.collected_ 429 if(cand[0].g.dead && !r[ 434 if(cand[0].g.dead && !r[ 430 better = true; 435 better = true; 431 else if(cand[0].g.dead = 436 else if(cand[0].g.dead = 432 better = (cand[1 | 437 better = (cand[1 433 tbt = true; 438 tbt = true; 434 } 439 } 435 } 440 } 436 } 441 } 437 if(better) { 442 if(better) { 438 cand = r; 443 cand = r; 439 tiebreak_by_turn = true; 444 tiebreak_by_turn = true; 440 writeln(cand); | 445 writeln(cand, " ", cand[0].g.map.collected_lambda); 441 } 446 } 442 } 447 } 443 g.command(plan[i]); 448 g.command(plan[i]); 444 } 449 } 445 450 446 sub_solver = cand[0]; 451 sub_solver = cand[0]; 447 plan = cand[1]; 452 plan = cand[1]; 448 plan_state = (plan.length < PredictFuture ? Fixed : cand[2]); 453 plan_state = (plan.length < PredictFuture ? Fixed : cand[2]); 449 replan_limit = tiebreak_by_turn ? min(PredictFuture, plan.length 454 replan_limit = tiebreak_by_turn ? min(PredictFuture, plan.length > 455 lambda_getter = current_game.map.collected_lambda < cand[0].g.ma 450 } 456 } 451 457 452 Tuple!(SubSolver, string, int) try_plan(in Game g, string prefix) 458 Tuple!(SubSolver, string, int) try_plan(in Game g, string prefix) 453 { 459 { 454 SubSolver s = new SubSolver(g); 460 SubSolver s = new SubSolver(g); 455 foreach(char c; prefix) 461 foreach(char c; prefix) 456 s.force(c); 462 s.force(c);