示例#1
0
  public void drawScene() {
    GLDrawer.clear();
    Board currentBoard = Crissaegrim.getCurrentBoard();

    if (Crissaegrim.getCurrentBoard() != null) {
      GameInitializer.initializeNewFrameForWindow();
      ClientBoard.drawBackground(currentBoard);

      GameInitializer.initializeNewFrameForScene();
      ClientBoard.draw(currentBoard, TileLayer.BACKGROUND);
      ClientBoard.draw(currentBoard, TileLayer.MIDDLEGROUND);
      for (Doodad doodad : currentBoard.getDoodads().values()) {
        if (!Crissaegrim.getDebugMode()) {
          doodad.draw();
        } else {
          doodad.drawDebugMode();
        }
      }
      drawLocalDroppedItems();
      Crissaegrim.getPlayer().draw();
      if (Crissaegrim.getDebugMode()) {
        Crissaegrim.getPlayer().drawDebugMode();
      }
      drawGhosts();
      ClientBoard.draw(currentBoard, TileLayer.FOREGROUND);
      drawParticleSystems();
    }

    GameInitializer.initializeNewFrameForWindow();
    Crissaegrim.getPlayer().getInventory().draw();
    while (!waitingChatMessages.isEmpty()) {
      Crissaegrim.getChatBox().addChatMessage(waitingChatMessages.remove(0));
    }
    Crissaegrim.getChatBox().draw();
  }
示例#2
0
  public static void clickHWall(BoardGui frame, Robot bot, Board board, int sectNum) {
    int xInstersectOffset = 7;
    int yInstersectOffset = 51;
    // Rest for a little while
    try {
      Thread.sleep(900, 000);
    } catch (InterruptedException e) {
    }

    // Intersects
    bot.mouseMove(
        frame.sect.get(sectNum).getX() + xInstersectOffset,
        frame.sect.get(sectNum).getY() + yInstersectOffset);

    bot.mousePress(InputEvent.BUTTON1_MASK);
    // add time between press and release or the input event system may
    // not think it is a click
    try {
      Thread.sleep(250);
    } catch (InterruptedException e) {
    }
    bot.mouseRelease(InputEvent.BUTTON1_MASK);

    try {
      Thread.sleep(250);
    } catch (InterruptedException e) {
    }
    frame.submitHWall();

    frame.labels[board.getCurrPlayer()].setText(
        "\t\t\t " + board.getWallCount(board.getCurrPlayer()) + " walls remain");
    frame.labels[board.getCurrPlayer()].repaint();

    frame.control.iteratePlayers(board, board.getPlayerCount());
  }
示例#3
0
  // ---------makes the animation for the remote player's (computer) bead---------
  private void startRemoteMoving(String position) {

    System.out.println("procesing " + position);
    if (isWin(position)) {

      winner = parseWinner(position);
      if (winner == 1) startImageLoader(WIN_IMAGE_FILE);
      else {

        isWinLoseTimer = new Timer(IMAGE_LOADERS_TIMER, this);
        isWinLoseTimer.setActionCommand("is win_lose");
        isWinLoseTimer.setRepeats(false); // occurs only one time
        isWinLoseTimer.start();
      }
      repaint();
      return;
    }
    if (isDraw(position)) {
      winner = 0;
      startImageLoader(TIE_IMAGE_FILE);
      repaint();
      return;
    }

    insertedInPegNum = mapPosToPeg(position);

    availableBeads[currentBead].setX(
        PEG_INITIAL_X[insertedInPegNum - 1]
            - (int) (availableBeads[currentBead].getBounds().getWidth() / 2));
    availableBeads[currentBead].setY(PEG_INITIAL_Y[insertedInPegNum - 1]);

    pegs[insertedInPegNum - 1].addBead(availableBeads[currentBead]);

    remoteBeadAnimTimer = new Timer(ANIMATION_REFRESH_RATE, this);
    remoteBeadAnimTimer.setActionCommand("remote bead animator");

    // sets the peg
    remoteBeadAnimTimer.setRepeats(true);
    remoteBeadAnimTimer.start();
    // creates and inserts new bead
    currentBead++;

    // System.out.println( "Type of game: " + typeOfGame );
    if (typeOfGame.equals("Gertrudis vs Computer")) {

      if (currentBead % 2 != 0) {
        availableBeads[currentBead] = new Bead(BEAD_INITIAL_X, BEAD_INITIAL_Y, 'b');
        availableBeads[currentBead].setImage(board.getBlackBeadImage());
      } else {
        availableBeads[currentBead] = new Bead(BEAD_INITIAL_X, BEAD_INITIAL_Y, 'w');
        availableBeads[currentBead].setImage(board.getWhiteBeadImage());
      }

    } else {
      availableBeads[currentBead] = new Bead(BEAD_INITIAL_X, BEAD_INITIAL_Y, 'w');
      availableBeads[currentBead].setImage(board.getWhiteBeadImage());
    }
  }
