Check-in [ffac82fc99]
Not logged in
Overview
SHA1 Hash:ffac82fc9986ec31762c42225aa294a212792a5d
Date: 2012-07-16 09:38:53
User: kinaba
Comment:Hopefully the correct way to detect deadly-round-trip.
Timelines: family | ancestors | descendants | both | trunk
Diffs: redesign
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified src/solver.d from [fc45f9bc575c213e] to [5e89251084030d6c].

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