Package minesweeper.ai.games

Examples of minesweeper.ai.games.BoardInfoHelper


 
  private Set<Position> toPick, toFlag;

  @Override
  public void solve(GameState game) {
    BoardInfoHelper helper = new BoardInfoHelper(game);
    game.pick(game.getRows()/2, game.getCols()/2);
   
    while(game.getState() == State.IN_PROGRESS) {
          if(! deduce(helper.getBoard()))
            if(! backtrackSolve(helper.getBoard()))
              if(! bruteForceSearch(helper.getBoard()))
                if(! probablisticBacktrackSolve(helper.getBoard()))
                  if(! pickRandom(helper.getBoard()))
                    break;
          pickAndFlag(game);
    }
   
    if(debug == DebugMode.ON) {
View Full Code Here


  }
 
  private int solutionsFound;
  private Map<Position,Integer> toPickMap, toFlagMap;
  private boolean backtrackSolve(MutableBoard grid) {
    BoardInfoHelper helper = new BoardInfoHelper(grid);
   
      for(List<Position> positions : helper.getClosedUnknownBorderCells()) {
        probBacktrackValid = false;
        toPickMap.clear(); toFlagMap.clear(); solutionsFound = 0;
        toPick.clear(); toPick.addAll(positions);
        toFlag.clear(); toFlag.addAll(positions);
        backtrackSolve(grid, helper, positions, new Node(null,null), new Node(null,null));
View Full Code Here

    positions.add(0,p);
    return result;
  }
 
  private boolean pickRandom(MutableBoard board) {
    BoardInfoHelper helper = new BoardInfoHelper(board);
      List<Position> unknown = helper.getUnknownBorderCells();
      toPick.clear(); toFlag.clear();
      if(unknown.size() == 0)
        unknown = helper.getCellsByValue(Cell.UNKNOWN);
      if(unknown.size() >= 1)
        toPick.add(unknown.get((int) (unknown.size() * Math.random())));
      dt = DeductionType.RANDOM;
      return toPick.size() == 1;
  }
View Full Code Here

      dt = DeductionType.RANDOM;
      return toPick.size() == 1;
  }
 
  private boolean deduce(MutableBoard board) {
    BoardInfoHelper helper = new BoardInfoHelper(board);
    toPick.clear(); toFlag.clear();
    for(Position cell : helper.getCellsWithAdjacentBombs()) {
            List<Position> unknown = helper.getAdjacentCellsByValue(cell, Cell.UNKNOWN);
            List<Position> flagged = helper.getAdjacentCellsByValue(cell, Cell.FLAG);
            if(board.getCell(cell) == unknown.size() + flagged.size())
                for(Position p : unknown)
                    toFlag.add(p);
            if(board.getCell(cell) == flagged.size())
                for(Position p : unknown)
View Full Code Here

    dt = DeductionType.NORMAL;
    return toPick.size() > 0 || toFlag.size() > 0;
  }
 
    private boolean bruteForceSearch(MutableBoard board) {
      BoardInfoHelper helper = new BoardInfoHelper(board);
        List<Position> unknown = helper.getCellsByValue(Cell.UNKNOWN);
        int bombsToPlace = board.getRemainingBombs();
        toFlag.clear(); toPick.clear();
        if(Combinations.nCr(unknown.size(), bombsToPlace) < SEARCH_SPACE_LIMIT) {
          toFlag.addAll(unknown); toPick.addAll(unknown);
          enumerateBombLocations(helper, unknown, new Node(null,null), new Node(null,null), bombsToPlace);
View Full Code Here

  private Set<Position> toPick;
  private Set<Position> toFlag;

  @Override
  public void solve(GameState game) {
    BoardInfoHelper helper = new BoardInfoHelper(game);

    game.pick(game.getRows()/2, game.getCols()/2);
    while(game.getState() == State.IN_PROGRESS) {
          if(! deduce(helper.getBoard()))
            if(! pickRandom(helper.getBoard()))
              break;
          pickAndFlag(game);
    }
    if(debug == DebugMode.ON) System.out.println(game);
  }
View Full Code Here

      for(Position p : toFlag)
        game.flag(p);
  }
 
  private boolean pickRandom(MutableBoard board) {
    BoardInfoHelper helper = new BoardInfoHelper(board);
      List<Position> unknown = helper.getUnknownBorderCells();
      toPick.clear(); toFlag.clear();
      if(unknown.size() == 0)
        unknown = helper.getCellsByValue(Cell.UNKNOWN);
      if(unknown.size() >= 1)
        toPick.add(unknown.get((int) (unknown.size() * Math.random())));
      return toPick.size() == 1;
  }
View Full Code Here

        toPick.add(unknown.get((int) (unknown.size() * Math.random())));
      return toPick.size() == 1;
  }
 
  private boolean deduce(MutableBoard board) {
    BoardInfoHelper helper = new BoardInfoHelper(board);
    toPick.clear(); toFlag.clear();
    for(Position cell : helper.getCellsWithAdjacentBombs()) {
            List<Position> unknown = helper.getAdjacentCellsByValue(cell, Cell.UNKNOWN);
            List<Position> flagged = helper.getAdjacentCellsByValue(cell, Cell.FLAG);
            if(board.getCell(cell) == unknown.size() + flagged.size())
                for(Position p : unknown)
                    toFlag.add(p);
            if(board.getCell(cell) == flagged.size())
                for(Position p : unknown)
View Full Code Here

 
    private Set<Position> toFlag, toPick;

  @Override
  public void solve(GameState game) {
    BoardInfoHelper helper = new BoardInfoHelper(game);
    game.pick(game.getRows()/2, game.getCols()/2);
    while(game.getState() == State.IN_PROGRESS) {
          if(! deduce(helper.getBoard()))
            if(! bruteForceSearch(helper.getBoard()))
              if(! pickRandom(helper.getBoard()))
                break;
          pickAndFlag(game);
    }
    if(debug == DebugMode.ON) System.out.println(game);
  }
View Full Code Here

      for(Position p : toFlag)
        game.flag(p);
  }
 
  private boolean pickRandom(MutableBoard board) {
    BoardInfoHelper helper = new BoardInfoHelper(board);
      List<Position> unknown = helper.getUnknownBorderCells();
      toPick.clear(); toFlag.clear();
      if(unknown.size() == 0)
        unknown = helper.getCellsByValue(Cell.UNKNOWN);
      if(unknown.size() >= 1)
        toPick.add(unknown.get((int) (unknown.size() * Math.random())));
      return toPick.size() == 1;
  }
View Full Code Here

TOP

Related Classes of minesweeper.ai.games.BoardInfoHelper

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.