• Main Page
  • Files
  • File List

Reversi_KI.h

00001 // Reversi_KI.h
00002 //
00003 // Part of PAI
00004 //
00005 // containing function for computer move
00006 
00007 #include <iostream>
00008 //#include <windows.h> //steht unter Linux nicht zur Verfügung... Sleep klappt auch so.
00009 
00010 using namespace std;
00011 
00012 int moegliche_zuege(int spielfeld[SIZE_X][SIZE_Y], int spieler);
00013 bool zug_ausfuehren(int spielfeld[SIZE_X][SIZE_Y], int spieler, int pos_x, int pos_y);bool zug_gueltig(int spielfeld[SIZE_X][SIZE_Y], int spieler, int pos_x, int pos_y);
00014 
00015 bool computer_zug(int spielfeld[SIZE_X][SIZE_Y], int spieler)
00016 {
00017     if (moegliche_zuege(spielfeld,spieler)==0)
00018     {
00019         return false;
00020     }
00021     int look_ahead[SIZE_X][SIZE_Y];
00022     int min_x=0;
00023     int min_y=0;
00024     int min=SIZE_X * SIZE_Y;
00025     
00026     for (int i=0;i<SIZE_Y;i++)
00027     {
00028         for (int j=0;j<SIZE_Y;j++)
00029         {
00030             // reset field
00031             for (int ci=0;ci<SIZE_X;ci++)
00032             {
00033                 for (int cj=0;cj<SIZE_Y;cj++)
00034                 {
00035                     look_ahead[ci][cj]=spielfeld[ci][cj];
00036                 }
00037             }
00038             
00039             if (zug_gueltig(look_ahead, spieler,i,j))
00040             {
00041                 zug_ausfuehren(look_ahead,spieler,i,j);
00042                 if (moegliche_zuege(look_ahead,-(spieler - 2) + 1)<min)
00043                 {
00044                     min=moegliche_zuege(look_ahead,-(spieler - 2) + 1);
00045                     min_x=i;
00046                     min_y=j;
00047                 }
00048             }
00049         }
00050     }
00051     
00052     zug_ausfuehren(spielfeld,spieler,min_x,min_y);
00053     cout << endl << "Player " << spieler << " moves to " << (char) (min_x+65) << (min_y+1) << endl;
00054     sleep( 2 );// 2 seconds pause to check computers move!
00055     return true;
00056 }

Generated on Wed Apr 27 2011 15:28:42 for Reversi by  doxygen 1.7.1