@Override
 public boolean isPlayerTurn() {
   return board.whoIsPlay() == this.playerTeamId;
 }
Exemplo n.º 2
0
  /**
   * ランダムにゲーム終了までプレイする
   *
   * @return ture プレイヤーの勝ち
   */
  public boolean doPlayout() {

    //  ゲームボードをコピーしおておく
    GameBoard playout = new GameBoard(this);

    //  プレイアウト専用移動履歴
    LinkedList<Hand> history = new LinkedList<>();

    //  ゲーム終了まで繰り返す
    while (playout.isGameEnd() == -1) {

      //  移動候補手
      ArrayList<Hand> canditate = new ArrayList();

      int id = playout.whoIsPlay();
      for (int j = 0; j < 4; j++) { //  すべての手について

        //  タワーマスにいて苦手とするユニットが接近していなければタワーにいる
        boolean f4 = formula4(unitLocation, j, id, this.turnState, this.firstTeamId);
        if (!f4) continue;

        for (int i = 0; i < 8; i++) {

          int x = playout.unitLocation[id][j].x + movex[i];
          int y = playout.unitLocation[id][j].y + movey[i];

          //  x,yが範囲外なら無視
          if (!availableArea(x, y)) {
            continue;
          }

          //  定石1を適用
          boolean f1 = formula1(movex[i], movey[i], x, y, id);
          if (!f1) continue; //  定石外

          //  定石2を適用
          boolean f2 = formula2(history, x, y, j, id);
          if (!f2) continue; //  定石外

          //  定石3
          /*
          boolean f3 = formula3(playout.unitLocation,x,y,j,id,playout.firstTeamId,playout.turnState);
          if(!f3) continue;
          */

          //  ここまできたら候補に追加
          canditate.add(new Hand(x, y, j, id));
        }
      }

      //  候補からランダム選択
      //  候補が1個もない場合はgetAnyHand()でなんでもいいから動かす
      Hand hand;
      if (canditate.size() == 0) {
        hand = getAnyHand(this.whoIsPlay());

      } else {
        int rand = (int) (canditate.size() * Math.random());
        hand = canditate.get(rand);
      }

      //  動かす
      boolean result = playout.movePos(hand.x, hand.y, hand.index);

      //  ログに保存
      history.addLast(hand);
      if (history.size() > 5) history.removeFirst();
    }

    //  勝ちの場合は勝ちの回数を増やす
    //  ここを修正
    //  チームIDではなく現在プレイ中のプレイヤーID
    if (playout.isGameEnd() == this.whoIsPlay()) {
      return true;
    }
    return false;
  }