function KI()
{
  var i, j, k, l;
  var blah, blah2, nimm;

  var temp  = new Array();
  var temp2 = new Array();
  var temp3 = new Array();

  // Züge prüfen, bei denen der Spieler
  // im nächsten Zug aussetzen muss
  for (i = 0; i < 64; i++)
  {
    tempPossibilities[i]['anzahl'] = possibilities[i]['anzahl'];
    tempPossibilities[i]['flips']  = possibilities[i]['flips'];
    tempSpielfeld[i]               = Spielfeld[i];
  }    
  for (i = 0; i < 64; i++)
  {
    if (tempPossibilities[i]['anzahl'] > 0)
    {
      Spielfeld[i] = computer;
      fakeFlip(computer, i);
    }
    else continue;

    checkPossibilities(player);
    if (checkMove() == 0) temp2.push(i);

    // Spielfeld wiederherstellen
    for (j = 0; j < 64; j++) Spielfeld[j] = tempSpielfeld[j];
  }
  for (i = 0; i < 64; i++)
  {
    possibilities[i]['anzahl'] = tempPossibilities[i]['anzahl'];
    possibilities[i]['flips']  = tempPossibilities[i]['flips'];
    Spielfeld[i]               = tempSpielfeld[i];
  }

  if (typeof(temp2[0]) == 'undefined')
  {
    // Ecken prüfen
    if (possibilities[0]['anzahl'] > 0) temp2.push(0);
    if (possibilities[7]['anzahl'] > 0) temp2.push(7);
    if (possibilities[56]['anzahl'] > 0) temp2.push(56);
    if (possibilities[63]['anzahl'] > 0) temp2.push(63);

    if (typeof(temp2[0]) == 'undefined')
    {
      // Felder am Rand testen, außer denen, die an die Ecken grenzen
      for (i = 2; i < 6; i++)
      {
        if (possibilities[i]['anzahl'] > 0) temp2.push(i);
        if (possibilities[(i*8)]['anzahl'] > 0) temp2.push(i*8);
        if (possibilities[(i*8+7)]['anzahl'] > 0) temp2.push(i*8+7);
        if (possibilities[(56+i)]['anzahl'] > 0) temp2.push(56+i);
      }

      // Felder horizontal und vertikal an den Ecken prüfen,
      // falls die Ecken schon okkupiert sind
      if (Spielfeld[0] == computer && possibilities[1]['anzahl'] > 0) temp2.push(1);
      if (Spielfeld[0] == computer && possibilities[8]['anzahl'] > 0) temp2.push(8);
      if (Spielfeld[7] == computer && possibilities[6]['anzahl'] > 0) temp2.push(6);
      if (Spielfeld[7] == computer && possibilities[15]['anzahl'] > 0) temp2.push(15);
      if (Spielfeld[56] == computer && possibilities[48]['anzahl'] > 0) temp2.push(48);
      if (Spielfeld[56] == computer && possibilities[57]['anzahl'] > 0) temp2.push(57);
      if (Spielfeld[63] == computer && possibilities[55]['anzahl'] > 0) temp2.push(55);
      if (Spielfeld[63] == computer && possibilities[62]['anzahl'] > 0) temp2.push(62);

      if (typeof(temp2[0]) == 'undefined')
      {
        // dritte Reihe von außen testen
        for (i = 2; i < 6; i++)
        {
          if (possibilities[(16+i)]['anzahl'] > 0) temp2.push(16+i);
          if (possibilities[(i*8+2)]['anzahl'] > 0) temp2.push(i*8+2);
          if (possibilities[(i*8+5)]['anzahl'] > 0) temp2.push(i*8+5);
          if (possibilities[(40+i)]['anzahl'] > 0) temp2.push(40+i);
        }

        // Felder diagonal an den Ecken prüfen, falls die Ecken schon okkupiert sind
        if (Spielfeld[0] == computer && possibilities[9]['anzahl'] > 0) temp2.push(9);
        if (Spielfeld[7] == computer && possibilities[14]['anzahl'] > 0) temp2.push(14);
        if (Spielfeld[56] == computer && possibilities[49]['anzahl'] > 0) temp2.push(49);
        if (Spielfeld[63] == computer && possibilities[54]['anzahl'] > 0) temp2.push(54);

        if (typeof(temp2[0]) == 'undefined')
        {
          // zweite Reihe von außen testen
          for (i = 2; i < 6; i++)
          {
            if (possibilities[(8+i)]['anzahl'] > 0) temp2.push(8+i);
            if (possibilities[(i*8+1)]['anzahl'] > 0) temp2.push(i*8+1);
            if (possibilities[(i*8+6)]['anzahl'] > 0) temp2.push(i*8+6);
            if (possibilities[(48+i)]['anzahl'] > 0) temp2.push(48+i);
          }

          if (typeof(temp2[0]) == 'undefined')
          {
            // horizontal und vertikal an Eckfelder angrenzende testen
            if (possibilities[1]['anzahl'] > 0) temp2.push(1);
            if (possibilities[6]['anzahl'] > 0) temp2.push(6);
            if (possibilities[8]['anzahl'] > 0) temp2.push(8);
            if (possibilities[15]['anzahl'] > 0) temp2.push(15);
            if (possibilities[48]['anzahl'] > 0) temp2.push(48);
            if (possibilities[55]['anzahl'] > 0) temp2.push(55);
            if (possibilities[57]['anzahl'] > 0) temp2.push(57);
            if (possibilities[62]['anzahl'] > 0) temp2.push(62);

            if (typeof(temp2[0]) == 'undefined')
            {
              // diagonal an Eckfelder grenzende
              if (possibilities[9]['anzahl'] > 0) temp2.push(9);
              if (possibilities[14]['anzahl'] > 0) temp2.push(14);
              if (possibilities[49]['anzahl'] > 0) temp2.push(49);
              if (possibilities[54]['anzahl'] > 0) temp2.push(54);
            }
          }
        }
      }
    }
  }

  // aus bis jetzt herausgefundenen Zügen den besten wählen
  // während des Spielanfangs wird zufällig gewählt, da auch
  // Situationen von Vorteil sein können, bei denen der Spieler
  // weniger Chips als der Gegner auf dem Brett hat,
  // später dann der Zug, bei dem die Differenz zwischen den jetzt
  // gewonnenen Werten und den Werten des bestmöglichen
  // Konterzuges am positivsten für die KI ausfällt

  if (white + black < 25)
  {
    for (i = 0; i < temp2.length; i++)
      temp3[i] = temp2[i];
  }
  else
  {
    var Differenz = -1000;
    if (temp2.length > 1)
    {
      // Backup anlegen
      for (i = 0; i < 64; i++)
      {
        tempPossibilities[i]['anzahl'] = possibilities[i]['anzahl'];
        tempPossibilities[i]['flips']  = possibilities[i]['flips'];
        tempSpielfeld[i]               = Spielfeld[i];
      }

      // Werte des eigenen Zuges ermitteln
      for (i = 0; i < temp2.length; i++)
      {
        temp = possibilities[(temp2[i])]['flips'].split('|');

        blah = 0;
        for (j = 0; j < temp.length-1; j++) blah += wert[(temp[j])];

        Spielfeld[(temp2[i])] = computer;
        fakeFlip(computer, (temp2[i]));

        checkPossibilities(player);

        for (j = 0; j < 64; j++)
        {
          temp = possibilities[j]['flips'].split('|');

          blah2 = 0;
          for (k = 0; k < temp.length-1; k++) blah2 += wert[(temp[k])];
        }

        for (j = 0; j < 64; j++)
        {
          possibilities[j]['anzahl'] = tempPossibilities[j]['anzahl'];
          possibilities[j]['flips']  = tempPossibilities[j]['flips'];
          Spielfeld[j]               = tempSpielfeld[j];
        }

        if (blah - blah2 > Differenz)
        {
          while (typeof(temp3[0]) != 'undefined') { temp3.pop() }
          temp3.push(temp2[i]);
          Differenz = blah - blah2;
        }
        else if (Differenz == blah - blah2)
        {
          temp3.push(temp2[i]);
        }
      }
    }
    else temp3[0] = temp2[0];
  }


  blah = Math.floor((Math.random() * 1000) % temp3.length);
  nimm = temp3[blah];

  putPiece(computer, nimm);
  flip(computer, nimm);
  progress = 0;

  // lässt Möglichkeiten für den Spieler bestimmen
  checkPossibilities(player);

  if (checkMove() == 0)
  {
    checkPossibilities(computer);
    if (checkMove() == 0) gameOver();
    else setTimeout("KI()", 2000);
  }
  else for (i = 0; i < 64; i++)
  {
    if (possibilities[i]['anzahl'] > 0) putPiece (5,i);
    else if (Spielfeld[i] == 0) putPiece(0,i);
  }
}
