Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 66 additions & 59 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="WereWolf">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../../usr/share/eclipse"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="WereWolf.classpath">
<pathelement location="bin"/>
<pathelement location="lib/pircbot.jar"/>
<pathelement location="lib/guava-11.0.1.jar"/>
<pathelement location="lib/java-getopt-1.0.13.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="WereWolf.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="WolfBot">
<java classname="no.arcticdrakefox.wolfbot.WolfBot" failonerror="true" fork="yes">
<classpath refid="WereWolf.classpath"/>
</java>
</target>
</project>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="WereWolf">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../../usr/share/eclipse"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="WereWolf.classpath">
<pathelement location="bin"/>
<pathelement location="lib/pircbot.jar"/>
<pathelement location="lib/guava-11.0.1.jar"/>
<pathelement location="lib/java-getopt-1.0.13.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="WereWolf.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="WolfBot2">
<java classname="no.arcticdrakefox.wolfbot.WolfBot" failonerror="true" fork="yes">
<arg line="-c#Wolfbot2 -nWolfbot2"/>
<classpath refid="WereWolf.classpath"/>
</java>
</target>
<target name="WolfBot">
<java classname="no.arcticdrakefox.wolfbot.WolfBot" failonerror="true" fork="yes">
<arg line="-sirc.cs.kent.ac.uk"/>
<classpath refid="WereWolf.classpath"/>
</java>
</target>
</project>
103 changes: 79 additions & 24 deletions src/no/arcticdrakefox/wolfbot/management/GameCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

