2048.html
author Oleksandr Gavenko <gavenkoa@gmail.com>
Tue, 09 Sep 2014 20:33:17 +0300
changeset 33 f1bbe12e2c3d
parent 32 f48151863cdf
child 34 16b711a81a16
permissions -rw-r--r--
Highlight score area.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
<!DOCTYPE html>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
<html>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
<head>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
  <title>2048 AI</title>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
  <meta name="viewport" content="width=device-width; initial-scale=1.0"/>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
  <meta charset="utf-8"/>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
10
70ece7f758a0 Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 7
diff changeset
     8
  <script src="rule.js"></script>
7
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
     9
  <script src="board.js"></script>
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
    10
  <script src="perf.js"></script>
10
70ece7f758a0 Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 7
diff changeset
    11
  <script src="ai.js"></script>
7
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
    12
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
  <style>
27
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    14
    body {
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    15
      font-size: 11pt;
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    16
    }
4
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
    17
    h1, div.area {
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
      text-align: center;
4
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
    19
      margin: 10px auto;
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
    }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
    #board {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
      margin: 10px auto;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
    }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
    #board td {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
      width: 40px;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
      height: 40px;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    27
      border: 1px solid red;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
      margin: 0;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
      text-align: center;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
    }
33
f1bbe12e2c3d Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 32
diff changeset
    31
    div.ai-control, div.move-control, div.score-conrol {
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    32
      border: 1px red solid;
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    33
      display: inline-block;
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    34
      margin: 10px 0 2px 0;
31
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
    35
      background-color: cornsilk;
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
    36
    }
33
f1bbe12e2c3d Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 32
diff changeset
    37
    div.move-control, div.score-conrol {
f1bbe12e2c3d Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 32
diff changeset
    38
      padding: 3px;
31
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
    39
    }
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
    40
    div.ai-control {
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    41
      padding: 2px 2px 2px 1em;
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    42
    }
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    43
    div.ai-control:before {
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    44
      content: "AI: ";
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    45
      margin-left: -.5em;
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    46
      padding: 0;
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    47
    }
4
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
    48
    .report > .name {
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
    49
      font-weight: bold;
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
    50
    }
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    51
    div.ai {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    52
      border: 1px red solid;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    53
      margin-top: 20px;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    54
      padding: 2px;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    55
      position: relative;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    56
      background-color: cornsilk;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    57
    }
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    58
    div.ai.enabled {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    59
      background-color: wheat;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    60
    }
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    61
    div.ai > h5 {
27
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    62
      margin: 2px 0 2px 6em;
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    63
    }
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    64
    button.ai {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    65
      position: absolute;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    66
      left: 1em;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    67
      top: -1em;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    68
    }
27
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    69
    div.ai > div.option {
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    70
      display: inline-block;
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    71
      float: left;
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    72
      margin: 1px 4px;
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    73
    }
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    74
    .clearfix {
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    75
      clear: both;
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
    76
    }
31
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
    77
    #test {
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
    78
      display: none;
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
    79
    }
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    80
  </style>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    81
</head>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    82
<body>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    83
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    84
  <h1>2048</h1>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    85
33
f1bbe12e2c3d Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 32
diff changeset
    86
  <div id="score-area" class="area">
f1bbe12e2c3d Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 32
diff changeset
    87
    <div class="score-conrol">
f1bbe12e2c3d Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 32
diff changeset
    88
      Score: <span id="score">0</span>, Max: <span id="max">0</span>, Turn: <span id="turn">0</span>, Speed: <span id="speed">0</span> t/s
f1bbe12e2c3d Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 32
diff changeset
    89
    </div>
f1bbe12e2c3d Highlight score area.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 32
diff changeset
    90
  </div>
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    91
4
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
    92
  <div id="message-area" class="area"></div>
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    93
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    94
  <table id="board">
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    95
    <tr>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    96
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    97
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    98
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    99
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   100
    </tr>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   101
    <tr>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   102
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   103
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   104
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   105
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   106
    </tr>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   107
    <tr>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   108
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   109
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   110
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   111
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   112
    </tr>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   113
    <tr>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   114
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   115
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   116
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   117
      <td></td>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   118
    </tr>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   119
  </table>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   120