示例#4
0
  // -----------draws names on screen-----------
  private void displayNames(Graphics g) {

    // draw players names
    drawText(g, "Player 1", TEXT_P1_INITIAL_X, TEXT_P1_INITIAL_Y + 4, Color.green, 22);
    drawText(g, board.player1(), TEXT_P1_INITIAL_X, TEXT_P1_INITIAL_Y, Color.blue, 22);
    drawText(g, "Player 2", TEXT_P2_INITIAL_X, TEXT_P2_INITIAL_Y + 4, Color.green, 22);
    drawText(g, board.player2(), TEXT_P2_INITIAL_X, TEXT_P2_INITIAL_Y, Color.blue, 22);
    drawText(g, "___________", BEAD_TEXT_INITIAL_X, BEAD_TEXT_INITIAL_Y - 4, Color.BLACK, 17);
    drawText(g, " Free Bead", BEAD_TEXT_INITIAL_X, BEAD_TEXT_INITIAL_Y, Color.BLACK, 17);
  }
  private EvalResult eval(
      Board board,
      int restDepth,
      Turn currentTurn,
      Evaluator evaluator,
      double alpha,
      double beta) {
    if (restDepth == 0) return new EvalResult(evaluator.score(board, currentTurn), null);

    // 置ける手を全て列挙
    List<Position> puttablePositions = board.findPuttableHands(currentTurn.stone());

    // 自分がおける場所がないならば、相手のターンになる。
    if (puttablePositions.isEmpty()) {
      double score =
          -eval(board, restDepth - 1, currentTurn.flip(), evaluator, -beta, -alpha).getScore();
      return new EvalResult(score, null);
    }

    if (restDepth >= 5) doMoveOrdering(board, puttablePositions, currentTurn, evaluator);

    // 自分の番では、評価が最も大きくなるものを選ぶ。
    double maxScore = Double.NEGATIVE_INFINITY;
    Position selectedPosition = null;

    for (Position p : puttablePositions) {
      Board b = board.clone();
      Evaluator e = evaluator.clone();

      e.willPut(b, p.x, p.y, currentTurn.stone());
      b.put(p.x, p.y, currentTurn.stone());

      double a = Math.max(alpha, maxScore);
      double score = -eval(b, restDepth - 1, currentTurn.flip(), e, -(a + 1), -a).getScore();
      if (a < score && score < beta) {
        e = evaluator.clone();
        e.willPut(board, p.x, p.y, currentTurn.stone());
        score = -eval(b, restDepth - 1, currentTurn.flip(), e, -beta, -score).getScore();
      }

      if (maxScore < score) {
        maxScore = score;
        selectedPosition = p;
      }

      // beta cut
      if (maxScore >= beta) return new EvalResult(score, p);
    }

    assert (selectedPosition != null);
    return new EvalResult(maxScore, selectedPosition);
  }
示例#6
0
 // ---------draws winner on screen--------------
 private void displayWinner(Graphics g) {
   if (winner == 1) {
     // System.out.println( "Printing winner "  + 1 );
     drawText(
         g, board.player1() + " wins!", LOSE_WIN_TIE_TEXT_X, LOSE_WIN_TIE_TEXT_Y, Color.red, 38);
   } else if (winner == 2) {
     // System.out.println( "Printing winner "  + 2 );
     drawText(
         g, board.player2() + " wins!", LOSE_WIN_TIE_TEXT_X, LOSE_WIN_TIE_TEXT_Y, Color.red, 38);
   } else if (winner == 0) {
     // System.out.println( "Printing tie" );
     drawText(g, "DRAW", LOSE_WIN_TIE_TEXT_X, LOSE_WIN_TIE_TEXT_Y, Color.red, 38);
   }
 }
