aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GameController/.gitignore74
-rw-r--r--GameController/build.xml38
-rw-r--r--GameController/src/nl/camilstaps/botleagues/Contestant.java134
-rw-r--r--GameController/src/nl/camilstaps/botleagues/GameController.java106
-rw-r--r--GameController/src/nl/camilstaps/botleagues/roundbasedgame/Move.java5
-rw-r--r--GameController/src/nl/camilstaps/botleagues/roundbasedgame/RoundBasedGameController.java21
6 files changed, 0 insertions, 378 deletions
diff --git a/GameController/.gitignore b/GameController/.gitignore
deleted file mode 100644
index 5bda502..0000000
--- a/GameController/.gitignore
+++ /dev/null
@@ -1,74 +0,0 @@
-# Source: http://www.bmchild.com/2012/06/git-ignore-for-java-eclipse-project.html
-
-# Directories #
-/build/
-/bin/
-/dist/
-target/
-
-# OS Files #
-.DS_Store
-
-*.class
-
-# Package Files #
-*.jar
-*.war
-*.ear
-*.db
-
-######################
-# Windows
-######################
-
-# Windows image file caches
-Thumbs.db
-
-# Folder config file
-Desktop.ini
-
-######################
-# OSX
-######################
-
-.DS_Store
-.svn
-
-# Thumbnails
-._*
-
-# Files that might appear on external disk
-.Spotlight-V100
-.Trashes
-
-
-######################
-# Eclipse
-######################
-
-*.pydevproject
-.project
-.metadata
-bin/**
-tmp/**
-tmp/**/*
-*.tmp
-*.bak
-*.swp
-*~.nib
-local.properties
-.classpath
-.settings/
-.loadpath
-/src/main/resources/rebel.xml
-# External tool builders
-.externalToolBuilders/
-
-# Locally stored "Eclipse launch configurations"
-*.launch
-
-# CDT-specific
-.cproject
-
-# PDT-specific
-.buildpath
diff --git a/GameController/build.xml b/GameController/build.xml
deleted file mode 100644
index 31b3d59..0000000
--- a/GameController/build.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<project name="GameController" default="dist" basedir=".">
- <description>
- Controls a Botleagues game
- </description>
- <!-- set global properties for this build -->
- <property name="src" location="src"/>
- <property name="build" location="bin"/>
- <property name="dist" location="dist"/>
-
- <target name="init">
- <!-- Create the time stamp -->
- <tstamp/>
- <!-- Create the build directory structure used by compile -->
- <mkdir dir="${build}"/>
- </target>
-
- <target name="compile" depends="init"
- description="compile the source " >
- <!-- Compile the java code from ${src} into ${build} -->
- <javac srcdir="${src}" destdir="${build}"/>
- </target>
-
- <target name="dist" depends="compile"
- description="generate the distribution" >
- <!-- Create the distribution directory -->
- <mkdir dir="${dist}/lib"/>
-
- <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
- <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
- </target>
-
- <target name="clean"
- description="clean up" >
- <!-- Delete the ${build} and ${dist} directory trees -->
- <delete dir="${build}"/>
- <delete dir="${dist}"/>
- </target>
-</project>
diff --git a/GameController/src/nl/camilstaps/botleagues/Contestant.java b/GameController/src/nl/camilstaps/botleagues/Contestant.java
deleted file mode 100644
index 570f884..0000000
--- a/GameController/src/nl/camilstaps/botleagues/Contestant.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package nl.camilstaps.botleagues;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-
-import nl.camilstaps.botleagues.exceptions.TimeOutException;
-
-/**
- * A contestant is a process, a unique identifier and has a score.
- *
- * @author Camil Staps <info@camilstaps.nl>
- */
-public class Contestant implements Comparable<Contestant> {
-
- /** The process we're running this on */
- private final Process process;
- /** A unique identifier (can be set in the constructor */
- private final int uid;
- /** The score */
- private int score = 0;
-
- private int index;
-
- /**
- * Create a new contestant with default uid -1
- *
- * @param p
- * the process to link this contestant to
- */
- public Contestant(Process p) {
- process = p;
- this.uid = -1;
- }
-
- /**
- * Create a new contestant with a custom uid
- *
- * @param p
- * the process to link this contestant to
- * @param uid
- * the uid
- */
- public Contestant(Process p, int uid) {
- process = p;
- this.uid = uid;
- }
-
- /**
- * Set a new score
- *
- * @param new_score
- */
- public void setScore(int new_score) {
- score = new_score;
- }
-
- /**
- * Get the current score
- *
- * @return
- */
- public int getScore() {
- return score;
- }
-
- public int getUID() {
- return uid;
- }
-
- public int getIndex() {
- return index;
- }
-
- public void setIndex(int index) {
- this.index = index;
- }
- public void write(String text) {
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
- process.getOutputStream()));
-
- try {
- writer.write(text);
- writer.flush();
- } catch (IOException e) {
-
- e.printStackTrace();
- }
-
- }
-
- /**
- *
- * @return line
- * @throws TimeOutException
- * @throws IOException
- */
- public String getLine(int timeOut) throws TimeOutException {
- float startTime = System.currentTimeMillis();
- BufferedReader reader = new BufferedReader(new InputStreamReader(
- process.getInputStream()));
- try {
- while (System.currentTimeMillis() - startTime < timeOut
- && !reader.ready()) {
- }
- if (reader.ready())
- return reader.readLine();
- else
- throw new TimeOutException();
- } catch (IOException e) {
-
- e.printStackTrace();
- return "";
- }
-
- }
-
- @Override
- /**
- * We compare contestants based on their score.
- * Like this, we can make a ranking.
- */
- public int compareTo(Contestant arg0) {
- return ((Integer) getScore()).compareTo(arg0.getScore());
- }
-
- @Override
- public String toString() {
- return "Contestant " + uid + " (" + score + "): " + process.toString();
- }
-
-}
diff --git a/GameController/src/nl/camilstaps/botleagues/GameController.java b/GameController/src/nl/camilstaps/botleagues/GameController.java
deleted file mode 100644
index 85ee88f..0000000
--- a/GameController/src/nl/camilstaps/botleagues/GameController.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package nl.camilstaps.botleagues;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * The idea is to let this be a generic class that can be used for any game. It
- * should take care of functions like:
- *
- * * Starting up bots * Sending data to bots * Receiving data from bots
- *
- * @author Camil Staps <info@camilstaps.nl>
- */
-public abstract class GameController {
-
- /** The contestants in this game */
- List<Contestant> contestants = new ArrayList<Contestant>();
- Contestant currentContestant;
-
- /**
- * Add a new contestant
- *
- * Internally, this will create a system call from directory `directory`:
- * java `contestant`
- *
- * So, an example call would be: `directory` = /home/user/my-bot
- * `contestant` = com.example.mybot.MyBot
- *
- * @param directory
- * The directory to work from
- * @param contestant
- * The Java path to start up
- * @throws IOException
- */
- protected void addContestant(File directory, String contestant)
- throws IOException {
- System.err.println("Adding " + contestant + " from "
- + directory.getAbsolutePath());
- ProcessBuilder pb = new ProcessBuilder("java", contestant);
- pb.directory(directory);
- contestants.add(new Contestant(pb.start(), contestants.size()));
- }
-
- public void addBots(String[] bots) {
- int index = 0;
- try {
- for (String bot : bots) {
- int i = bot.lastIndexOf("/");
- addContestant(new File(bot.substring(0, i + 1)),
- bot.substring(i + 1));
- contestants.get(index).setIndex(index);
- index++;
- }
- } catch (IOException e) {
- System.err.println(e.getMessage());
- }
- }
-
- /**
- * Rank the contestants by ascending score
- */
- protected void rank() {
- Collections.sort(contestants);
- }
-
- /**
- * Get the current contestants
- *
- * @return contestants
- */
- public List<Contestant> getContestants() {
- return contestants;
- }
-
- /**
- *
- * @return currentContestant
- */
-
- public Contestant getCurrentContestant() {
- return currentContestant;
- }
-
- public void setCurrentContestant(Contestant contestant) {
- currentContestant = contestant;
- }
-
-
- /**
- * Get the winner of the game (the one with the highest score)
- *
- * NB: the contestants will be sorted after this.
- *
- * @see rank
- *
- * @return the winner of the game
- */
- public Contestant getWinner() {
- rank();
- return contestants.get(contestants.size() - 1);
- }
-
-}
diff --git a/GameController/src/nl/camilstaps/botleagues/roundbasedgame/Move.java b/GameController/src/nl/camilstaps/botleagues/roundbasedgame/Move.java
deleted file mode 100644
index 5e03707..0000000
--- a/GameController/src/nl/camilstaps/botleagues/roundbasedgame/Move.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package nl.camilstaps.botleagues.roundbasedgame;
-
-public class Move {
-
-}
diff --git a/GameController/src/nl/camilstaps/botleagues/roundbasedgame/RoundBasedGameController.java b/GameController/src/nl/camilstaps/botleagues/roundbasedgame/RoundBasedGameController.java
deleted file mode 100644
index 3f61565..0000000
--- a/GameController/src/nl/camilstaps/botleagues/roundbasedgame/RoundBasedGameController.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package nl.camilstaps.botleagues.roundbasedgame;
-
-import nl.camilstaps.botleagues.GameController;
-import nl.camilstaps.botleagues.exceptions.TimeOutException;
-
-public abstract class RoundBasedGameController extends GameController {
-
- public void run() throws TimeOutException {
- while (getCurrentContestant() != null)
-
- nextTurn();
- setNextContestant();
- System.out.println(getWinner());
-
- }
-
- public abstract Move nextTurn() throws TimeOutException;
-
- public abstract void setNextContestant();
-
-}