Package aima.core.search.adversarial

Examples of aima.core.search.adversarial.GameState


    return (TicTacToeBoard) state.get("board");
  }

  @Override
  public List<GameState> getSuccessorStates(GameState state) {
    GameState temp = presentState;
    List<GameState> retVal = new ArrayList<GameState>();
    int parentLevel = getLevel(state);
    for (int i = 0; i < getMoves(state).size(); i++) {
      XYLocation loc = (XYLocation) getMoves(state).get(i);

      GameState aState = makeMove(state, loc);
      aState.put("moveMade", loc);
      aState.put("level", new Integer(parentLevel + 1));
      retVal.add(aState);

    }
    presentState = temp;
    return retVal;
View Full Code Here


    XYLocation loc = (XYLocation) o;
    return makeMove(state, loc.getXCoOrdinate(), loc.getYCoOrdinate());
  }

  public GameState makeMove(GameState state, int x, int y) {
    GameState temp = getMove(state, x, y);
    if (temp != null) {
      presentState = temp;
    }
    return presentState;
  }
View Full Code Here

    }
    return presentState;
  }

  public GameState makeMove(int x, int y) {
    GameState state = presentState;
    GameState temp = getMove(state, x, y);
    if (temp != null) {
      presentState = temp;
    }
    return presentState;
  }
View Full Code Here

    }
    return presentState;
  }

  public GameState getMove(GameState state, int x, int y) {
    GameState retVal = null;
    XYLocation loc = new XYLocation(x, y);
    List<XYLocation> moves = getMoves(state);
    List<XYLocation> newMoves = new ArrayList<XYLocation>(moves);
    if (moves.contains(loc)) {
      int index = newMoves.indexOf(loc);
      newMoves.remove(index);

      retVal = new GameState();

      retVal.put("moves", newMoves);
      TicTacToeBoard newBoard = getBoard(state).cloneBoard();
      if (getPlayerToMove(state) == "X") {
        newBoard.markX(x, y);
        retVal.put("player", "O");

      } else {
        newBoard.markO(x, y);
        retVal.put("player", "X");

      }
      retVal.put("board", newBoard);
      retVal.put(
          "utility",
          new Integer(computeUtility(newBoard,
              getPlayerToMove(getState()))));
      retVal.put("level", new Integer(getLevel(state) + 1));
      // presentState = retVal;
    }
    return retVal;
  }
View Full Code Here

    System.out.println("Possible moves");

    List<XYLocation> moves = getMoves(presentState);
    for (int i = 0; i < moves.size(); i++) {
      XYLocation moveLoc = (XYLocation) moves.get(i);
      GameState newState = getMove(presentState,
          moveLoc.getXCoOrdinate(), moveLoc.getYCoOrdinate());
      System.out.println("utility = " + computeUtility(newState));
      System.out.println("");
    }
View Full Code Here

        String val = board.getValue(i / 3, i % 3);
        if (val == TicTacToeBoard.EMPTY)
          val = "";
        squares[i].setText(val);
      }
      GameState state = game.getState();
      if (game.getUtility(state) == 0 && game.hasEnded())
        status.setText("No winner...");
      else
        status.setText((game.hasEnded() ? "Just lost: " : "Next move: ")
          + game.getPlayerToMove(game.getState()));
View Full Code Here

    while (!(t4.hasEnded())) {
      System.out.println("\n" + t4.getPlayerToMove(t4.getState())
          + "  playing ... ");

      t4.makeAlphaBetaMove();
      GameState presentState = t4.getState();
      TicTacToeBoard board = t4.getBoard(presentState);
      board.print();
    }
    System.out.println("ALPHA BETA DEMO done");
  }
View Full Code Here

    while (!(t3.hasEnded())) {
      System.out.println("\n" + t3.getPlayerToMove(t3.getState())
          + " playing");
      System.out.println("");
      t3.makeMiniMaxMove();
      GameState presentState = t3.getState();
      TicTacToeBoard board = t3.getBoard(presentState);
      System.out.println("");
      board.print();

    }
View Full Code Here

  @Test
  public void testGameStateEquality() {
    TicTacToeBoard tb1 = new TicTacToeBoard();
    TicTacToeBoard tb2 = new TicTacToeBoard();
    GameState gs1 = new GameState();
    GameState gs2 = new GameState();
    gs1.put("board", tb1);
    gs2.put("board", tb2);
    Assert.assertEquals(gs1, gs2);
    gs1.put("minimaxValue", new Integer(3));
    Assert.assertTrue(!(gs1.equals(gs2)));
  }
View Full Code Here

  // PRIVATE METHODS
  //
  private void checkSuccessorList(List<GameState> successorList,
      String playerToMove, int sizeOfSuccessors) {
    for (int i = 0; i < successorList.size(); i++) {
      GameState h = successorList.get(i);

      List<GameState> successors2 = new TicTacToe().getSuccessorStates(h);
      Assert.assertEquals(sizeOfSuccessors, successors2.size());
      Assert.assertEquals(playerToMove,
          new TicTacToe().getPlayerToMove(h));
View Full Code Here

TOP

Related Classes of aima.core.search.adversarial.GameState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.