示例#7
0
文件: King.java 项目: cmnadolny/chess
  /*
   * Method to check if the king can move to a position without being put in check
   */
  public Boolean canKingMove(int destX, int destY, Board board) {
    ArrayList<Piece> enemyPieces = board.getEnemyPieces(this.color);

    for (int i = 0; i < enemyPieces.size(); i++) {
      Piece enemyPiece = enemyPieces.get(i);
      String type = enemyPiece.getClass().getName().substring(7).toLowerCase();
      if (type.equals("king") && board.canKingMove(destX, destY, enemyPiece)) {
        return false;
      } else if (enemyPiece.checkValid(destX, destY, board)) {
        return false;
      }
    }

    return true;
  }
示例#8
0
  /**
   * Returns the move with the best score for the selected player, doing a recursive search to the
   * specified depth. Returns a ScoreMove object that holds the move and its score
   *
   * @param depth the max depth to search to
   * @param color the color whose score to maximize
   * @param a
   * @return the highest scoring move and score
   */
  private ScoreMove chooseMove(int depth, int color, int a, int b) {
    Move bestMove = new Move();
    int bestScore = 0;
    if (color == this.color) bestScore = a;
    else bestScore = b;

    LinkedList<ScoreMove> scores = new LinkedList<ScoreMove>();
    boolean first = true; // first is used to get the method started
    for (Move move : board.getValidMoves(color)) {
      int moveScore = getScore(move, depth, color, a, b);
      scores.add(new ScoreMove(moveScore, move));
      if (first
          || (this.color == color && moveScore > bestScore)
          || (oppositeColor(this.color) == color
              && moveScore < bestScore)) // This player's move (max score)
      { // Other player's move (min score)
        bestMove = move;
        bestScore = moveScore;
        if (this.color == color) {
          a = moveScore;
        } else {
          b = moveScore;
        }
        first = false;
      }
      if (a >= b) break;
    }
    return new ScoreMove(bestScore, bestMove);
  }
示例#9
0
  public static ArrayList<Tile> getMovements(
      Board board, Color color, Type t, Location l, boolean attacksOnly) {
    ArrayList<Location> movements = null;
    int row = l.getRow();
    int col = l.getCol();
    switch (t) {
      case PAWN:
        movements = PawnMovement.getAdjacentMoves(board, color, row, col, attacksOnly);
        break;
      case ROOK:
        movements = HorizontalMovement.getHorizontalMoves(board, row, col, attacksOnly);
        break;
      case KNIGHT:
        movements = KnightMovement.getLMoves(row, col);
        break;
      case BISHOP:
        movements = DiagonalMovement.getDiagonalMoves(board, row, col, attacksOnly);
        break;
      case KING:
        movements = KingMovement.getKingMoves(board, row, col, attacksOnly);
        break;
      case QUEEN:
        movements = HorizontalMovement.getHorizontalMoves(board, row, col, attacksOnly);
        movements.addAll(DiagonalMovement.getDiagonalMoves(board, row, col, attacksOnly));
        break;
    }

    ArrayList<Tile> ret = filterMovements(board, l, movements, color);
    if (ret != null && !ret.isEmpty()) {
      Assert.assertEquals(ret.get(0), board.getSquare(ret.get(0).getRow(), ret.get(0).getColumn()));
    }

    return ret;
  }
  private Point getRandomShot() {
    Random random = new Random();

    Point nextShot = null;
    boolean validShot = false;

    int nextX;
    int nextY;

    int origX = origHit.getX();
    int origY = origHit.getY();

    while (!validShot) {
      if (random.nextInt() % 2 == 0) {
        if (random.nextInt() % 2 == 0) nextX = origX - 1;
        else nextX = origX + 1;

        nextY = origY;
      } else {
        nextX = origX;

        if (random.nextInt() % 2 == 0) nextY = origY - 1;
        else nextY = origY + 1;
      }

      nextShot = new Point(nextX, nextY);

      if (!board.isValidShot(nextShot) || alreadyTriedShot(nextShot)) validShot = false;
      else validShot = true;
    }

    return nextShot;
  }
