public void gameEnded(Node nodeIn) { Node currentNode = nodeIn; int terminalDepth = 0; parentFound: while (true) { if (currentNode.winDepth > terminalDepth) { currentNode.winDepth = terminalDepth; terminalDepth++; if (currentNode.winDepth == 0 && agentPlayerNumber == 1 && !currentNode.hasParent()) { // piece for (Node e : pieceList) { if (e.pieceID == currentNode.pieceID) { pieceList.remove(e); break parentFound; } } } else if (currentNode.winDepth == 0 && agentPlayerNumber == 0 && !currentNode.hasParent()) { // move found = currentNode; critical = true; break; } if (!currentNode.hasParent()) break parentFound; currentNode = currentNode.parent; } else if (currentNode.winDepth <= terminalDepth) { break; } } workingBoard = new QuartoBoard(originalBoard); }
public int getMCS(QuartoBoard copyBoard) { agentPlayerNumber = 1; // availableChoices will hold all possible choices from this point on availableChoices = new ArrayList<Node>(); // Instantiate our boards originalBoard = new QuartoBoard(copyBoard); workingBoard = new QuartoBoard(originalBoard); // agentPlayerNumber ^= 1; generateMissingActions(-1); // Group pieces into a pieceList pieceList = new ArrayList<Node>(); for (int piece = 0; piece < originalBoard.getNumberOfPieces(); piece++) { if (!originalBoard.isPieceOnBoard(piece)) { int nextPiece = originalBoard.chooseNextPieceNotPlayed(piece); Node newPiece = new Node(); newPiece.pieceID = nextPiece; pieceList.add(newPiece); } } // Random randomGenerator = new Random(); // Loop through each Node in availableChoices and run a random game on it until numIterations is // hit for (int j = 1; j < 10; j++) { for (int x = 0; x < 4; x++) { for (int i = 0; i < (availableChoices.size() - 1) / j; i++) { recurThroughNextGame(availableChoices.get(i), 3); } } Collections.sort(availableChoices); } // Iterate through each Node in availableChoices. If the Node's pieceID exists in pieceList, // then apply the lowest score // of the two to pieceList's score. for (Node e : availableChoices) { for (Node f : pieceList) { if (f.pieceID == e.pieceID) { double bestPath = Math.min(e.winDepth, f.winDepth); f.winDepth = bestPath; } } } // Sort the pieceList by winDepth Collections.sort(pieceList); // Grab the worst winDepth pieceID and do many random games off of it, then keep the best score. // If the best score // is better than the second worst winDepth pieceID, replace it. Repeat. // scrubTopChoices(); if (!pieceList.isEmpty()) submittedAction.pieceID = pieceList.get(pieceList.size() - 1).pieceID; else submittedAction.pieceID = workingBoard.chooseNextPieceNotPlayed(); depthLimit += 0.4; return submittedAction.pieceID; }