4
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   121
  <div id="control-area" class="area">
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   122
    <div>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   123
      <button id="start">Start</button>
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   124
    </div>
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   125
    <div class="ai-control">
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   126
      <button id="suggest">Suggest</button>
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   127
      <button id="step">Step</button>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   128
      <button id="finish">Finish</button>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   129
    </div>
31
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   130
    <div class="clearfix"></div>
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   131
    <div class="move-control">
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   132
      <table>
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   133
        <tr>
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   134
          <td></td><td><button id="up">up</button></td><td></td>
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   135
        </tr>
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   136
        <tr>
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   137
          <td><button id="left">left</button></td><td><button id="down">down</button></td><td><button id="right">right</button></td>
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   138
        </tr>
9de51a02b039 Visualise buttons.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 30
diff changeset
   139
      </table>
12
a9a44cfc3e08 Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 11
diff changeset
   140
      <button id="test">test</button>
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   141
    </div>
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   142
    <h1>AIs</h1>
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   143
    <div>
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   144
      <div class="ai" id="ai-random">
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   145
        <button class="ai">enable</button>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   146
        <h5>bling random</h5>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   147
      </div>
27
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   148
      <div class="ai" id="ai-blind-cycle">
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   149
        <button class="ai">enable</button>
27
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   150
        <h5>blind cycle</h5>
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   151
        <div class="option">
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   152
          <input type="checkbox" name="clockwise"/> clockwise
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   153
        </div>
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   154
        <div class="option">
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   155
          <input type="checkbox" name="whilePossible"/> max move in one direction
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   156
        </div>
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   157
        <div class="clearfix"></div>
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   158
      </div>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   159
      <div class="ai" id="ai-next-max-value">
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   160
        <button class="ai">enable</button>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   161
        <h5>next merge makes max value</h5>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   162
      </div>
26
fba85224a8f0 Remove debug code.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 25
diff changeset
   163
      <div class="ai" id="ai-deep-max-score">
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   164
        <button class="ai">enable</button>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   165
        <h5>deep merges without simulation make max score</h5>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   166
      </div>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   167
      <div class="ai" id="ai-deep-max-score-corner">
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   168
        <button class="ai">enable</button>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   169
        <h5>deep merges without simulation make max score + bonus if max value at corner/edge</h5>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   170
      </div>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   171
      <div class="ai" id="ai-expectimax">
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   172
        <button class="ai">enable</button>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   173
        <h5>expectimax</h5>
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   174
      </div>
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   175
    </div>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   176
  </div>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   177
4
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   178
  <div id="report-area" class="area">
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   179
    <h1>Reports</h1>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   180
    <div class="report" class="area">
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   181
      <div class="name">next max score</div>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   182
      <table>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   183
        <tr>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   184
          <th>Max</th>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   185
          <th>Count</th>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   186
          <th>%</th>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   187
        </tr>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   188
        <tr>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   189
          <td>128</td><td>8</td><td><div style="background: red; width: 100px">x</div></td>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   190
        </tr>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   191
        <tr>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   192
          <td>256</td><td>4</td><td><div style="background: red; width: 50px">x</div></td>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   193
        </tr>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   194
        <tr>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   195
          <td>512</td><td>12</td><td><div style="background: red; width: 150px">x</div></td>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   196
        </tr>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   197
      </table>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   198
    </div>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   199
  </div>
732aef931a9e Report mockup.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 3
diff changeset
   200
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   201
  <script>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   202
    "use strict";
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   203
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   204
    var boardDom = document.getElementById("board");
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   205
    var ui = {};
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   206
    ui.board = {};
15
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   207
    /* 'val' typesafe.  */
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   208
    ui.board.set = function(i, j, val) {
16
ab283d2534db Fix typo.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 15
diff changeset
   209
      if (typeof val !== 'number')
15
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   210
        val = 0;
13
b3bfa9d1b537 Add color to board depending on values..
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 12
diff changeset
   211
      var dom = boardDom.querySelectorAll("tr")[i].querySelectorAll("td")[j];
15
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   212
      if (0 < val && val < 15) {
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   213
        dom.innerHTML = val;
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   214
        var rgb = 'rgb(255,'+ (255-5*val-2*(val%2)) +','+ (255-10*val-5*((val-1)%2)) +')';
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   215
      } else {
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   216
        dom.innerHTML = '';
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   217
        var rgb = 'white';
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   218
      }
13
b3bfa9d1b537 Add color to board depending on values..
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 12
diff changeset
   219
      dom.style.backgroundColor = rgb;
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   220
    }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   221
    ui.board.update = function(brd) {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   222
      for (var i = 0; i < 4; i++) {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   223
        for (var j = 0; j < 4; j++) {
15
0fa97e430a9e ui.board.set care about 'val' argument.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 14
diff changeset
   224
          ui.board.set(i, j, brd[i][j]);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   225
        }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   226
      }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   227
    }
