Android Open Source - eent-for-android Computer Player






From Project

Back to project page eent-for-android.

License

The source code is released under:

GNU General Public License

If you think the Android project eent-for-android 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

/*
 * ComputerPlayer.java/* w  w  w . ja va2  s .  c  o  m*/
 *
 * Created on 24 maart 2003, 21:12
 */
/*
 It is distributed under the GNU Public Licence (GPL) version 2.  See
 http://www.gnu.org/ for further details of the GPL.
 */
package eu.veldsoft.eent;

/**
 * 
 * @author me
 */
class ComputerPlayer extends Player {

  private int civ, chooser, lead, cat, row, col;

  /** Creates a new instance of ComputerPlayer */
  public ComputerPlayer() {
    super(Player.CPU);
    LeadTile[] templead = new LeadTile[4];
    templead[0] = new LeadTile(LeadTile.LEADER_KING, (Player) this);
    templead[1] = new LeadTile(LeadTile.LEADER_PRIEST, (Player) this);
    templead[2] = new LeadTile(LeadTile.LEADER_FARMER, (Player) this);
    templead[3] = new LeadTile(LeadTile.LEADER_TRADER, (Player) this);
    setLeaders(templead);
  }

  /**
   * computerplayer makes to moves. This is done totally at random and should
   * be changed to be more compettative
   */
  public void ComputerPlay() {
    CivTile[] tempciv = getPlayerTiles();
    LeadTile[] templead = getLeaders();
    CatTile[] tempcat = getCatTiles();

    while (hasTurn()) {
      chooser = Util.PRNG.nextInt(3);
      civ = Util.PRNG.nextInt(6);
      lead = Util.PRNG.nextInt(4);
      cat = Util.PRNG.nextInt(2);

      switch (chooser) {
      case 1:
        if (tempciv[civ] != null) {
          Grid g = new Grid(tempciv[civ], (civ + "P"));
          row = Util.PRNG.nextInt(11);
          col = Util.PRNG.nextInt(16);
          while (!(g.setTile(Board.grids[row][col]))) {
            row = Util.PRNG.nextInt(11);
            col = Util.PRNG.nextInt(16);
          }
          this.incr_turn();
          System.out.println(hasTurn());
          System.out.println(civ + ", " + row + "-" + col);
        }
        break;
      case 2:
        if (templead[lead] != null) {
          Grid m = new Grid(templead[lead], (lead + "L"));
          while (!(m.setTile(Board.grids[row][col]))) {
            row = Util.PRNG.nextInt(11);
            col = Util.PRNG.nextInt(16);
          }
          this.incr_turn();
          System.out.println(hasTurn());
          System.out.println(lead + ", " + row + "-" + col);

        }
        break;
      case 3:
        if (tempcat[cat] != null) {

          Grid m = new Grid(tempcat[cat], (cat + "C"));
          while (!(m.setTile(Board.grids[row][col]))) {
            row = Util.PRNG.nextInt(11);
            col = Util.PRNG.nextInt(16);
          }
          this.incr_turn();
          System.out.println(hasTurn());
          System.out.println(cat + ", " + row + "-" + col);

        }
        break;
      }
    }
    Tigris2.checkPlayerTurn();
  }
}




Java Source Code List

eu.veldsoft.eent.BagListener.java
eu.veldsoft.eent.Bag.java
eu.veldsoft.eent.Board.java
eu.veldsoft.eent.ButtonListener2.java
eu.veldsoft.eent.ButtonListener.java
eu.veldsoft.eent.CatTile.java
eu.veldsoft.eent.CheckBoxListener.java
eu.veldsoft.eent.CivTile.java
eu.veldsoft.eent.ComputerPlayer.java
eu.veldsoft.eent.Grid.java
eu.veldsoft.eent.HumanPlayer.java
eu.veldsoft.eent.Kingdom.java
eu.veldsoft.eent.LeadTile.java
eu.veldsoft.eent.Player.java
eu.veldsoft.eent.ScoreCounter.java
eu.veldsoft.eent.TemTile.java
eu.veldsoft.eent.Tigris2.java
eu.veldsoft.eent.Tile.java
eu.veldsoft.eent.Util.java