示例#11
0
  /**
   * This method takes an event, and sends the appropriate commands to the model based on the
   * command that the event sends:
   *
   * @param event an actionEvent representing an instruction from the View.
   */
  public void actionPerformed(ActionEvent event) {
    gameBoard = Board.getBoard();
    gameInfo = GameInfoPanel.getGameInfo();

    String actionCommand = event.getActionCommand();

    // play button commands
    if (actionCommand.equals("play")) {
      /** this is passed in as an ActionListener */
      if (!hasStarted) {
        makeGameThread();
        waitTime = DEFAULT_RUN;
        hasStarted = true;
        isFinished = model.isFinished();
      } else {
        paused = false;
        waitTime = DEFAULT_RUN;
      }
    }

    // fastforward button commands
    if (actionCommand.equals("fastForward")) {
      paused = false;
      waitTime = FAST_FORWARD;
    }

    // fastforwardX2 button commands
    if (actionCommand.equals("fastForwardX2")) {
      paused = false;
      waitTime = DOUBLE_FAST_FORWARD;
    }

    // pause button commands (pause game until user runs some sort of play
    if (actionCommand.equals("pause")) {
      paused = true;
    }

    // stop game
    if (actionCommand.equals("stop")) {
      gameStopped = true;
    }

    // handle stepback button
    if (actionCommand.equals("home")) {
      JOptionPane.showMessageDialog(
          null,
          "This button does not work at this time, sorry.",
          "ERROR",
          JOptionPane.WARNING_MESSAGE);
    }
    // handle stepback button
    if (actionCommand.equals("stepback")) {
      JOptionPane.showMessageDialog(
          null,
          "This button does not work at this time, sorry.",
          "ERROR",
          JOptionPane.WARNING_MESSAGE);
    }
  }
示例#12
0
  @Override
  public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    displayNames(g);
    displayWinner(g);
    g2d.drawImage(board.getImage(), board.getX(), board.getY(), null, null);

    for (int i = 0; i < 16; i++) {
      g2d.drawImage(pegs[i].getImage(), pegs[i].getX(), pegs[i].getY(), null, null);
      for (int j = 0; j < pegs[i].amountOfBeads2(); j++) {
        g2d.drawImage(
            pegs[i].beadAt(j).getImage(),
            pegs[i].beadAt(j).getX(),
            pegs[i].beadAt(j).getY(),
            null,
            null);
      }
    }

    if (availableBeads[currentBead].getImage() == null) {
      availableBeads[currentBead].loadImage();
    }

    g2d.drawImage(
        availableBeads[currentBead].getImage(),
        availableBeads[currentBead].getX(),
        availableBeads[currentBead].getY(),
        null,
        null);

    if (beadMustAnimate) {
      animationTimer = new Timer(ANIMATION_REFRESH_RATE, this); // every
      // REFRESH_RATE
      // ms
      animationTimer.setActionCommand("animation");
      animationTimer.start();
      beadMustAnimate = false;
      currentBead++;
      // creates next new bead
      availableBeads[currentBead] = new Bead(BEAD_INITIAL_X, BEAD_INITIAL_Y, 'b');
      availableBeads[currentBead].setImage(board.getBlackBeadImage());
    }
  }
示例#13
0
 private boolean pathIsObstructed(Board board, Location currentLocation, Location newLocation) {
   boolean lastValidMove = false;
   if (board.getSquare(newLocation).isOccupied()) {
     if (!newLocation.equals(currentLocation)) {
       lastValidMove = true;
     }
   }
   return lastValidMove;
 }
