From 47bf19036e049787fa7742f5ff72a08a0c9e887c Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Fri, 17 Jun 2011 22:12:41 +0200 Subject: Use new AI for computer players git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@448 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/control/turn/AIControlTest.java | 115 ++++++++++++++++++++ test/jrummikub/control/turn/BaseAIControlTest.java | 120 --------------------- 2 files changed, 115 insertions(+), 120 deletions(-) create mode 100644 test/jrummikub/control/turn/AIControlTest.java delete mode 100644 test/jrummikub/control/turn/BaseAIControlTest.java (limited to 'test') diff --git a/test/jrummikub/control/turn/AIControlTest.java b/test/jrummikub/control/turn/AIControlTest.java new file mode 100644 index 0000000..6f7bf6f --- /dev/null +++ b/test/jrummikub/control/turn/AIControlTest.java @@ -0,0 +1,115 @@ +package jrummikub.control.turn; + +import static org.junit.Assert.*; + +import java.awt.Color; + +import jrummikub.model.GameSettings; +import jrummikub.model.IHand; +import jrummikub.model.IPlayer; +import jrummikub.model.ITable; +import jrummikub.model.Player; +import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; +import jrummikub.model.Position; +import jrummikub.model.Stone; +import jrummikub.model.StoneColor; +import jrummikub.model.Table; +import jrummikub.util.IListener; +import jrummikub.view.MockView; + +import org.junit.Before; +import org.junit.Test; + +/** */ +public class AIControlTest { + ITurnControl aiControl; + + GameSettings gameSettings; + PlayerSettings playerSettings; + IPlayer player; + ITable table; + MockView view; + + boolean turnEnded; + boolean redealt; + + /** */ + @Before + public void setUp() { + aiControl = TurnControlFactory.getFactory(Type.COMPUTER).create(); + ((AIControl)aiControl).useBackgroundThread = false; + gameSettings = new GameSettings(); + playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY); + player = new Player(playerSettings); + table = new Table(gameSettings); + view = new MockView(); + turnEnded = false; + redealt = false; + + aiControl.getEndOfTurnEvent().add(new IListener() { + + @Override + public void handle() { + turnEnded = true; + } + + }); + + aiControl.getRedealEvent().add(new IListener() { + + @Override + public void handle() { + redealt = true; + } + + }); + + IHand hand = player.getHand(); + hand.drop(new Stone(11, StoneColor.RED), new Position(0, 0)); + hand.drop(new Stone(12, StoneColor.RED), new Position(0, 0)); + hand.drop(new Stone(13, StoneColor.RED), new Position(0, 0)); + } + + /** + * @throws InterruptedException + */ + @Test(timeout = 10000) + public void testTurnZeroNoRedealing() throws InterruptedException { + aiControl.setup(new ITurnControl.TurnInfo(table, player.getHand(), + player.getLaidOut(), TurnMode.MAY_REDEAL), gameSettings, view); + aiControl.startTurn(); + assertTrue(turnEnded); + assertFalse(redealt); + assertEquals(table.getSize(), 0); + } + + /** + * @throws InterruptedException + */ + @Test(timeout = 10000) + public void testTurnZeroNotMelding() throws InterruptedException { + aiControl + .setup(new ITurnControl.TurnInfo(table, player.getHand(), + player.getLaidOut(), TurnMode.INSPECT_ONLY), + gameSettings, view); + aiControl.startTurn(); + assertTrue(turnEnded); + assertFalse(redealt); + assertEquals(table.getSize(), 0); + } + + /** + * @throws InterruptedException + */ + @Test(timeout = 10000) + public void testNormalTurnMelding() throws InterruptedException { + aiControl.setup(new ITurnControl.TurnInfo(table, player.getHand(), + player.getLaidOut(), TurnMode.NORMAL_TURN), gameSettings, view); + aiControl.startTurn(); + assertTrue(turnEnded); + assertFalse(redealt); + assertEquals(table.getSize(), 1); + assertEquals(player.getHand().getSize(), 0); + } +} diff --git a/test/jrummikub/control/turn/BaseAIControlTest.java b/test/jrummikub/control/turn/BaseAIControlTest.java deleted file mode 100644 index 51b1f1f..0000000 --- a/test/jrummikub/control/turn/BaseAIControlTest.java +++ /dev/null @@ -1,120 +0,0 @@ -package jrummikub.control.turn; - -import static org.junit.Assert.*; - -import java.awt.Color; - -import jrummikub.model.GameSettings; -import jrummikub.model.IHand; -import jrummikub.model.IPlayer; -import jrummikub.model.ITable; -import jrummikub.model.Player; -import jrummikub.model.PlayerSettings; -import jrummikub.model.PlayerSettings.Type; -import jrummikub.model.Position; -import jrummikub.model.Stone; -import jrummikub.model.StoneColor; -import jrummikub.model.Table; -import jrummikub.util.IListener; -import jrummikub.view.MockView; - -import org.junit.Before; -import org.junit.Test; - -/** */ -public class BaseAIControlTest { - ITurnControl aiControl; - - GameSettings gameSettings; - PlayerSettings playerSettings; - IPlayer player; - ITable table; - MockView view; - - boolean turnEnded; - boolean redealt; - - /** */ - @Before - public void setUp() { - aiControl = TurnControlFactory.getFactory(Type.COMPUTER).create(); - gameSettings = new GameSettings(); - playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY); - player = new Player(playerSettings); - table = new Table(gameSettings); - view = new MockView(); - turnEnded = false; - redealt = false; - - aiControl.getEndOfTurnEvent().add(new IListener() { - - @Override - public void handle() { - turnEnded = true; - } - - }); - - aiControl.getRedealEvent().add(new IListener() { - - @Override - public void handle() { - redealt = true; - } - - }); - - IHand hand = player.getHand(); - hand.drop(new Stone(11, StoneColor.RED), new Position(0, 0)); - hand.drop(new Stone(12, StoneColor.RED), new Position(0, 0)); - hand.drop(new Stone(13, StoneColor.RED), new Position(0, 0)); - } - - /** - * @throws InterruptedException - */ - @Test(timeout = 10000) - public void testTurnZeroRedealing() throws InterruptedException { - aiControl.setup(new ITurnControl.TurnInfo(table, player.getHand(), - player.getLaidOut(), TurnMode.MAY_REDEAL), gameSettings, view); - aiControl.startTurn(); - while (!redealt) { - Thread.sleep(100); - } - assertFalse(turnEnded); - assertEquals(table.getSize(), 0); - } - - /** - * @throws InterruptedException - */ - @Test(timeout = 10000) - public void testTurnZeroNotMelding() throws InterruptedException { - aiControl - .setup(new ITurnControl.TurnInfo(table, player.getHand(), - player.getLaidOut(), TurnMode.INSPECT_ONLY), - gameSettings, view); - aiControl.startTurn(); - while (!turnEnded) { - Thread.sleep(100); - } - assertFalse(redealt); - assertEquals(table.getSize(), 0); - } - - /** - * @throws InterruptedException - */ - @Test(timeout = 10000) - public void testNormalTurnMelding() throws InterruptedException { - aiControl.setup(new ITurnControl.TurnInfo(table, player.getHand(), - player.getLaidOut(), TurnMode.NORMAL_TURN), gameSettings, view); - aiControl.startTurn(); - while (!turnEnded) { - Thread.sleep(100); - } - assertFalse(redealt); - assertEquals(table.getSize(), 1); - assertEquals(player.getHand().getSize(), 0); - } -} -- cgit v1.2.3