Merge branch 'master' of manuel-voegele.de:inf3

This commit is contained in:
Wafa Sadri
2014-06-05 11:50:07 +02:00
6 changed files with 115 additions and 30 deletions

View File

@@ -57,10 +57,13 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="src\GameStrategy.cs" />
<Compile Include="src\IGame.cs" />
<Compile Include="src\Receiver.cs" />
<Compile Include="src\Sender.cs" />
<Compile Include="src\Dragon.cs" />
<Compile Include="src\Map.cs" />
<Compile Include="src\Skirmish.cs" />
<Compile Include="src\Tile.cs" />
<Compile Include="src\Entity.cs" />
<Compile Include="src\Player.cs" />

View File

@@ -2,9 +2,9 @@
namespace WorldOfPeacecraft
{
public enum Decision
{
DRAGON, STAGHUNT, SKIRMISH
}
public enum Decision
{
FIGHT, REST, STAG, BUNNY, SWORD, ALCHEMY, MAGIC
}
}

View File

@@ -3,40 +3,44 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace inf3.src
namespace WorldOfPeacecraft
{
class GameStrategy
class GameStrategy : IGame
{
// 0 = defect, 1 = cooperate
int opponentLastMove;
bool opDefected = false;
Decision cooperate;
Decision defect;
int counter = 0;
public GameStrategy(int opLM)
public GameStrategy(Decision cooperate, Decision defect)
{
opponentLastMove = opLM;
this.cooperate = cooperate;
this.defect = defect;
}
public int nextMove()
public Decision getFirstMove()
{
if (opponentLastMove != 0)
return cooperate;
}
public Decision nextMove(Decision opLM)
{
if (opLM == cooperate && counter == 0)
{
return opponentLastMove;
return cooperate;
}
else
{
opDefected = true;
counter++;
if (counter < 10)
{
return 0;
return defect;
}
else
{
counter = 0;
opDefected = false;
return 0;
return defect;
}
}

13
src/IGame.cs Normal file
View File

@@ -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);
}
}

View File

@@ -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 <string> 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:

41
src/Skirmish.cs Normal file
View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WorldOfPeacecraft
{
class Skirmish : IGame
{
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;
}
}
}