Skip to content

Method: Minimax()

1: package de.fhdw.gaming.ipspiel24.minimax.core.moves.impl;
2:
3: /**
4: * has function getBestMove().
5: */
6: public class Minimax {
7: /*
8:
9: public int[] getBestMove(final List<List<?>> board, boolean player){
10: List<List<?>> newBoard = board;
11:
12: int bestValue = Integer.MIN_VALUE;
13: Move bestMove;
14: for(List<?> x: newBoard) {
15: for()
16: int value = minimax(move, 9, Integer.MIN_VALUE, Integer.MAX_VALUE, player);
17: if (value > bestValue) {
18: bestValue = value;
19: bestMove = move;
20: }
21: }
22: return new int[] {1,2};
23: }
24:
25:
26:
27: /** minimax function.
28: * @param node is the gametree.
29: * @param depth is the depth of the node.
30: * @param alpha is used to find nodes for pruning.
31: * @param beta is used to find nodes for pruning.
32: * @param player is the player.
33: * @return value of node.
34: *//*
35: public static int minimax(List node, int depth, int alpha, int beta, boolean player) {
36: int newAlpha = alpha;
37: int newBeta = beta;
38:
39: /*if (depth == 0 || node.isTerminal()) {
40: return node.getValue();
41: }
42:
43: if (player) {
44: int bestValue = Integer.MIN_VALUE;
45: for (Node child: node.getChildren()) {
46: //place mark
47: final int value = minimax(child, depth - 1, newAlpha, newBeta, false);
48: //remove mark
49: bestValue = Math.max(bestValue, value);
50: newAlpha = Math.max(newAlpha, value);
51: if (newBeta <= newAlpha) {
52: break;
53: }
54: }
55: return bestValue;
56: } else {
57: int minValue = Integer.MAX_VALUE;
58: for (Node child : node.getChildren()) {
59: //place mark
60: final int value = minimax(child, depth - 1, newAlpha, newBeta, true);
61: //remove mark
62: minValue = Math.min(minValue, value);
63: newBeta = Math.min(newBeta, value);
64: if (newBeta <= newAlpha) {
65: break;
66: }
67: }
68: return minValue;
69: }
70: }
71: */
72:
73: }
74:
75:
76:
77: