| |
---|
| | |
---|
| | import interfaces.IAttack; |
---|
| | import interfaces.IBotBehavior; |
---|
| | |
---|
| | import java.util.AbstractMap; |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.List; |
---|
| | import java.util.Map; |
---|
| | import java.util.*; |
---|
| | |
---|
| | import static views.Constants.DECK_COUNT; |
---|
| | |
---|
| | public class BotIntelligence implements IBotBehavior { |
---|
| | |
---|
| | BotIntelligence(){ |
---|
| | public BotIntelligence(){ |
---|
| | |
---|
| | } |
---|
| | /** |
---|
| | 未確定の数字を列挙する |
---|
| |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * 相手の手札に対して、候補となる数字を割り当てる |
---|
| | * @param iAttack |
---|
| | * @return 候補のリスト |
---|
| | */ |
---|
| | void assignCandidateNumberEachHand(IAttack iAttack){ |
---|
| | List<int[]> assignCandidateNumberEachHand(IAttack iAttack){ |
---|
| | var opponentsHands=iAttack.getOpponentHands(); |
---|
| | var targetList=new ArrayList<>(); |
---|
| | var result=new ArrayList<int[]>(); |
---|
| | |
---|
| | for(var card:opponentsHands){//ユーザーの手札を左から見ていく |
---|
| | var index=opponentsHands.indexOf(card);//左からindex番目に |
---|
| | var candidateList = calculateCandidate(iAttack);//確認するカード |
---|
| |
---|
| | |
---|
| | if(card.getValue()) { |
---|
| | candidateList.clear(); |
---|
| | }else{ //裏の場合 |
---|
| | |
---|
| | |
---|
| | //そのカードから右隣のカードを確認していく |
---|
| | for(int i=0;i<opponentsHands.size()-index-1;i++){ |
---|
| | //今確認していっているカード |
---|
| |
---|
| | var s=(card.getValue()?"+":"-")+card.getKey()+":["; |
---|
| | for (var i:candidateList)s+=i+" "; |
---|
| | s+="]\n"; |
---|
| | System.out.println(s); |
---|
| | result.add(candidateList.stream().mapToInt(x -> x).toArray()); |
---|
| | } |
---|
| | return result; |
---|
| | } |
---|
| | |
---|
| | //公開されていないカードのインデックスを選ぶ(カードにかかれている番号ではない) |
---|
| | @Override |
---|
| | public int selectAttacker(IAttack iAttack) { |
---|
| | var botsHands = iAttack.getMyHands(); |
---|
| | var botHands = iAttack.getMyHands(); |
---|
| | |
---|
| | for(var i:botsHands){ |
---|
| | if(!i.getValue())return botsHands.indexOf(i); |
---|
| | for(var i:botHands){//小さいものから選択 |
---|
| | if(!i.getValue())return botHands.indexOf(i); |
---|
| | } |
---|
| | return 0; |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public int selectTarget(IAttack iAttack) { |
---|
| | |
---|
| | return 0; |
---|
| | var candidate= assignCandidateNumberEachHand(iAttack); |
---|
| | int result=0; |
---|
| | int min=DECK_COUNT; |
---|
| | for(var i:candidate){ |
---|
| | if(i.length<min&&i.length!=0){ |
---|
| | result=candidate.indexOf(i); |
---|
| | min=i.length; |
---|
| | } |
---|
| | } |
---|
| | return result; |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public int declareNumber(IAttack iAttack) { |
---|
| | var list = new ArrayList<>(); |
---|
| | for(int i=0;i<DECK_COUNT;i++)list.add(i); |
---|
| | return 0; |
---|
| | public int declareNumber(IAttack iAttack, int target) { |
---|
| | var array =assignCandidateNumberEachHand(iAttack).get(target); |
---|
| | return array[new Random().nextInt(array.length)]; |
---|
| | } |
---|
| | |
---|
| | |
---|
| | } |
---|
| | |