From e540f649cb51984ffda38d6ec7d650603fbacda1 Mon Sep 17 00:00:00 2001 From: The Vu Date: Sat, 21 Feb 2015 15:43:18 +0100 Subject: deleted turn-class --- .../src/nl/camilstaps/botleagues/MyGame.java | 89 --------------------- .../nl/camilstaps/botleagues/MyGameController.java | 93 ++++++++++++++++++++++ 2 files changed, 93 insertions(+), 89 deletions(-) delete mode 100644 GuessANumber/Controller/src/nl/camilstaps/botleagues/MyGame.java create mode 100644 GuessANumber/Controller/src/nl/camilstaps/botleagues/MyGameController.java (limited to 'GuessANumber/Controller') diff --git a/GuessANumber/Controller/src/nl/camilstaps/botleagues/MyGame.java b/GuessANumber/Controller/src/nl/camilstaps/botleagues/MyGame.java deleted file mode 100644 index ba26a97..0000000 --- a/GuessANumber/Controller/src/nl/camilstaps/botleagues/MyGame.java +++ /dev/null @@ -1,89 +0,0 @@ -package nl.camilstaps.botleagues; - -import java.util.List; -import java.util.Random; - -import nl.camilstaps.botleagues.roundbasedgame.RoundBasedGameController; - -/** - * The idea is to let this be an example of a game controller. Initially, we can - * do all the work here. Ideally, later, we'll split that up in an abstract part - * (in GameController) and an extension. - * - * @author Camil Staps - */ -public class MyGame extends RoundBasedGameController { - MyTurn turn = new MyTurn(); - private int numberToGuess; - - /** - * Start the game. In the command line arguments should be descriptions of - * the bots, as described in @see MyGame() - * - * @param args - * command line arguments - */ - public static void main(String[] args) { - @SuppressWarnings("unused") - MyGame game = new MyGame(args); - } - - /** - * Setup a game, adds bots and runs it - * - * @param bots - * descriptions of the bots (array of strings). For example: - * - * /home/user/my-bot/com.example.mybot.MyBot - * - * Internally, this will cd to /home/user/my-bot and then execute - * - * java com.example.mybot.MyBot - * - * Arbitrarily many bots can be added - */ - public MyGame(String[] bots) { - addBots(bots); - - Random rand = new Random(); - int n = rand.nextInt(100) + 1; - numberToGuess = n; - - run(); - } - - /** - * - * @return next Contestant - */ - @Override - public Contestant getNextContestant() { - Contestant currentContestant = getCurrentContestant(); - List contestants = getContestants(); - if (currentContestant == null) { - Random rand = new Random(); - int n = rand.nextInt(contestants.size() - 1); - currentContestant = contestants.get(n); - return contestants.get(n + 1); - } - for (int i = 0; i < contestants.size(); i++) { - if (contestants.get(i).getUID() == currentContestant.getUID()) - if (contestants.size() != i + 1) - return contestants.get(i + 1); - else - return null; - } - return null; - - } - - @Override - public MyTurn getTurn() { - return turn; - } - - public int getNumberToGuess() { - return numberToGuess; - } - -} diff --git a/GuessANumber/Controller/src/nl/camilstaps/botleagues/MyGameController.java b/GuessANumber/Controller/src/nl/camilstaps/botleagues/MyGameController.java new file mode 100644 index 0000000..1ba7658 --- /dev/null +++ b/GuessANumber/Controller/src/nl/camilstaps/botleagues/MyGameController.java @@ -0,0 +1,93 @@ +package nl.camilstaps.botleagues; + +import java.util.List; +import java.util.Random; + +import nl.camilstaps.botleagues.roundbasedgame.RoundBasedGameController; + +/** + * The idea is to let this be an example of a game controller. Initially, we can + * do all the work here. Ideally, later, we'll split that up in an abstract part + * (in GameController) and an extension. + * + * @author Camil Staps + */ +public class MyGameController extends RoundBasedGameController { + private int numberToGuess; + + /** + * Start the game. In the command line arguments should be descriptions of + * the bots, as described in @see MyGame() + * + * @param args + * command line arguments + */ + public static void main(String[] args) { + @SuppressWarnings("unused") + MyGameController game = new MyGameController(args); + } + + /** + * Setup a game, adds bots and runs it + * + * @param bots + * descriptions of the bots (array of strings). For example: + * + * /home/user/my-bot/com.example.mybot.MyBot + * + * Internally, this will cd to /home/user/my-bot and then execute + * + * java com.example.mybot.MyBot + * + * Arbitrarily many bots can be added + */ + public MyGameController(String[] bots) { + addBots(bots); + + Random rand = new Random(); + int n = rand.nextInt(100) + 1; + numberToGuess = n; + + run(); + } + + /** + * + * @return next Contestant + */ + @Override + public Contestant getNextContestant() { + Contestant currentContestant = getCurrentContestant(); + List contestants = getContestants(); + if (currentContestant == null) { + Random rand = new Random(); + int n = rand.nextInt(contestants.size()); + currentContestant = contestants.get(n); + return contestants.get(n + 1); + } + for (int i = 0; i < contestants.size(); i++) { + if (contestants.get(i).getUID() == currentContestant.getUID()) + if (contestants.size() != i + 1) + return contestants.get(i + 1); + else + return null; + } + return null; + + } + + public int getNumberToGuess() { + return numberToGuess; + } + + @Override + public MyMove nextTurn(Contestant nextContestant) { + + nextContestant.write("Guess\n"); + int guess = Integer.parseInt(nextContestant.getLine()); + MyMove currentMove = new MyMove(guess); + return currentMove; + + } + +} -- cgit v1.2.3