示例#14
0
  /**
   * Returns the score of the given move made by the given color based upon searches to the
   * specified depth.
   *
   * @param m the move to score
   * @param depth the max depth to search to
   * @param color the player who makes the move
   * @return the score of the move
   */
  private int getScore(Move m, int depth, int color, int a, int b) {
    board.makeMove(m, color);
    depth--;

    int score = 0;
    if (board.hasNetwork(oppositeColor(this.color))) {
      score = Scorer.MINSCORE - depth;
    } else if (board.hasNetwork(this.color)) {
      score = Scorer.MAXSCORE + depth;
    } else if (depth == 0 || Scorer.hasScore(board, color)) {
      score = Scorer.getScore(board, this.color);
    } else {
      score = chooseMove(depth, oppositeColor(color), a, b).score;
      Scorer.addScore(board, color, score);
    }
    board.rollback();
    return score;
  }
示例#15
0
 public void moveTo(int x, int y) {
   if (board.isValidPosition(x, y)) {
     if (x == this.x + 1 || x == this.x - 1) {
       if (y == this.y + 1 || y == this.y - 1) {
         this.x = x;
         this.y = y;
       }
     }
   }
 }
示例#16
0
  ////////////////////////////////////////////////////////////
  // 			CONSTRUCTOR
  ////////////////////////////////////////////////////////////
  public Panel(
      String p1,
      String p2,
      LinkedBlockingQueue<String> sendQueue,
      LinkedBlockingQueue<String> recvQueue,
      JMenuBar menuBar)
      throws InterruptedException, ExecutionException {
    winner = NO_WINNER;
    typeOfGame = "";
    this.menuBar = menuBar;
    this.sendQueue = sendQueue; // receives queues
    this.recvQueue = recvQueue;
    board = new Board(BOARD_INITIAL_X, BOARD_INITIAL_Y); // creates board
    board.setPlayerNames(p1, p2);
    pegs = new Peg[MAX_NUM_PEGS];
    beadMustAnimate = false;
    isFirstTransaction = true;
    insertedInPegNum = 0;
    currentBead = 0;
    // its referree's responsibility to stop the game when no more bead are avasilable
    availableBeads = new Bead[MAX_NUM_BEADS * 2];

    // sets first free bead
    availableBeads[0] = new Bead(BEAD_INITIAL_X, BEAD_INITIAL_Y, 'w');
    availableBeads[0].setImage(board.getWhiteBeadImage());
    for (int i = 0; i < 16; i++) {
      pegs[i] = new Peg(PEG_INITIAL_X[i], PEG_INITIAL_Y[i]);
    }

    setFocusable(true); // makes panel focusable

    // adds listeners
    mouseListener = new MouseListener();
    addMouseMotionListener(mouseListener);
    addMouseListener(mouseListener);

    // when this timer fires, images will be displayed
    updateWhenLoaded = new Timer(IMAGE_LOADERS_TIMER, this);
    updateWhenLoaded.setActionCommand("images are loaded");
    updateWhenLoaded.setRepeats(false); // occurs only one time
    updateWhenLoaded.start();
  }
示例#17
0
 /**
  * Returns a new <code>Move</code> by this player. Internally records the move (update the
  * internal game board) as a move by this player. Changes search depth based on whether pieces are
  * being added or stepped
  *
  * @return the Move chosen by this player
  */
 public Move chooseMove() {
   int maxDepth = searchDepth;
   if (maxDepth == VARDEPTH) {
     if (board.getNumPieces(color) > 8) // Step move
     maxDepth = 4;
     else // Add move
     maxDepth = 4;
   }
   Move m;
   if (board.getNumPieces(color) == 0) { // First move starts in center
     m = new Move(3, 3);
     if (!board.isValidMove(m, color)) m = new Move(3, 4);
   } else {
     ScoreMove sm = chooseMove(maxDepth, color, Scorer.MINSCORE - 1, Scorer.MAXSCORE + 1);
     m = sm.move;
     Scorer.clearCache();
   }
   board.makeMove(m, color);
   return m;
 }
