@Override
 public List<DiscreteGameState> availableStates() {
   List<Position> availableMoves = board.getOpenPositions();
   List<DiscreteGameState> availableStates =
       new ArrayList<DiscreteGameState>(availableMoves.size());
   for (Position move : availableMoves) {
     TicTacToeGameState newState = new TicTacToeGameState(this);
     newState.play(move.getRow(), move.getCol());
     newState.switchPlayer();
     availableStates.add(newState);
   }
   return availableStates;
 }
Ejemplo n.º 2
0
  public boolean step(Position to) {

    if (to.isNull()) {
      return false;
    }

    int tmpRow = super.position.getRow() - to.getRow();
    int tmpColumn = super.position.getColumn() - to.getColumn();

    boolean flag = (tmpRow == 0 || tmpColumn == 0);

    if (!Board.isEmpty(to)) {
      return flag && (Board.getColour(to) != super.getColour());
    }
    return flag;
  }
Ejemplo n.º 3
0
  public int toDOT(FileWriter fr, boolean redColored, int i) throws IOException {

    String red, format, val, blue;
    int me = i, aux;
    if (redColored) {
      red = "color=red, style=filled, ";
    } else {
      red = "";
    }
    if (value == Integer.MAX_VALUE || value == Integer.MIN_VALUE) {
      val = "";
      blue = "color=blue, style=filled, ";
    } else {
      val = "" + value;
      blue = "";
    }
    format = getDOTFormat();
    fr.append(me + " [" + red + blue + format + "label=\"" + pos.toString() + " " + val + "\"];\n");
    boolean redSon, selected = true;
    for (Node son : childs) {
      if (selected && son.value == value) {
        selected = false;
        redSon = true;
      } else {
        redSon = false;
      }
      aux = i + 1;
      i = son.toDOT(fr, redSon, ++i);
      fr.append(me + " -> " + aux + ";\n");
    }
    return i;
  }