Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Algorithmus-Problem

Empfohlene Antworten

Hallo, ich möchte 4 Gewinnt mit einer KI programmieren und benutze dazu den Negamax-Algorithmus.

Der Algorithmus funktioniert soweit, spuckt jedoch noch keine wirklichen logischen Züge aus. 3 senkrecht stehende steine erkennt er nicht. nicht von mir und nicht von ihm...

Was ist denn falsch?

Negamax-Aufruf:

		//Negamax

		else

		{

			negamax(depth, Integer.MIN_VALUE, Integer.MAX_VALUE); //depth = 8

			return doNext;

		}
	

	/**

	 * Der beste Spielzug wird mit Hilfe des Negamax-algorithmus gesucht.

	 * Jeder Spielbaum wird bis zur Tiefe "depth" ausgewertet und dann eine Feldbewertung vorgenommen.

	 * 

	 * @param	depth	die Tiefe des Spielbaumes

	 * @return 	max     Der Wert des Zuges

	 */

	private int negamax(int depth, int alpha, int beta) 

	{

		if(depth == 0                      	 	//Abbruchbedingun der Rekursion (Tiefe erreicht, 

				|| pf.possibleMovesInt()+1 == 0) 	//aktueller spieler hat keine möglichen Züge -> Feld ist voll

		{						

			if (pf.checkfourBoolean(2))  			//Gewonnen?

		 		return 10;

			else if (pf.checkfourBoolean(1))  		//Verloren?

		  		return -10;

			else         	 						//Unentschieden 

		  		return 0;		

		}


		for(int s = 0; s < pf.getSpalten(); s++)            //for(int s = 0; s < pf.getSpalten(); s++) 				//Alle Züge durchprobieren

		{		

			if (pf.columnFree(s)) 								//Alle möglichen Züge durchprobieren

			{

				player = player == 1 ? 2 : 1;

				pf.set(s, player);       						//Zug simulieren 

				int value = -negamax(depth-1,-beta,-alpha); 	//Rekursionsaufruf 

				pf.removeHighestField(s);  						//Zug rückgängig machen


				//Betacut

				//if (value >= beta)

				//{

				//	return beta;

				//}

				//Alphacut

				if (value > alpha)

				{

					alpha = value;

					doNext = s;

				}

			}

		}

		return alpha;

	}

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.