示例#18
0
文件: King.java 项目: cmnadolny/chess
  /*
   *Method to check if a king can move to a location on the board
   *
   */
  public Boolean checkValid(int destX, int destY, Board board) {

    if (Math.abs(destX - this.currX) != 1 && (destX - this.currX) != 0) {
      return false;
    }

    if (Math.abs(destY - this.currY) != 1 && (destY - this.currY) != 0) {
      return false;
    }

    if (board.getPiece(destX, destY) != null && board.getPiece(destX, destY).color == this.color) {
      return false;
    }

    if (!canKingMove(destX, destY, board)) {
      return false;
    }

    return true;
  }
  protected List<Position> doMoveOrdering(
      Board board, List<Position> ps, Turn currentTurn, Evaluator evaluator) {
    List<EvalResult> shallowEvaluation = new ArrayList<EvalResult>();
    for (Position p : ps) {
      Board b = board.clone();
      Evaluator e = evaluator.clone();

      e.willPut(board, p.x, p.y, currentTurn.stone());
      b.put(p.x, p.y, currentTurn.stone());

      EvalResult er = eval(b, 2, currentTurn.flip(), e);
      shallowEvaluation.add(new EvalResult(-er.getScore(), p));
    }

    // スコアの大きい方から並べる。
    Collections.sort(shallowEvaluation, new HandComparator());

    List<Position> result = new ArrayList<Position>();
    for (EvalResult er : shallowEvaluation) result.add(er.getPosition());
    return result;
  }