17
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   228
    ui.board.handleEdit = function(tdDom, i, j) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   229
      if (!tdDom.firstChild || tdDom.firstChild.nodeType === Node.TEXT_NODE) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   230
        if (tdDom.firstChild)
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   231
          tdDom.removeChild(tdDom.firstChild);
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   232
        var inputDom = document.createElement('input');
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   233
        inputDom.value = board.current[i][j];
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   234
        inputDom.style.width = '1em';
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   235
        tdDom.appendChild(inputDom);
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   236
        inputDom.focus();
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   237
        inputDom.select();
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   238
        inputDom.addEventListener("blur", function(tdDom, i, j) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   239
          return function(event) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   240
            ui.board.handleEdit(tdDom, i, j);
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   241
            return false;
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   242
          }
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   243
        }(tdDom, i, j));
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   244
      } else {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   245
        var inputDom = tdDom.firstChild;
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   246
        var val = parseInt(inputDom.value);
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   247
        if (0 <= val && val < 15) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   248
          board.current[i][j] = val;
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   249
          ui.board.set(i, j, val);
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   250
        } else {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   251
          ui.board.set(i, j, board.current[i][j]);
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   252
        }
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   253
      }
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   254
    }
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   255
    ui.board.enableEdit = function() {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   256
      var trDoms = boardDom.querySelectorAll("tr");
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   257
      for (var i = 0; i < 4; i++) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   258
        var tdDoms = trDoms[i].querySelectorAll("td");
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   259
        for (var j = 0; j < 4; j++) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   260
          var tdDom = tdDoms[j];
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   261
          tdDom.addEventListener("click", function(tdDom, i, j) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   262
            return function(event) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   263
              ui.board.handleEdit(tdDom, i, j);
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   264
              return false;
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   265
            }
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   266
          }(tdDom, i, j));
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   267
          tdDom.addEventListener("keyup", function(tdDom, i, j) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   268
            return function(event) {
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   269
              if (event.keyCode === 13)
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   270
                ui.board.handleEdit(tdDom, i, j);
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   271
            }
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   272
          }(tdDom, i, j));
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   273
        }
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   274
      }
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   275
    }
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   276
    ui.board.enableEdit();
06ad7999b9f6 Add board editor.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
   277
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   278
    ui.score = {};
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   279
    var scoreDom = document.getElementById("score");
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   280
    var maxDom = document.getElementById("max");
1
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   281
    var speedDom = document.getElementById("speed");
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   282
    var turnDom = document.getElementById("turn");
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   283
    ui.score.clear = function(brd) {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   284
      scoreDom.innerHTML = '0';
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   285
      maxDom.innerHTML = '0';
1
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   286
      speedDom.innerHTML = '0';
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   287
      turnDom.innerHTML = '0';
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   288
    }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   289
    ui.score.update = function(brd) {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   290
      var score = board.score(brd);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   291
      scoreDom.innerHTML = '' + score.score;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   292
      maxDom.innerHTML = '' + score.max;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   293
    }
