Android Open Source - MiReversi Computer Player Level0






From Project

Back to project page MiReversi.

License

The source code is released under:

MIT License

If you think the Android project MiReversi listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
* Copyright (c) 2011 Makoto Ishida//from  w ww.j ava2  s.  c om
* Please see the file MIT-LICENSE.txt for copying permission.
*/

package com.example.mireversi.model;

import java.util.ArrayList;
import java.util.Random;
import android.graphics.Point;
import com.example.mireversi.model.Cell.E_STATUS;

public class ComputerPlayerLevel0 extends ComputerPlayer {

  private static int WAIT_MSEC = 10;
  private Random mRnd;
  
  public ComputerPlayerLevel0(E_STATUS turn, String name, Board board){
    super(turn, name, board);
    
    mRnd = new Random();
  }

  @Override
  protected Point think() {
    Point pos = null;
    
    try {
      Thread.sleep(WAIT_MSEC);
    } catch (InterruptedException e) {
      setStopped(true);
    }
    if (isStopped()) return pos;          //????????????????????????????
    
    //????????????????????????????
    ArrayList<Cell> available_cells = mBoard.getAvailableCells();
    if (available_cells.size() == 0){
      return pos;
    }
    
    if (isStopped()) return pos;          //????????????????????????????
    
    //?????????????????????????????????
    int n = mRnd.nextInt(available_cells.size());
    Cell chosenCell = available_cells.get(n);
    pos = chosenCell.getPoint();

    return pos;
  }

}




Java Source Code List

com.example.mireversi.GameActivity.java
com.example.mireversi.Pref.java
com.example.mireversi.ReversiView.java
com.example.mireversi.Utils.java
com.example.mireversi.exceptions.InvalidMoveException.java
com.example.mireversi.model.Board.java
com.example.mireversi.model.Cell.java
com.example.mireversi.model.ComputerPlayerLevel0.java
com.example.mireversi.model.ComputerPlayerLevel1.java
com.example.mireversi.model.ComputerPlayerLevel2.java
com.example.mireversi.model.ComputerPlayerLevel3.java
com.example.mireversi.model.ComputerPlayer.java
com.example.mireversi.model.HumanPlayer.java
com.example.mireversi.model.IPlayerCallback.java
com.example.mireversi.model.Player.java