示例#20
0
  public static void main(String[] args) throws IOException, OverPopulationException {
    String path = args[0];
    String lineread;
    BoardLoader BL = new BoardLoader();
    Display BD =
        new Display(new Location(-100, -30), new Location(-100, 50), new Location(100, -30));
    Board B = BL.Load(path);

    BD.PrintBoard(B);
    System.out.println("\n\nEnter q to quit, otherwise press enter:\n\n");
    try (BufferedReader cin = new BufferedReader(new InputStreamReader(System.in))) {
      while (!(lineread = cin.readLine()).equals("q")) {
        B = B.NextGeneration();
        BD.PrintBoard(B);
        System.out.println("\n\nEnter q to quit, otherwise press enter:\n\n");
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    return;
  }
示例#21
0
  /** @author David Rice This is the main for the Quoridor game */
  public static void main(String[] args) throws AWTException {

    Board board = new Board(2);

    board.setCurrPlayer(0);

    BoardGui frame = new BoardGui(board.getPlayerCount(), board.getCurrPlayer(), board);
    frame.setSize(700, 410);
    frame.setResizable(false);
    frame.setVisible(true);

    /*
    Robot bot = new Robot();

    // Rest for a little while
    try{Thread.sleep(900,000);}catch(InterruptedException e){}
    clickSpace(frame, bot, board, 3);

    clickHWall(frame, bot, board, 17);

    clickVWall(frame, bot, board, 10);
    */
  }
示例#22
0
  private static ArrayList<Tile> filterMovements(
      Board board, Location l, List<Location> locations, Color color) {

    ArrayList<Tile> moves = new ArrayList<Tile>();

    for (Location location : locations) {
      Tile tile = board.getSquare(location);
      // You can't take a king or your own pieces
      if (!(tile.isOccupied() && (tile.getOccupiedPiece().getColor().equals(color)))) {
        moves.add(tile);
      }
    }
    Collections.sort(moves, new TileComparator());
    return moves;
  }
示例#23
0
  public static void main(String[] args) throws Exception {
    Board board = new Board();
    board.setup();

    Turn turn = Turn.BLACK;
    boolean hasPassed = false;

    // Player blackPlayer = new HumanPlayer(Turn.BLACK);
    // Player blackPlayer = new SimpleAI(Turn.BLACK);
    // Player blackPlayer = new MinMaxSimpleAIPlayer(Turn.BLACK, 5);
    // Player blackPlayer = new NegaMaxBoardScoreAIPlayer(Turn.BLACK, 5);
    Player blackPlayer =
        new PerfectPlayWrapperPlayer(new NegaScoutAdvancedAIPlayer(Turn.BLACK, 7), 15);
    // Player blackPlayer = new AlphaBetaSimpleAI(Turn.BLACK, 5);
    // Player blackPlayer = new LearnedAI(turn, 9, 15);
    // Player whitePlayer = new SimpleAI(Turn.WHITE);
    // Player whitePlayer = new MinMaxSimpleAIPlayer(Turn.WHITE, 5);
    // Player whitePlayer = new NegaMaxSimpleAIPlayer(Turn.WHITE, 5);
    Player whitePlayer =
        new PerfectPlayWrapperPlayer(new NegaScoutLearnedAIPlayer(Turn.WHITE, 7), 15);
    // Player whitePlayer = new NegaMaxBoardScoreAIPlayer(Turn.WHITE, 5);
    // Player whitePlayer = new NegaMaxAdvancedAI(Turn.WHITE, 5);
    // Player whitePlayer = new AlphaBetaSimpleAI(Turn.WHITE, 5);
    // Player whitePlayer = new AlphaBetaEvaluationSimpleWithCompleteReadingAI(Turn.WHITE, 5, 15);
    // Player whitePlayer = new NegaScoutEvaluationSimpleAI(Turn.WHITE, 5);
    // Player whitePlayer = new NegaScoutEvaluationSimpleWithCompleteReadingAI(Turn.WHITE, 5, 15);
    // Player whitePlayer = new TranpositionEvaluationSimpleAI(Turn.WHITE, 5);
    // Player whitePlayer = new TranpositionEvaluationCompleteReadingSimpleAI(Turn.WHITE, 5, 15);

    while (true) {
      // 盤を見やすいように表示
      board.show();

      // どこかに置けないならばパスをしなければならない。
      if (!board.isPuttableSomewhere(turn.stone())) {
        if (hasPassed) // 2連続パスすると終了
        break;

        hasPassed = true;
        turn = turn.flip();
        continue;
      }

      hasPassed = false;
      Position p;
      if (turn == Turn.BLACK) p = blackPlayer.play(board);
      else p = whitePlayer.play(board);

      board.put(p.x, p.y, turn.stone());
      turn = turn.flip();
    }

    System.out.printf("BLACK = %d\n", board.countStone(Stone.BLACK));
    System.out.printf("WHITE = %d\n", board.countStone(Stone.WHITE));
  }
示例#24
0
  @Override
  // public void draw(Graphics g, Board b, int z, boolean highlight) {
  public void draw(Graphics g, Board b) {
    int doorFraction = 5;
    // int pixelModifier = 25;
    int pixelModifier =
        Math.min(b.size().width / b.getNumColumns(), b.size().height / b.getNumRows());
    int doorOffset = pixelModifier / doorFraction;
    b.setPixelModifier(pixelModifier);

    g.setColor(Color.LIGHT_GRAY);
    if (this.highlight) {
      g.setColor(Color.GREEN);
    }

    g.fillRect(column * pixelModifier, row * pixelModifier, pixelModifier, pixelModifier);
    g.setColor(Color.blue);
    if (this.isDoorway() && (doorDirection.equals(DoorDirection.UP))) {
      g.fillRect(column * pixelModifier, row * pixelModifier, pixelModifier, doorOffset);
    } else if (this.isDoorway() && (doorDirection.equals(DoorDirection.DOWN))) {
      g.fillRect(
          column * pixelModifier,
          (row * pixelModifier + pixelModifier) - doorOffset,
          pixelModifier,
          doorOffset);
    } else if (this.isDoorway() && (doorDirection.equals(DoorDirection.LEFT))) {
      g.fillRect(column * pixelModifier, row * pixelModifier, doorOffset, pixelModifier);
    } else if (this.isDoorway() && (doorDirection.equals(DoorDirection.RIGHT))) {
      g.fillRect(
          (column * pixelModifier + pixelModifier) - doorOffset,
          row * pixelModifier,
          doorOffset,
          pixelModifier);
    }
    if (drawName) {
      g.drawChars(
          b.getRooms().get(roomClassifier).toCharArray(),
          0,
          b.getRooms().get(roomClassifier).length(),
          column * pixelModifier,
          row * pixelModifier);
    }
  }
示例#25
0
  public static void clickSpace(BoardGui frame, Robot bot, Board board, int space) {
    int xButtonOffset = 16;
    int yButtonOffset = 63;
    // Rest for a little while
    try {
      Thread.sleep(900, 000);
    } catch (InterruptedException e) {
    }
    // Spaces
    bot.mouseMove(
        frame.space.get(space).getX() + xButtonOffset,
        frame.space.get(space).getY() + yButtonOffset);

    bot.mousePress(InputEvent.BUTTON1_MASK);
    // add time between press and release or the input event system may
    // not think it is a click
    try {
      Thread.sleep(250);
    } catch (InterruptedException e) {
    }
    bot.mouseRelease(InputEvent.BUTTON1_MASK);

    frame.control.iteratePlayers(board, board.getPlayerCount());
  }
示例#26
0
  public vsGame(Board board, ArrayList<InputConfigData> InitialConfig) {
    gameBoard = board;

    board.reset(InitialConfig);
  }
示例#27
0
  @Override
  public ArrayList<Move> getMoves(Board board) {
    ArrayList<Move> movesList = new ArrayList<Move>();

    Location newLocation = null;
    Location currentLocation = board.getLocation(this);
    char column = currentLocation.getCharacter();
    int row = currentLocation.getInteger();
    int boardLength = 8;

    // Down Left
    for (int i = 1; i < boardLength; i++) {
      newLocation = new Location((char) (column - i), (row - i));
      if (board.isValidSquare(newLocation)) {
        Piece p = board.getPiece(newLocation);
        if (p != null && p.getColor() != this.getColor()) {
          movesList.add(new Move(currentLocation, newLocation));
        } else if (p == null) {
          movesList.add(new Move(currentLocation, newLocation));
        }

        if (pathIsObstructed(board, currentLocation, newLocation)) break;
      }
    }

    // Down Right
    for (int i = 1; i < boardLength; i++) {
      newLocation = new Location((char) (column + i), (row - i));
      if (board.isValidSquare(newLocation)) {
        Piece p = board.getPiece(newLocation);
        if (p != null && p.getColor() != this.getColor()) {
          movesList.add(new Move(currentLocation, newLocation));
        } else if (p == null) {
          movesList.add(new Move(currentLocation, newLocation));
        }

        if (pathIsObstructed(board, currentLocation, newLocation)) break;
      }
    }

    // Up Left
    for (int i = 1; i < boardLength; i++) {
      newLocation = new Location((char) (column - i), (row + i));
      if (board.isValidSquare(newLocation)) {
        Piece p = board.getPiece(newLocation);
        if (p != null && p.getColor() != this.getColor()) {
          movesList.add(new Move(currentLocation, newLocation));
        } else if (p == null) {
          movesList.add(new Move(currentLocation, newLocation));
        }

        if (pathIsObstructed(board, currentLocation, newLocation)) break;
      }
    }

    // Up Right
    for (int i = 1; i < boardLength; i++) {
      newLocation = new Location((char) (column + i), (row + i));
      if (board.isValidSquare(newLocation)) {
        Piece p = board.getPiece(newLocation);
        if (p != null && p.getColor() != this.getColor()) {
          movesList.add(new Move(currentLocation, newLocation));
        } else if (p == null) {
          movesList.add(new Move(currentLocation, newLocation));
        }

        if (pathIsObstructed(board, currentLocation, newLocation)) break;
      }
    }

    return movesList;
  }
示例#28
0
 /**
  * Forces this player to make the specified move if legal and returns true. If the move is not
  * legal, returns false and does not record the move.
  *
  * @param m the Move forced to make
  * @return true if legal move, false otherwise
  */
 public boolean forceMove(Move m) {
   if (!board.isValidMove(m, color)) return false;
   board.makeMove(m, color);
   return true;
 }
示例#29
0
 /**
  * Records the specified move as a move by the opponent if it is legal and returns true. If the
  * move is not legal, returns false and does not record the move.
  *
  * @param m the Move provided by the opponent
  * @return true if legal move, false otherwise
  */
 public boolean opponentMove(Move m) {
   if (!board.isValidMove(m, oppositeColor(color))) return false;
   board.makeMove(m, oppositeColor(color));
   return true;
 }
 @Override
 public List<Coordinate> getMatchCoordinates(Board board, Coordinate coord) {
   List<Coordinate> res = new ArrayList<>();
   res.addAll(board.getColumn(coord));
   return res;
 }