1
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   294
    ui.score.speed = function(speed, turn) {
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   295
      speedDom.innerHTML = '' + speed;
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   296
      turnDom.innerHTML = '' + turn;
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   297
    }
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   298
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   299
    ui.action = {};
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   300
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   301
    ui.action.start = function() {
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   302
      ui.score.clear();
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   303
      ui.message.clear();
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   304
      board.current = board.create();
7
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
   305
      board.putRandom(board.current);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   306
      ui.board.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   307
    }
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   308
    document.getElementById("start").addEventListener("click", ui.action.start);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   309
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   310
    ui.action.up = function() {
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   311
      var updated = board.move.up(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   312
      if (updated) {
7
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
   313
        board.putRandom(board.current);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   314
        ui.board.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   315
        ui.score.update(board.current);
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   316
        ui.ai.current && ui.ai.current.cleanup();
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   317
      }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   318
    }
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   319
    document.getElementById("up").addEventListener("click", ui.action.up);
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   320
    ui.action.down = function() {
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   321
      var updated = board.move.down(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   322
      if (updated) {
7
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
   323
        board.putRandom(board.current);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   324
        ui.board.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   325
        ui.score.update(board.current);
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   326
        ui.ai.current && ui.ai.current.cleanup();
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   327
      }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   328
    }
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   329
    document.getElementById("down").addEventListener("click", ui.action.down);
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   330
    ui.action.left = function() {
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   331
      var updated = board.move.left(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   332
      if (updated) {
7
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
   333
        board.putRandom(board.current);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   334
        ui.board.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   335
        ui.score.update(board.current);
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   336
        ui.ai.current && ui.ai.current.cleanup();
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   337
      }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   338
    }
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   339
    document.getElementById("left").addEventListener("click", ui.action.left);
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   340
    ui.action.right = function() {
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   341
      var updated = board.move.right(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   342
      if (updated) {
7
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
   343
        board.putRandom(board.current);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   344
        ui.board.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   345
        ui.score.update(board.current);
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   346
        ui.ai.current && ui.ai.current.cleanup();
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   347
      }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   348
    }
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   349
    document.getElementById("right").addEventListener("click", ui.action.right);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   350
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   351
    document.body.addEventListener("keydown", function(event) {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   352
      var key = event.keyCode || event.which;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   353
      switch (key) {
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   354
          case 38: ui.action.up(); break;
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   355
          case 40: ui.action.down(); break;
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   356
          case 37: ui.action.left(); break;
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   357
          case 39: ui.action.right(); break;
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   358
      }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   359
      return false;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   360
    });
12
a9a44cfc3e08 Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 11
diff changeset
   361
a9a44cfc3e08 Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 11
diff changeset
   362
    document.getElementById("test").addEventListener("click", function() {
a9a44cfc3e08 Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 11
diff changeset
   363
      board.move.replaceByBoardJS(ui.brdEngine);
a9a44cfc3e08 Moves for 2d array board + test toolkit.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 11
diff changeset
   364
    });
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   365
    
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   366
    ui.message = {};
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   367
    var messageDom = document.getElementById("message-area");
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   368
    ui.message.clear = function() {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   369
      messageDom.innerHTML = "";
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   370
    }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   371
    ui.message.set = function(msg) {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   372
      messageDom.innerHTML = msg;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   373
    }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   374
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   375
    function step() {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   376
      ui.message.clear();
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   377
      if (board.gameOver(board.current)) {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   378
        ui.message.set("Game over!");
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   379
        return;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   380
      }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   381
      var tmpBrd = board.create();
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   382
      board.copy(board.current, tmpBrd);
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   383
      var move = ui.ai.current.analyse(tmpBrd);
10
70ece7f758a0 Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 7
diff changeset
   384
      if (typeof move === 'undefined') {
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   385
        ui.message.set("I don't know how to move!");
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   386
        return;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   387
      }
10
70ece7f758a0 Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 7
diff changeset
   388
      var updated = board.move[move].call(null, board.current);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   389
      if (updated) {
7
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
   390
        board.putRandom(board.current);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   391
        ui.board.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   392
        ui.score.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   393
      } else {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   394
        ui.message.set("Wrong move!");
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   395
      }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   396
    }
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   397
    document.getElementById("step").addEventListener("click", step);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   398
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   399
    ui.action.finish = function() {
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   400
      ui.message.clear();
1
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   401
      var step = 0;
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   402
      var tsFrom = new Date().getTime();
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   403
      while (!board.gameOver(board.current)) {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   404
        var tmpBrd = board.create();
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   405
        board.copy(board.current, tmpBrd);
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   406
        var move = ui.ai.current.analyse(tmpBrd);
10
70ece7f758a0 Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 7
diff changeset
   407
        if (typeof move === 'undefined') {
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   408
          ui.message.set("I don't know how to move!");
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   409
          return;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   410
        }
10
70ece7f758a0 Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 7
diff changeset
   411
        var updated = board.move[move].call(null, board.current);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   412
        if (updated) {
7
d8106c8c0481 Rename methods and use sequential numbers instead of power of 2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 4
diff changeset
   413
          board.putRandom(board.current);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   414
        } else {
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   415
          ui.board.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   416
          ui.score.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   417
          ui.message.set("Wrong move!");
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   418
          return;
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   419
        }
1
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   420
        step++; 
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   421
      }
1
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   422
      var tsTo = new Date().getTime();
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   423
      ui.board.update(board.current);
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   424
      ui.score.update(board.current);
1
8fb744f2df13 Speed measure.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
   425
      ui.score.speed(step*1000.0/(tsTo-tsFrom), step);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   426
      ui.message.set("Game over!");
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   427
      ui.ai.current && ui.ai.current.cleanup();
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   428
    }
30
1d19768ca71d Highlight AI controls.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
   429
    document.getElementById("finish").addEventListener("click", ui.action.finish);
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   430
10
70ece7f758a0 Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 7
diff changeset
   431
    ////////////////////////////////////////////////////////////////
70ece7f758a0 Move rule and AI engine to separate files.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 7
diff changeset
   432
    // Register AIs.
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   433
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   434
    ui.ai = {};
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   435
    ui.ai.current = null;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   436
    ui.ai.algList = {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   437
      "ai-random": function() {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   438
        return new ai.random(ui.brdEngine);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   439
      },
27
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   440
      "ai-blind-cycle": function(aiDom) {
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   441
        var cfg = {};
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   442
        cfg.clockwise = aiDom.querySelectorAll("input[name='clockwise']")[0].checked;
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   443
        cfg.whilePossible = aiDom.querySelectorAll("input[name='whilePossible']")[0].checked;
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   444
        return new ai.blindCycle(ui.brdEngine, cfg);
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   445
      },
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   446
      "ai-next-max-score": function() {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   447
        return new ai.nextMaxScore(ui.brdEngine);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   448
      },
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   449
      "ai-next-max-value": function() {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   450
        return new ai.nextMaxValue(ui.brdEngine);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   451
      },
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   452
      "ai-deep-max-score": function() {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   453
        return new ai.deepMaxScore(ui.brdEngine);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   454
      },
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   455
      "ai-deep-max-score-corner": function() {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   456
        return new ai.deepMaxScoreCorner(ui.brdEngine);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   457
      },
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   458
      "ai-expectimax": function() {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   459
        return new ai.expectimax(ui.brdEngine);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   460
      },
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   461
      // "": function() {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   462
      //   return new ai.(ui.brdEngine);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   463
      // },
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   464
    };
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   465
    ui.ai.domList = document.querySelectorAll('div.ai');
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   466
    for (var i = 0; i < ui.ai.domList.length; i++) {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   467
      ui.ai.domList[i].querySelectorAll('button.ai')[0].addEventListener("click", function (event) {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   468
        ui.ai.enable(event.target.parentNode);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   469
      });
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   470
    }
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   471
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   472
    ui.ai.moveToTop = function(aiDom) {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   473
      for (var i = 0; i < ui.ai.domList.length; i++) {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   474
        ui.ai.domList[i].classList.remove('enabled');
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   475
      }
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   476
      var rootDom = aiDom.parentNode;
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   477
      rootDom.removeChild(aiDom);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   478
      rootDom.insertBefore(aiDom, rootDom.firstChild);
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   479
      aiDom.classList.add('enabled');
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   480
    }
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   481
    ui.ai.enable = function(aiDom) {
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   482
      if (ui.ai.current)
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   483
        ui.ai.current.cleanup();
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   484
      ui.ai.moveToTop(aiDom);
27
8f96d09a4d94 Add Blind cycle AI. Add example of setting passing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 26
diff changeset
   485
      ui.ai.current = ui.ai.algList[aiDom.id](aiDom);
25
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   486
    }
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   487
2ef10a49a28f Prepare UI for AI configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
   488
    ui.brdEngine = BoardArr2d; // TODO make user selectable
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   489
32
f48151863cdf Start game after page load.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
   490
    ui.action.start();
f48151863cdf Start game after page load.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
   491
0
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   492
  </script>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   493
  
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   494
</body>
2821cc5e0189 basic implementation
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   495
</html>