function init() {
  fixLinks();

  var m = document.cookie.match(/difficulty=([01])/);
  var difficultyIndex = m ? m[1] : 0;
  SPEED = [750, 500][difficultyIndex];
  document.getElementById('difficulty').selectedIndex = difficultyIndex;
  var playerCount = 1;
  m = document.cookie.match(/players=([12])/);
  if (m && m[1] === '2') {
    playerCount = 2;
  }
  document.getElementById('players').selectedIndex = playerCount - 1;
  registerOptions('players', 'difficulty');

  document.addEventListener('keydown', keyDown);
  document.addEventListener('keyup', keyUp);

  initGrid();

  player1 = new Tank(1);
  tanks.push(player1);
  if (playerCount > 1) {
    player2 = new Tank(2);
    tanks.push(player2);
  } else {
    document.getElementById('player2scores').style.display = 'none';
    document.getElementById('player2keys').style.display = 'none';
  }
  playerComputer = new Tank(3);
  tanks.push(playerComputer);
  // If there are an even number of tanks:
  // 2:  S2,S1,T1 - S1,S2,T2 - Repeat...
  // 4:  S3,S1,T1 - S4,S2,T2 - S1,S3,T3 - S2,S4,T4 - Repeat...
  // If there are an odd number of tanks:
  // 1:  S1,T1 - S1 - Repeat...
  // 3:  S1,T1 - S3 - S2,T2 - S1 - S3,T3 - S2 - Repeat...
  var interval = SPEED / (tanks.length * ((tanks.length % 2) ?  2 : 1));
  setInterval(clock, interval);
}
// On page load, initialize the event handlers and draw the grid.
On page load, initialize the event handlers and draw the grid.
On page load initialize the event handlers and draw the grid .
function init() {
  fixLinks();
  var m = document.cookie.match(/difficulty=([01])/);
  var difficultyIndex = m ? m[1] : 0;
  SPEED = [750, 500][difficultyIndex];
  document.getElementById('difficulty').selectedIndex = difficultyIndex;
  var playerCount = 1;
  m = document.cookie.match(/players=([12])/);
  if (m && m[1] === '2') {
    playerCount = 2;
  }
  document.getElementById('players').selectedIndex = playerCount - 1;
  registerOptions('players', 'difficulty');
  document.addEventListener('keydown', keyDown);
  document.addEventListener('keyup', keyUp);
  initGrid();
  player1 = new Tank(1);
  tanks.push(player1);
  if (playerCount > 1) {
    player2 = new Tank(2);
    tanks.push(player2);
  } else {
    document.getElementById('player2scores').style.display = 'none';
    document.getElementById('player2keys').style.display = 'none';
  }
  playerComputer = new Tank(3);
  tanks.push(playerComputer);
  var interval = SPEED / (tanks.length * ((tanks.length % 2) ?  2 : 1));
  setInterval(clock, interval);
}
function init ( ) { fixLinks ( ) ; var m = document . cookie . match ( / difficulty=([01]) / ) ; var difficultyIndex = m ? m [ 1 ] : 0 ; SPEED = [ 750 , 500 ] [ difficultyIndex ] ; document . getElementById ( 'difficulty' ) . selectedIndex = difficultyIndex ; var playerCount = 1 ; m = document . cookie . match ( / players=([12]) / ) ; if ( m && m [ 1 ] === '2' ) { playerCount = 2 ; } document . getElementById ( 'players' ) . selectedIndex = playerCount - 1 ; registerOptions ( 'players' , 'difficulty' ) ; document . addEventListener ( 'keydown' , keyDown ) ; document . addEventListener ( 'keyup' , keyUp ) ; initGrid ( ) ; player1 = new Tank ( 1 ) ; tanks . push ( player1 ) ; if ( playerCount > 1 ) { player2 = new Tank ( 2 ) ; tanks . push ( player2 ) ; } else { document . getElementById ( 'player2scores' ) . style . display = 'none' ; document . getElementById ( 'player2keys' ) . style . display = 'none' ; } playerComputer = new Tank ( 3 ) ; tanks . push ( playerComputer ) ; var interval = SPEED / ( tanks . length * ( ( tanks . length % 2 ) ? 2 : 1 ) ) ; setInterval ( clock , interval ) ; }
On page load, initialize the event handlers and draw the grid.
On page load initialize the event handlers and draw the grid .
// If there are an even number of tanks: // 2:  S2,S1,T1 - S1,S2,T2 - Repeat... // 4:  S3,S1,T1 - S4,S2,T2 - S1,S3,T3 - S2,S4,T4 - Repeat... // If there are an odd number of tanks: // 1:  S1,T1 - S1 - Repeat... // 3:  S1,T1 - S3 - S2,T2 - S1 - S3,T3 - S2 - Repeat...