/** Uses adversarial search for selecting the next action. */ private void proposeMove() { Integer action; int time = (timeCombo.getSelectedIndex() + 1) * 5; dasg_i_SearchAdversarial<ConnectFourState, Integer> search; switch (strategyCombo.getSelectedIndex()) { case 0: search = dasg_SearchAdversarialMinimax.createFor(game); break; case 1: search = dasg_SearchAlphaBeta.createFor(game); break; case 2: search = dasg_SearchAdversarialIterativeDeepeningAlphaBeta.createFor(game, 0.0, 1.0, time); break; case 3: search = new ConnectFourAIPlayer(game, time); break; default: search = new ConnectFourAIPlayer(game, time); ((ConnectFourAIPlayer) search).setLogEnabled(true); } action = search.makeDecision(currState); searchMetrics = search.getMetrics(); currState = game.getResult(currState, action); }
/** Handles all button events and updates the view. */ public void actionPerformed(ActionEvent e) { searchMetrics = null; if (e == null || e.getSource() == clearButton) { currState = game.getInitialState(); } else if (!game.isTerminal(currState)) { if (e.getSource() == proposeButton) { proposeMove(); } else if (e.getSource() instanceof GridElement) { GridElement el = (GridElement) e.getSource(); currState = game.getResult(currState, el.col); // take next // turn } } repaint(); // paint all disks! updateStatus(); }