/** * 定石を適用し、考えられるすべての手を実行した子ノードのゲームボードを返します * * @return */ public ArrayList<GameBoard> extpand() { /** 子ノードを定石を使って拡張する */ ArrayList<GameBoard> children = new ArrayList<>(); // くじ引き ArrayList<Integer> omikuji = new ArrayList<Integer>(); omikuji.add(0); omikuji.add(1); omikuji.add(2); omikuji.add(3); int id = this.whoIsPlay(); // タワーに存在するユニットの数を取得 int towerUnit = 0; for (int j = 0; j < 4; j++) { if (isTowerPos(unitLocation[id][j])) towerUnit++; } // 実行可能手をすべて展開 for (int j = 0; j < 4; j++) { int index = omikuji.remove((int) (omikuji.size() * Math.random())); // すべてタワーにいない場合に限り // タワーマスにいて苦手とするユニットが接近していなければタワーにいる if (towerUnit < 3) { boolean f4 = formula4(unitLocation, index, id, this.turnState, this.firstTeamId); if (!f4) continue; } for (int i = 0; i < 8; i++) { int x = this.unitLocation[id][index].x + movex[i]; int y = this.unitLocation[id][index].y + movey[i]; // x,yが範囲外なら無視 if (!availableArea(x, y)) { continue; } boolean f1 = formula1(movex[i], movey[i], x, y, id); // 移動範囲漏れチェック if (!f1) continue; // 定石外 // boolean f2 = formula2(handHistory,x,y,index,id); // 過去の動き重複チェック // if(!f2) continue; // 定石外 // ボードを複製し、動かす GameBoard tmp = new GameBoard(this); tmp.move(movex[i], movey[i], index); tmp.handHistory.addLast(new Hand(x, y, index, id)); // 一定数以上の履歴は破棄する if (tmp.handHistory.size() > HAND_HISTORY_NUM) { tmp.handHistory.removeFirst(); } // 候補に追加 children.add(tmp); } } return children; }