Merge branch 'master' of manuel-voegele.de:inf3
This commit is contained in:
@@ -57,10 +57,13 @@
|
|||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="src\GameStrategy.cs" />
|
||||||
|
<Compile Include="src\IGame.cs" />
|
||||||
<Compile Include="src\Receiver.cs" />
|
<Compile Include="src\Receiver.cs" />
|
||||||
<Compile Include="src\Sender.cs" />
|
<Compile Include="src\Sender.cs" />
|
||||||
<Compile Include="src\Dragon.cs" />
|
<Compile Include="src\Dragon.cs" />
|
||||||
<Compile Include="src\Map.cs" />
|
<Compile Include="src\Map.cs" />
|
||||||
|
<Compile Include="src\Skirmish.cs" />
|
||||||
<Compile Include="src\Tile.cs" />
|
<Compile Include="src\Tile.cs" />
|
||||||
<Compile Include="src\Entity.cs" />
|
<Compile Include="src\Entity.cs" />
|
||||||
<Compile Include="src\Player.cs" />
|
<Compile Include="src\Player.cs" />
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace WorldOfPeacecraft
|
namespace WorldOfPeacecraft
|
||||||
{
|
{
|
||||||
public enum Decision
|
public enum Decision
|
||||||
{
|
{
|
||||||
DRAGON, STAGHUNT, SKIRMISH
|
FIGHT, REST, STAG, BUNNY, SWORD, ALCHEMY, MAGIC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,40 +3,44 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace inf3.src
|
namespace WorldOfPeacecraft
|
||||||
{
|
{
|
||||||
class GameStrategy
|
class GameStrategy : IGame
|
||||||
{
|
{
|
||||||
// 0 = defect, 1 = cooperate
|
|
||||||
|
|
||||||
int opponentLastMove;
|
Decision cooperate;
|
||||||
bool opDefected = false;
|
Decision defect;
|
||||||
int counter = 0;
|
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
|
else
|
||||||
{
|
{
|
||||||
opDefected = true;
|
|
||||||
counter++;
|
counter++;
|
||||||
if (counter < 10)
|
if (counter < 10)
|
||||||
{
|
{
|
||||||
return 0;
|
return defect;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
counter = 0;
|
counter = 0;
|
||||||
opDefected = false;
|
return defect;
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/IGame.cs
Normal file
13
src/IGame.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,10 +26,17 @@ namespace WorldOfPeacecraft
|
|||||||
public const string ValueY = "y";
|
public const string ValueY = "y";
|
||||||
public const string ValueCol = "col";
|
public const string ValueCol = "col";
|
||||||
public const string ValueRow = "row";
|
public const string ValueRow = "row";
|
||||||
public const string EValueDragon = "DRAGON";
|
public const string EValueFight = "FIGHT";
|
||||||
public const string EValueStagunt = "STAGHUNT";
|
public const string EValueRest = "REST";
|
||||||
public const string EValueSkirmish = "SKIRMISH";
|
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 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 EValueWall = "WALL";
|
||||||
public const string EValueForest = "FOREST";
|
public const string EValueForest = "FOREST";
|
||||||
public const string EValueWater = "WATER";
|
public const string EValueWater = "WATER";
|
||||||
@@ -239,7 +246,7 @@ namespace WorldOfPeacecraft
|
|||||||
Result r = new Result(round, running, delay);
|
Result r = new Result(round, running, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessOpponent(Block oppBlock)
|
private void ProcessOpponent (Block oppBlock)
|
||||||
{
|
{
|
||||||
int id = oppBlock.GetIntValue (ValueId);
|
int id = oppBlock.GetIntValue (ValueId);
|
||||||
int points = oppBlock.GetIntValue (ValuePoints);
|
int points = oppBlock.GetIntValue (ValuePoints);
|
||||||
@@ -247,14 +254,31 @@ namespace WorldOfPeacecraft
|
|||||||
LinkedList <string> unnamedValue = oppBlock.GetUnnamedValues ();
|
LinkedList <string> unnamedValue = oppBlock.GetUnnamedValues ();
|
||||||
string stringValue = unnamedValue.First.Value;
|
string stringValue = unnamedValue.First.Value;
|
||||||
Decision d;
|
Decision d;
|
||||||
if (stringValue == EValueDragon)
|
switch (stringValue) {
|
||||||
d = Decision.DRAGON;
|
case EValueAlchemy:
|
||||||
else if (stringValue == EValueStagunt)
|
d = Decision.ALCHEMY;
|
||||||
d = Decision.STAGHUNT;
|
break;
|
||||||
else if (stringValue == EValueSkirmish)
|
case EValueBunny:
|
||||||
d = Decision.SKIRMISH;
|
d = Decision.BUNNY;
|
||||||
else
|
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
|
throw new ParsingException("Wrong param"); // TODO Better message
|
||||||
|
}
|
||||||
Opponent o = new Opponent (id, points, total, d);
|
Opponent o = new Opponent (id, points, total, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +299,7 @@ namespace WorldOfPeacecraft
|
|||||||
case EValueDragon:
|
case EValueDragon:
|
||||||
type = "Dragon";
|
type = "Dragon";
|
||||||
break;
|
break;
|
||||||
case EValueStagunt:
|
case EValueStaghunt:
|
||||||
type = "Staghunt";
|
type = "Staghunt";
|
||||||
break;
|
break;
|
||||||
case EValueSkirmish:
|
case EValueSkirmish:
|
||||||
|
|||||||
41
src/Skirmish.cs
Normal file
41
src/Skirmish.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user