Differences From Artifact [b27a6df805fe9112]:
- File        
test.d
- 2012-07-13 14:16:22 - part of checkin [b59ee91407] on branch trunk - GUI version. (user: kinaba) [annotate]
 
 
To Artifact [ab6badd03b0f582a]:
- File        
test.d
- 2012-07-13 14:32:47 - part of checkin [8f5135c552] on branch trunk - tenuki scoring. (user: kinaba) [annotate]
 
 
    42     42       if(i) result ~= '\n';
    43     43       result ~= s.idup;
    44     44      }
    45     45      return result;
    46     46     }
    47     47    }
    48     48   
    49         - void command_R() { move(0, +1); }
    50         - void command_L() { move(0, -1); }
    51         - void command_U() { move(-1, 0); }
    52         - void command_D() { move(+1, 0); }
    53         - void wait() { update(); }
           49  + int command_R() { return move(0, +1); }
           50  + int command_L() { return move(0, -1); }
           51  + int command_U() { return move(-1, 0); }
           52  + int command_D() { return move(+1, 0); }
           53  + int wait() { update(); return -1; }
    54     54   
    55         - void move(int dy, int dx) {
           55  + int move(int dy, int dx) {
    56     56     foreach(y,s; data)
    57     57     foreach(x,c; s)
    58     58      if(c == 'R')
    59     59       return move(dy, dx, y, x);
           60  +  assert(false);
    60     61    }
    61     62   
    62         - void move(int dy, int dx, int y, int x) {
           63  + int gained = 0; // TODO: atode naosu
           64  + int move(int dy, int dx, int y, int x) {
           65  +  int score = 0;
           66  +  if(data[y+dy][x+dx]=='\\') {
           67  +   score += 25;
           68  +   ++gained;
           69  +  }
           70  +  if(data[y+dy][x+dx]=='O')
           71  +   score += gained*50;
           72  +
    63     73     if(data[y+dy][x+dx]==' ' || data[y+dy][x+dx]=='.'
    64     74        || data[y+dy][x+dx]=='\\' || data[y+dy][x+dx]=='O') {
    65     75      data[y][x]=' ';
    66     76      data[y+dy][x+dx]='R';
    67     77     } else if(dy==0 && data[y+dy][x+dx]=='*' && data[y+2*dy][x+2*dx]==' ') {
    68     78      data[y][x]=' ';
    69     79      data[y+dy][x+dx]='R';
    70     80      data[y+2*dy][x+2*dx]='*';
    71     81     }
    72     82     update();
           83  +  return score-1;
    73     84    }
    74     85   
    75     86    void update() {
    76     87     char[][] next;
    77     88     foreach(y,s; data)
    78     89      next ~= s.dup;
    79     90   
................................................................................
   110    121     data = next;
   111    122    }
   112    123   }
   113    124   
   114    125   class MyForm : Form
   115    126   {
   116    127    Map m;
          128  + int score;
          129  +
   117    130    this(Map m)
   118    131    {
   119    132     noMessageFilter();
   120    133     this.m = m;
   121    134     this.text = "Dark Integers";
   122    135     this.keyDown ~= &myKey;
          136  +  this.score = 0;
   123    137    }
   124    138    override void onResize(EventArgs ev) {
   125    139     invalidate();
   126    140    }
   127    141    override void onPaint(PaintEventArgs ev)
   128    142    {
   129    143     int Z = min(this.clientSize.width, this.clientSize.height) / max(m.W-2, m.H-2);
................................................................................
   155    169     }
   156    170    }
   157    171    void myKey(Control c, KeyEventArgs ev)
   158    172    {
   159    173     switch(ev.keyCode)
   160    174     {
   161    175     case Keys.DOWN:
   162         -   m.command_D();
          176  +   score += m.command_D();
          177  +   write("D");
          178  +   stdout.flush();
   163    179      break;
   164    180     case Keys.UP:
   165         -   m.command_U();
          181  +   score += m.command_U();
          182  +   write("U");
          183  +   stdout.flush();
   166    184      break;
   167    185     case Keys.LEFT:
   168         -   m.command_L();
   169         -    break;
          186  +   score += m.command_L();
          187  +   write("L");
          188  +   stdout.flush();
          189  +   break;
   170    190     case Keys.RIGHT:
   171         -   m.command_R();
          191  +   score += m.command_R();
          192  +   write("R");
          193  +   stdout.flush();
   172    194      break;
   173    195     case Keys.W:
   174         -   m.wait();
          196  +   score += m.wait();
          197  +   write("W");
          198  +   stdout.flush();
   175    199      break;
   176    200     default:
   177    201      break;
   178    202     }
          203  +  this.text = .text("Score: ", score);
   179    204     invalidate();
   180    205    }
   181    206   }
   182    207   
   183    208   void main(string[] args)
   184    209   {
   185    210    Form myForm = new MyForm(new Map(File(args[1])));
   186    211    Application.run(myForm);
   187    212   }