コード例 #1
0
ファイル: Board.java プロジェクト: hodgesbe/Othello
 // checks to see who won the game
 public void whoWon(Player me, Player opp) {
   int myPieces = countPieces(me);
   int oppPieces = countPieces(opp);
   if (myPieces > oppPieces) {
     System.out.println("C " + me.getPlayerColor() + " has won the game with: " + myPieces);
   } else System.out.println("C " + opp.getPlayerColor() + " has won the game with: " + oppPieces);
 }
コード例 #2
0
ファイル: Board.java プロジェクト: hodgesbe/Othello
  // generates all possible moves for player passed, gives them a rating, and sorts them
  public ArrayList<Move> generateMoves(Player player) {
    int playerNumber = player.getPlayerNumber();
    ArrayList<Move> moveList = new ArrayList<>();

    for (int i = 0; i < board.length; i++) {
      if (isValidMove(playerNumber, i)) {
        Move move = new Move(i);
        if (CORNERS.contains(move.getMove())) {
          move.setValue(500);
        } else if (AMOVES.contains(move.getMove())) {
          move.setValue(250);
        } else if (BMOVES.contains(move.getMove())) {
          move.setValue(100);
        } else if (CMOVES.contains(move.getMove())) {
          move.setValue(50);
        } else move.setValue(-5);

        moveList.add(move);
      }
    }

    // in case of no moves, add pass move
    if (moveList.size() > 0) {
      Collections.sort(moveList, new MoveComparator());
      Collections.reverse(moveList);
    } else {
      String pass = "" + player.getPlayerColor();
      Move move = new Move(pass);
      moveList.add(move);
    }

    player.assignPossibleMoves(moveList);
    return moveList;
  }
コード例 #3
0
ファイル: Board.java プロジェクト: hodgesbe/Othello
  // evaluates board for each player
  public void evaluateBoard(Player me, Player opp) {
    int myNumber = me.getPlayerNumber();
    int oppNumber = opp.getPlayerNumber();
    int myScore = 0, oppScore = 0;

    for (int i = 0; i < board.length; i++) {
      if (board[i] == myNumber) {
        myScore += rateSpace(i);

      } else if (board[i] == oppNumber) {
        oppScore += rateSpace(i);
      }
    }

    me.setCurrentBoardScore(myScore);
    opp.setCurrentBoardScore(oppScore);

    System.out.println("C " + me.getPlayerColor() + "'s current board score is: " + myScore);
    System.out.println("C " + opp.getPlayerColor() + "'s current board score is: " + oppScore);
  }