public class GameCore {
public static void lynchVote(String senderS, String targetS, WolfBotModel data, MessageType type) {
Expand Down Expand Up @@ -54,6 +55,8 @@ public static void lynchVote(String senderS, String targetS, WolfBotModel data,
endDay(true, data);
}



public static void drop(String name, String sender, WolfBotModel data){
if (data.getState() == State.None || data.getState() == State.Starting)
{
Expand Down Expand Up @@ -234,7 +237,7 @@ public static void startNight(WolfBotModel data) {
public static void endNight(WolfBotModel data) {
// Kill the timer first:
endNightTimer.cancel(); // Javadoc says this is safe when called by a TimerTask. We'll see.
killWolfVote(data);
calculateNightKills(data);
data.getWolfBot().sendNightEndMessages();
checkDead(data);
if (!checkVictory(data))
Expand Down Expand Up @@ -304,36 +307,88 @@ public int compare(Player o1, Player o2)
}
}

public static void killWolfVote(WolfBotModel data) {
Player wolfVote = data.getPlayers().getVote(true);
if (wolfVote != null) {
Player baner = data.getPlayers().getPlayerTargeting(wolfVote,
Role.baner);
if (baner != null) {
wolfVote = null;
if (baner.getVote().equals(baner)) {
data.getWolfBot().sendIrcMessage(
baner.getName(),
Messages.getString("GameCore.vigilanti.multualTarget")); //$NON-NLS-1$
} else {
data.getWolfBot().sendIrcMessage(
baner.getName(), Messages.getString("GameCore.vigilanti.killWolf", //$NON-NLS-1$
baner.getVote()));


/**
*
* @param data
*/
public static void calculateNightKills(WolfBotModel data) {
Collection<Pair<Player, String>> kills = Sets.newHashSet();


// Wolf stuff.
{
Player wolfVote = data.getPlayers().getVote(true);
String deathMessage;
if (WolfBotModel.getInstance().getSilentMode()) {
deathMessage = Messages.getString("GameCore.wolfKill.noReveal", //$NON-NLS-1$
bold(wolfVote.getName()));
} else {
deathMessage = Messages.getString("GameCore.wolfKill.reveal", //$NON-NLS-1$
bold(wolfVote.getName()), wolfVote.getRole().toStringColor());
}

kills.add(new Pair<Player, String>(wolfVote,deathMessage));
}

List<Player> livingPlayers = data.getPlayers().getLivingPlayers();

ret_k:
for (Player p : livingPlayers) {
Pair<Player, String> kill = p.kill(data.getState());
if (kill != null) {
for (Pair<Player, String > k : kills) {
if (k.fst().equals(kill.fst())) continue ret_k;
}
kills.add(kill);
}
}
if (wolfVote == null
|| data.getPlayers().getPlayerTargeting(wolfVote, Role.baner) != null) {

for (Player p : livingPlayers) {
p.save(data.getState(), kills);
}


if (kills.isEmpty()) {
data.getWolfBot().sendIrcMessage(data.getChannel(),
Messages.getString("GameCore.noWolfKill")); //$NON-NLS-1$
} else {
if (WolfBotModel.getInstance().getSilentMode()) {
wolfVote.die(Messages.getString("GameCore.wolfKill.noReveal", //$NON-NLS-1$
bold(wolfVote.getName())));
} else {
wolfVote.die(Messages.getString("GameCore.wolfKill.reveal", //$NON-NLS-1$
bold(wolfVote.getName()), wolfVote.getRole().toStringColor()));
for(Pair<Player, String> k: kills) {
k.fst().die(k.snd());
}
}


//
// if (wolfVote != ns) {
// Player baner = data.getPlayers().getPlayerTargeting(wolfVote,
// Role.baner);
// if (baner != null) {
// wolfVote = null;
// if (baner.getVote().equals(baner)) {
// data.getWolfBot().sendIrcMessage(
// baner.getName(),
// Messages.getString("GameCore.vigilanti.multualTarget")); //$NON-NLS-1$
// } else {
// data.getWolfBot().sendIrcMessage(
// baner.getName(), Messages.getString("GameCore.vigilanti.killWolf", //$NON-NLS-1$
// baner.getVote()));
// }
// }
// }
// if (wolfVote == null
// || data.getPlayers().getPlayerTargeting(wolfVote, Role.baner) != null) {
// data.getWolfBot().sendIrcMessage(data.getChannel(),
// Messages.getString("GameCore.noWolfKill")); //$NON-NLS-1$
// } else {
// if (WolfBotModel.getInstance().getSilentMode()) {
// wolfVote.die(Messages.getString("GameCore.wolfKill.noReveal", //$NON-NLS-1$
// bold(wolfVote.getName())));
// } else {
// wolfVote.die(Messages.getString("GameCore.wolfKill.reveal", //$NON-NLS-1$
// bold(wolfVote.getName()), wolfVote.getRole().toStringColor()));
// }
// }
}
}
2 changes: 1 addition & 1 deletion src/no/arcticdrakefox/wolfbot/management/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static String getString(String key, Object... args) {
try {
return MessageFormat.format(RESOURCE_BUNDLE.getString(key), args);
} catch (MissingResourceException ex) {
return "Missing String in properties file.";
return "Missing String in properties file. \"" + key + "\" not found.";
}
}
}
Expand Down
51 changes: 51 additions & 0 deletions src/no/arcticdrakefox/wolfbot/management/Pair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package no.arcticdrakefox.wolfbot.management;

public class Pair<T1,T2> {
T1 a;
T2 b;

public Pair(T1 a, T2 b) {
super();
this.a = a;
this.b = b;
}

public T1 fst() {
return a;
}

public T2 snd() {
return b;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((a == null) ? 0 : a.hashCode());
result = prime * result + ((b == null) ? 0 : b.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pair<?,?> other = (Pair<?,?>) obj;
if (a == null) {
if (other.a != null)
return false;
} else if (!a.equals(other.a))
return false;
if (b == null) {
if (other.b != null)
return false;
} else if (!b.equals(other.b))
return false;
return true;
}
}
15 changes: 15 additions & 0 deletions src/no/arcticdrakefox/wolfbot/management/Player.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package no.arcticdrakefox.wolfbot.management;

import java.util.Collection;

import no.arcticdrakefox.wolfbot.model.Role;
import no.arcticdrakefox.wolfbot.model.State;

public abstract class Player {

Expand Down Expand Up @@ -55,4 +58,16 @@ protected final String targetNotFound(String name){
public abstract String nightEnd();

public abstract String helpText();

/**
* Does this player kill someone?
* @param time
* @return
*/
public Pair<Player, String> kill(State time) {
return null;
}

public void save(State time, Collection<Pair<Player, String>> players) { }

}
2 changes: 2 additions & 0 deletions src/no/arcticdrakefox/wolfbot/model/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import no.arcticdrakefox.wolfbot.roles.ApprenticeScry;
import no.arcticdrakefox.wolfbot.roles.AuraScry;
import no.arcticdrakefox.wolfbot.roles.Baner;
import no.arcticdrakefox.wolfbot.roles.BodyGuard;
import no.arcticdrakefox.wolfbot.roles.Devil;
import no.arcticdrakefox.wolfbot.roles.Diseased;
import no.arcticdrakefox.wolfbot.roles.Ghost;
Expand All @@ -24,6 +25,7 @@
import org.jibble.pircbot.Colors;

public enum Role {
bodyguard (BodyGuard.class, Team.Villagers),
villager (Villager.class, Team.Villagers),
wolf (Wolf.class, Team.Wolves),
scry (Scry.class, Team.Villagers),
Expand Down
Loading