/
SampleVillager.java
113 lines (102 loc) · 3.59 KB
/
SampleVillager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* SampleVillager.java
*
* Copyright (c) 2018 人狼知能プロジェクト
*/
package org.aiwolf.sample.player;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.aiwolf.client.lib.Content;
import org.aiwolf.common.data.Agent;
import org.aiwolf.common.data.Judge;
import org.aiwolf.common.data.Role;
import org.aiwolf.common.data.Species;
import org.aiwolf.common.data.Vote;
/**
* 村人役エージェントクラス
*
* @author otsuki
*/
public final class SampleVillager extends SampleBasePlayer {
@Override
void chooseVoteCandidate() {
List<Agent> wolfCandidates = new ArrayList<>();
// 村人目線での人狼候補決定アルゴリズム
for (Judge divination : divinationList) {
// まず占い結果から人狼候補を見つける
Agent he = divination.getAgent();
Species result = divination.getResult();
if (!isAlive(he) || wolfCandidates.contains(he) || result == Species.HUMAN) {
continue;
}
Agent target = divination.getTarget();
if (target == me) {
// 自分を人狼と判定した自称占い師は人狼か裏切り者なので投票先候補に追加
wolfCandidates.add(he);
Content hisDivination = dayContent(me, divination.getDay(), divinedContent(he, target, result));
Content reason = andContent(me, coContent(me, me, Role.VILLAGER), hisDivination);
estimateReasonMap.put(new Estimate(me, he, reason, Role.WEREWOLF, Role.POSSESSED));
} else if (isKilled(target)) {
// 殺されたエージェントを人狼と判定した自称占い師は人狼か裏切り者なので投票先候補に追加
wolfCandidates.add(he);
Content hisDivination = dayContent(me, divination.getDay(), divinedContent(he, target, result));
Content reason = andContent(me, attackedContent(Content.ANY, target), hisDivination);
estimateReasonMap.put(new Estimate(me, he, reason, Role.WEREWOLF, Role.POSSESSED));
}
}
if (!wolfCandidates.isEmpty()) {
// 見つかった場合
if (!wolfCandidates.contains(voteCandidate)) {
// 新しい投票先の場合,推測発言をする
voteCandidate = randomSelect(wolfCandidates);
Estimate estimate = estimateReasonMap.getEstimate(me, voteCandidate);
if (estimate != null) {
enqueueTalk(estimate.toContent());
voteReasonMap.put(me, voteCandidate, estimate.getEstimateContent());
}
}
} else {
// 見つからなかった場合
if (!isRevote) {
// 初回投票では投票リクエストに応じた投票
if (voteRequestCounter.isChanged()) {
List<Agent> candidates = voteRequestCounter.getRequestMap().values().stream()
.collect(Collectors.toList());
voteCandidate = randomSelect(candidates);
} else if (!isAlive(voteCandidate)) {
voteCandidate = randomSelect(aliveOthers);
}
} else {
// 再投票の場合は自分以外の前回最多得票に入れる
VoteReasonMap vrmap = new VoteReasonMap();
for (Vote v : currentGameInfo.getLatestVoteList()) {
vrmap.put(v.getAgent(), v.getTarget(), null);
}
List<Agent> candidates = vrmap.getOrderedList();
candidates.remove(me);
if (candidates.isEmpty()) {
voteCandidate = randomSelect(aliveOthers);
} else {
voteCandidate = candidates.get(0);
}
}
}
}
@Override
public String whisper() {
throw new UnsupportedOperationException();
}
@Override
public Agent attack() {
throw new UnsupportedOperationException();
}
@Override
public Agent divine() {
throw new UnsupportedOperationException();
}
@Override
public Agent guard() {
throw new UnsupportedOperationException();
}
}