SpielStrategien mit Interface und Enum
This commit is contained in:
@@ -4,7 +4,7 @@ namespace WorldOfPeacecraft
|
||||
{
|
||||
public enum Decision
|
||||
{
|
||||
DRAGON, STAGHUNT, SKIRMISH
|
||||
FIGHT, REST, STAG, BUNNY, SWORD, ALCHEMY, MAGIC
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
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