From e53f2657aacbd9de7160e003c9feff11ff5f2e74 Mon Sep 17 00:00:00 2001 From: Daniel Herrmann Date: Thu, 5 Jun 2014 11:22:06 +0200 Subject: [PATCH 1/3] SpielStrategien mit Interface und Enum --- inf3.csproj | 5 ++++- src/EnumDecision.cs | 2 +- src/GameStrategy.cs | 26 +++++++++++++------------- src/IGame.cs | 13 +++++++++++++ src/Skirmish.cs | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 src/IGame.cs create mode 100644 src/Skirmish.cs diff --git a/inf3.csproj b/inf3.csproj index ecd81fb..22ec838 100644 --- a/inf3.csproj +++ b/inf3.csproj @@ -57,10 +57,13 @@ + + + @@ -138,4 +141,4 @@ - + \ No newline at end of file diff --git a/src/EnumDecision.cs b/src/EnumDecision.cs index 1d71fcd..56b236f 100644 --- a/src/EnumDecision.cs +++ b/src/EnumDecision.cs @@ -4,7 +4,7 @@ namespace WorldOfPeacecraft { public enum Decision { - DRAGON, STAGHUNT, SKIRMISH + FIGHT, REST, STAG, BUNNY, SWORD, ALCHEMY, MAGIC } } diff --git a/src/GameStrategy.cs b/src/GameStrategy.cs index 842915d..93c5058 100644 --- a/src/GameStrategy.cs +++ b/src/GameStrategy.cs @@ -3,40 +3,40 @@ using System.Collections.Generic; using System.Linq; using System.Text; -namespace inf3.src +namespace WorldOfPeacecraft { class GameStrategy { - // 0 = defect, 1 = cooperate - int opponentLastMove; - bool opDefected = false; + int counter = 0; - public GameStrategy(int opLM) + public GameStrategy() { - opponentLastMove = opLM; } - public int nextMove() + public bool getFirstMove() { - if (opponentLastMove != 0) + return true; + } + + public bool nextMove(bool opCooperated) + { + if (opCooperated && counter==0) { - return opponentLastMove; + return true; } else { - opDefected = true; counter++; if (counter < 10) { - return 0; + return false; } else { counter = 0; - opDefected = false; - return 0; + return false; } } diff --git a/src/IGame.cs b/src/IGame.cs new file mode 100644 index 0000000..3c84cd3 --- /dev/null +++ b/src/IGame.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WorldOfPeacecraft +{ + public interface IGame + { + Decision getFirstMove(); + Decision getNextMove(Decision opLM); + } +} diff --git a/src/Skirmish.cs b/src/Skirmish.cs new file mode 100644 index 0000000..1a7be41 --- /dev/null +++ b/src/Skirmish.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WorldOfPeacecraft +{ + class Skirmish + { + Random random = new Random(); + + public Skirmish() + { + } + + public Decision getFirstMove() + { + return getNextMove(); + } + + public Decision getNextMove() + { + int randomNumber = random.Next(0, 2); + Decision bla; + switch (randomNumber) + { + case 0: + bla = Decision.SWORD; + break; + case 1: + bla = Decision.MAGIC; + break; + case 2: + default: + bla = Decision.ALCHEMY; + break; + } + return bla; + } + } +} From 5229f218da340e0e82ab7b5bc7d7d2829670fb1c Mon Sep 17 00:00:00 2001 From: Daniel Herrmann Date: Thu, 5 Jun 2014 11:38:33 +0200 Subject: [PATCH 2/3] GameStrategy allgemein angelegt --- src/EnumDecision.cs | 8 ++++---- src/GameStrategy.cs | 24 ++++++++++++++---------- src/Skirmish.cs | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/EnumDecision.cs b/src/EnumDecision.cs index 56b236f..e4783cd 100644 --- a/src/EnumDecision.cs +++ b/src/EnumDecision.cs @@ -2,9 +2,9 @@ namespace WorldOfPeacecraft { - public enum Decision - { - FIGHT, REST, STAG, BUNNY, SWORD, ALCHEMY, MAGIC - } + public enum Decision + { + FIGHT, REST, STAG, BUNNY, SWORD, ALCHEMY, MAGIC + } } diff --git a/src/GameStrategy.cs b/src/GameStrategy.cs index 93c5058..5507dec 100644 --- a/src/GameStrategy.cs +++ b/src/GameStrategy.cs @@ -5,38 +5,42 @@ using System.Text; namespace WorldOfPeacecraft { - class GameStrategy + class GameStrategy : IGame { - + Decision cooperate; + Decision defect; int counter = 0; - public GameStrategy() + public GameStrategy(Decision cooperate, Decision defect) { + this.cooperate = cooperate; + this.defect = defect; + } - public bool getFirstMove() + public Decision getFirstMove() { - return true; + return cooperate; } - public bool nextMove(bool opCooperated) + public Decision nextMove(Decision opLM) { - if (opCooperated && counter==0) + if (opLM == cooperate && counter == 0) { - return true; + return cooperate; } else { counter++; if (counter < 10) { - return false; + return defect; } else { counter = 0; - return false; + return defect; } } diff --git a/src/Skirmish.cs b/src/Skirmish.cs index 1a7be41..901b323 100644 --- a/src/Skirmish.cs +++ b/src/Skirmish.cs @@ -5,7 +5,7 @@ using System.Text; namespace WorldOfPeacecraft { - class Skirmish + class Skirmish : IGame { Random random = new Random(); From addfbcaa1a578f3ae62c06ccb0c63d7fd9c94611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Thu, 5 Jun 2014 11:47:51 +0200 Subject: [PATCH 3/3] Parser gefixed --- src/Parser.cs | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/Parser.cs b/src/Parser.cs index cda8da3..cc63d68 100644 --- a/src/Parser.cs +++ b/src/Parser.cs @@ -26,10 +26,17 @@ namespace WorldOfPeacecraft public const string ValueY = "y"; public const string ValueCol = "col"; public const string ValueRow = "row"; - public const string EValueDragon = "DRAGON"; - public const string EValueStagunt = "STAGHUNT"; - public const string EValueSkirmish = "SKIRMISH"; + public const string EValueFight = "FIGHT"; + public const string EValueRest = "REST"; + public const string EValueStag = "STAG"; + public const string EValueBunny = "BUNNY"; + public const string EValueSword = "SWORD"; + public const string EValueMagic = "MAGIC"; + public const string EValueAlchemy = "ALCHEMY"; public const string EValueWalkable = "WALKABLE"; + public const string EValueSkirmish = "SKIRMISH"; + public const string EValueStaghunt = "STAGHUNT"; + public const string EValueDragon = "DRAGON"; public const string EValueWall = "WALL"; public const string EValueForest = "FOREST"; public const string EValueWater = "WATER"; @@ -239,7 +246,7 @@ namespace WorldOfPeacecraft Result r = new Result(round, running, delay); } - private void ProcessOpponent(Block oppBlock) + private void ProcessOpponent (Block oppBlock) { int id = oppBlock.GetIntValue (ValueId); int points = oppBlock.GetIntValue (ValuePoints); @@ -247,14 +254,31 @@ namespace WorldOfPeacecraft LinkedList unnamedValue = oppBlock.GetUnnamedValues (); string stringValue = unnamedValue.First.Value; Decision d; - if (stringValue == EValueDragon) - d = Decision.DRAGON; - else if (stringValue == EValueStagunt) - d = Decision.STAGHUNT; - else if (stringValue == EValueSkirmish) - d = Decision.SKIRMISH; - else + switch (stringValue) { + case EValueAlchemy: + d = Decision.ALCHEMY; + break; + case EValueBunny: + d = Decision.BUNNY; + break; + case EValueFight: + d = Decision.FIGHT; + break; + case EValueMagic: + d = Decision.MAGIC; + break; + case EValueRest: + d = Decision.REST; + break; + case EValueStag: + d = Decision.STAG; + break; + case EValueSword: + d = Decision.SWORD; + break; + default: throw new ParsingException("Wrong param"); // TODO Better message + } Opponent o = new Opponent (id, points, total, d); } @@ -275,7 +299,7 @@ namespace WorldOfPeacecraft case EValueDragon: type = "Dragon"; break; - case EValueStagunt: + case EValueStaghunt: type = "Staghunt"; break; case EValueSkirmish: