function drawScore() {
  // Print text message.
  var state = boardState(board);
  var text = '';
  if (state === (cpuFirst ? X_VALUE : O_VALUE)) {
    text = 'Computer wins.';
    document.getElementById('fail').play();
  } else if (state === (cpuFirst ? O_VALUE : X_VALUE)) {
    text = 'You win!';
    document.getElementById('ding').play();
  } else if (state === TIE) {
    text = 'It is a tie.';
  }
  if (text) {
    document.getElementById('status').textContent = text;
    document.getElementById('shield').style.display = 'block';
  }

  // Draw a winning stroke.
  // <line x1="5%" y1="5%" x2="95%" y2="95%" id="win" />
  if (state === X_VALUE || state === O_VALUE) {
    var x1, y1, x2, y2;
    // Vertical.
    for (var i = 0; i < 3; i++) {
      if (board[i] !== EMPTY &&
          board[i] === board[i + 3] && board[i] === board[i + 6]) {
        x1 = ['16.7%', '50%', '83.3%'][i];
        y1 = '5%';
        x2 = x1;
        y2 = '95%';
      }
    }
    // Horizontal.
    for (var i = 0; i < 9; i += 3) {
      if (board[i] !== EMPTY &&
          board[i] === board[i + 1] && board[i] === board[i + 2]) {
        x1 = '5%';
        y1 = ['16.7%', '50%', '83.3%'][Math.floor(i / 3)];
        x2 = '95%';
        y2 = y1;
      }
    }
    if (board[0] === board[4] && board[4] === board[8]) {
      // \.
      x1 = '5%';
      y1 = '5%';
      x2 = '95%';
      y2 = '95%';
    } else if (board[2] === board[4] && board[4] === board[6]) {
      // /.
      x1 = '5%';
      y1 = '95%';
      x2 = '95%';
      y2 = '5%';
    }
    var line = document.getElementById('win');
    line.setAttribute('x1', x1);
    line.setAttribute('y1', y1);
    line.setAttribute('x2', x2);
    line.setAttribute('y2', y2);
    line.style.display = 'block';
  }

  // Lock up the human if there is nowhere to play.
  if (state != EMPTY) {
    enabled = false;
  }
}
// Add UI elements to end the game.
Add UI elements to end the game.
Add UI elements to end the game .
function drawScore() {
  var state = boardState(board);
  var text = '';
  if (state === (cpuFirst ? X_VALUE : O_VALUE)) {
    text = 'Computer wins.';
    document.getElementById('fail').play();
  } else if (state === (cpuFirst ? O_VALUE : X_VALUE)) {
    text = 'You win!';
    document.getElementById('ding').play();
  } else if (state === TIE) {
    text = 'It is a tie.';
  }
  if (text) {
    document.getElementById('status').textContent = text;
    document.getElementById('shield').style.display = 'block';
  }
  if (state === X_VALUE || state === O_VALUE) {
    var x1, y1, x2, y2;
    for (var i = 0; i < 3; i++) {
      if (board[i] !== EMPTY &&
          board[i] === board[i + 3] && board[i] === board[i + 6]) {
        x1 = ['16.7%', '50%', '83.3%'][i];
        y1 = '5%';
        x2 = x1;
        y2 = '95%';
      }
    }
    for (var i = 0; i < 9; i += 3) {
      if (board[i] !== EMPTY &&
          board[i] === board[i + 1] && board[i] === board[i + 2]) {
        x1 = '5%';
        y1 = ['16.7%', '50%', '83.3%'][Math.floor(i / 3)];
        x2 = '95%';
        y2 = y1;
      }
    }
    if (board[0] === board[4] && board[4] === board[8]) {
      x1 = '5%';
      y1 = '5%';
      x2 = '95%';
      y2 = '95%';
    } else if (board[2] === board[4] && board[4] === board[6]) {
      x1 = '5%';
      y1 = '95%';
      x2 = '95%';
      y2 = '5%';
    }
    var line = document.getElementById('win');
    line.setAttribute('x1', x1);
    line.setAttribute('y1', y1);
    line.setAttribute('x2', x2);
    line.setAttribute('y2', y2);
    line.style.display = 'block';
  }
  if (state != EMPTY) {
    enabled = false;
  }
}
function drawScore ( ) { var state = boardState ( board ) ; var text = '' ; if ( state === ( cpuFirst ? X_VALUE : O_VALUE ) ) { text = 'Computer wins.' ; document . getElementById ( 'fail' ) . play ( ) ; } else if ( state === ( cpuFirst ? O_VALUE : X_VALUE ) ) { text = 'You win!' ; document . getElementById ( 'ding' ) . play ( ) ; } else if ( state === TIE ) { text = 'It is a tie.' ; } if ( text ) { document . getElementById ( 'status' ) . textContent = text ; document . getElementById ( 'shield' ) . style . display = 'block' ; } if ( state === X_VALUE || state === O_VALUE ) { var x1 , y1 , x2 , y2 ; for ( var i = 0 ; i < 3 ; i ++ ) { if ( board [ i ] !== EMPTY && board [ i ] === board [ i + 3 ] && board [ i ] === board [ i + 6 ] ) { x1 = [ '16.7%' , '50%' , '83.3%' ] [ i ] ; y1 = '5%' ; x2 = x1 ; y2 = '95%' ; } } for ( var i = 0 ; i < 9 ; i += 3 ) { if ( board [ i ] !== EMPTY && board [ i ] === board [ i + 1 ] && board [ i ] === board [ i + 2 ] ) { x1 = '5%' ; y1 = [ '16.7%' , '50%' , '83.3%' ] [ Math . floor ( i / 3 ) ] ; x2 = '95%' ; y2 = y1 ; } } if ( board [ 0 ] === board [ 4 ] && board [ 4 ] === board [ 8 ] ) { x1 = '5%' ; y1 = '5%' ; x2 = '95%' ; y2 = '95%' ; } else if ( board [ 2 ] === board [ 4 ] && board [ 4 ] === board [ 6 ] ) { x1 = '5%' ; y1 = '95%' ; x2 = '95%' ; y2 = '5%' ; } var line = document . getElementById ( 'win' ) ; line . setAttribute ( 'x1' , x1 ) ; line . setAttribute ( 'y1' , y1 ) ; line . setAttribute ( 'x2' , x2 ) ; line . setAttribute ( 'y2' , y2 ) ; line . style . display = 'block' ; } if ( state != EMPTY ) { enabled = false ; } }
Add UI elements to end the game.
Add UI elements to end the game .
// Print text message. // Draw a winning stroke. // <line x1="5%" y1="5%" x2="95%" y2="95%" id="win" /> // Vertical. // Horizontal. // \. // /. // Lock up the human if there is nowhere to play.