Overview
SHA1 Hash: | 879099f815ae88e83e6eb88e0c16a6798e6afca8 |
---|---|
Date: | 2012-07-15 13:44:33 |
User: | kinaba |
Comment: | Moved 'abort' behavior completely out of Game. |
Timelines: | family | ancestors | descendants | both | trunk |
Diffs: | redesign |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [16f0b5784f]
- sym-trunk inherited from [16f0b5784f]
Changes
Modified src/game.d from [9d4255819d57ec36] to [0eb850e277f37179].
391 Game clone() const { return new Game(this); } 391 Game clone() const { return new Game(this); } 392 this(in Game g) { 392 this(in Game g) { 393 map = g.map.clone(); 393 map = g.map.clone(); 394 water = g.water.clone(); 394 water = g.water.clone(); 395 turn = g.turn; 395 turn = g.turn; 396 dead = g.dead; 396 dead = g.dead; 397 lambda = g.lambda; 397 lambda = g.lambda; 398 exit_bonus = g.exit_bonus; | 398 cleared = g.cleared; 399 under_water = g.under_water; 399 under_water = g.under_water; 400 } 400 } 401 401 402 void command(char c) 402 void command(char c) 403 { 403 { > 404 assert(c != 'A'); 404 if(dead || cleared) 405 if(dead || cleared) 405 return; 406 return; 406 407 407 if(c == 'A') < 408 { < 409 exit_bonus = 1; < 410 return; < 411 } < 412 < 413 // TODO: clarify the event order 408 // TODO: clarify the event order 414 Tuple!(int,bool) ld = map.command(c, turn); 409 Tuple!(int,bool) ld = map.command(c, turn); 415 if( map.cleared() ) { 410 if( map.cleared() ) { 416 exit_bonus = 2; | 411 cleared = true; 417 } 412 } 418 else { 413 else { 419 lambda += ld[0]; 414 lambda += ld[0]; 420 if( ld[1] ) { | 415 if( ld[1] ) 421 dead = true; 416 dead = true; 422 } < 423 } 417 } 424 if( map.robot.y <= water_level ) 418 if( map.robot.y <= water_level ) 425 ++under_water; 419 ++under_water; 426 else 420 else 427 under_water = 0; 421 under_water = 0; 428 if( under_water > map.waterproof ) 422 if( under_water > map.waterproof ) 429 dead = true; 423 dead = true; ................................................................................................................................................................................ 431 } 425 } 432 426 433 Map map; 427 Map map; 434 Water water; 428 Water water; 435 int turn = 0; 429 int turn = 0; 436 bool dead = false; 430 bool dead = false; 437 int lambda = 0; 431 int lambda = 0; 438 int exit_bonus = 0; < 439 int under_water = 0; 432 int under_water = 0; > 433 bool cleared = false; 440 // TODO: when adding members, take care of clone(). 434 // TODO: when adding members, take care of clone(). 441 // TODO: fix this poor design. 435 // TODO: fix this poor design. 442 436 443 @property const { 437 @property const { 444 long score() { return lambda*25L*(1+exit_bonus) - turn; } | 438 long score() { return lambda*(dead ? 25L : cleared ? 75L : 50L) 445 int water_level() { return water.level(turn); } 439 int water_level() { return water.level(turn); } 446 int water_until_rise() { return water.until_rise(turn); } 440 int water_until_rise() { return water.until_rise(turn); } 447 int hige_until_rise() { return map.hige.until_rise(turn); } 441 int hige_until_rise() { return map.hige.until_rise(turn); } 448 bool cleared() { return exit_bonus>0; } < 449 int hp() { return map.waterproof - under_water; } 442 int hp() { return map.waterproof - under_water; } 450 long score_if_abort_now() { return lambda*25*(1+max(1,exit_bonus < 451 } 443 } 452 } 444 }
Modified src/output.d from [62e6040714438eff] to [ef5cfcc2ac51c863].
20 } 20 } 21 21 22 class GuardedOutput : GameObserver 22 class GuardedOutput : GameObserver 23 { 23 { 24 this(in Game g) 24 this(in Game g) 25 { 25 { 26 setup_sigint_handling(); 26 setup_sigint_handling(); 27 ideal_log ~= g.score_if_abort_now; | 27 score_log ~= g.score; 28 flushed = false; 28 flushed = false; 29 } 29 } 30 30 31 override void on_game_changed(char c, in Game g, bool finished) 31 override void on_game_changed(char c, in Game g, bool finished) 32 { 32 { 33 if(flushed) 33 if(flushed) 34 return; 34 return; 35 35 36 log ~= c; 36 log ~= c; 37 score_log ~= g.score; 37 score_log ~= g.score; 38 ideal_log ~= g.score_if_abort_now; < 39 if(finished || log.length+1==g.map.W*g.map.H) 38 if(finished || log.length+1==g.map.W*g.map.H) 40 flush(); 39 flush(); 41 } 40 } 42 41 43 private: 42 private: 44 string log; 43 string log; 45 long[] score_log; 44 long[] score_log; 46 long[] ideal_log; < 47 bool flushed; 45 bool flushed; 48 46 49 void flush() 47 void flush() 50 { 48 { 51 Tuple!(long, int, int) cand; | 49 Tuple!(long, int) cand; 52 cand[0] = long.min; 50 cand[0] = long.min; 53 51 54 for(int i=0; i<score_log.length; ++i) 52 for(int i=0; i<score_log.length; ++i) 55 if(cand[0] < score_log[i]) 53 if(cand[0] < score_log[i]) 56 cand = tuple(score_log[i],i,0); | 54 cand = tuple(score_log[i],i); 57 for(int i=0; i<ideal_log.length; ++i) < 58 if(cand[0] < ideal_log[i]) < 59 cand = tuple(ideal_log[i],i,1); < 60 55 61 if(cand[2]==0) { < 62 string str = log[0..cand[1]+1]; < 63 std.c.stdio.printf("%.*s\n", str.length, str.ptr); < 64 } else { < 65 string str = log[0..cand[1]]; < 66 std.c.stdio.printf("%.*sA\n", str.length, str.ptr); | 56 std.c.stdio.printf("%.*sA\n", cand[1], log.ptr); 67 } < 68 std.c.stdio.fflush(std.c.stdio.stdout); 57 std.c.stdio.fflush(std.c.stdio.stdout); 69 flushed = true; 58 flushed = true; 70 } 59 } 71 60 72 private: 61 private: 73 static __gshared GuardedOutput g_output; 62 static __gshared GuardedOutput g_output; 74 63
Modified src/solver.d from [98744373e0968733] to [ede3d182d99f2de5].
1 import util; 1 import util; 2 import game; 2 import game; 3 3 4 class Solver_0 4 class Solver_0 5 { 5 { 6 this(const(Game) g) {} | 6 this(in Game g) {} 7 char single_step() { return 'W'; } 7 char single_step() { return 'W'; } 8 void force(char c) {} 8 void force(char c) {} 9 } 9 } 10 10 11 class Solver_1 11 class Solver_1 12 { 12 { 13 int wait_count = 0; 13 int wait_count = 0; 14 int choke_count = 0; 14 int choke_count = 0; 15 15 16 Game g; 16 Game g; 17 this(const(Game) g) | 17 this(in Game g) 18 { 18 { 19 this.g = g.clone(); 19 this.g = g.clone(); 20 forbidden_cell = new bool[][](g.map.H+2, g.map.W+2); 20 forbidden_cell = new bool[][](g.map.H+2, g.map.W+2); 21 } 21 } 22 22 23 char single_step() 23 char single_step() 24 { 24 { 25 Tuple!(string,int) de = death_move(g); 25 Tuple!(string,int) de = death_move(g); 26 char c = act(g, de[0], de[1]); 26 char c = act(g, de[0], de[1]); 27 g.command(c); | 27 force(c); 28 return c; 28 return c; 29 } 29 } 30 30 31 void force(char c) 31 void force(char c) 32 { 32 { > 33 if(c != 'A') 33 g.command(c); | 34 g.command(c); 34 } 35 } 35 36 36 Tuple!(string,int) death_move(const(Game) g) 37 Tuple!(string,int) death_move(const(Game) g) 37 { 38 { 38 string death; 39 string death; 39 int choice = 0; 40 int choice = 0; 40 foreach(char c; "UDLRW") { 41 foreach(char c; "UDLRW") {