From 244108a4423c9b85e4e6471fd6a9d0acaf6c0ea5 Mon Sep 17 00:00:00 2001 From: Markus Himmel Date: Sat, 27 Aug 2016 15:27:33 +0200 Subject: [PATCH] Show coordinates, determine draws --- Morris/ConsoleInteraction.cs | 10 +++++++--- Morris/GameState.cs | 10 +++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Morris/ConsoleInteraction.cs b/Morris/ConsoleInteraction.cs index 1287429..208945c 100644 --- a/Morris/ConsoleInteraction.cs +++ b/Morris/ConsoleInteraction.cs @@ -79,11 +79,15 @@ namespace Morris } } - // Spielfeld tatsächlich ausgeben - foreach (var row in field) + // Spielfeld mit Koordinaten ausgeben + for (int i = 0; i < 13; i++) { - Console.WriteLine(new string(row)); + Console.Write(i % 2 == 0 ? (char)('0' + 7 - i / 2) : ' '); + Console.Write(' '); + Console.WriteLine(new string(field[i])); } + Console.Write(" "); + Console.WriteLine(string.Join(" ", Enumerable.Range('a', 7).Select(x => (char)x))); // Spielstatus mitteilen, falls das Spiel nicht mehr läuft. switch (state.Result) diff --git a/Morris/GameState.cs b/Morris/GameState.cs index 7f2c7f5..497052b 100644 --- a/Morris/GameState.cs +++ b/Morris/GameState.cs @@ -22,6 +22,8 @@ namespace Morris public Player NextToMove { get; private set; } public GameResult Result { get; private set; } + private List history = new List(); + private Dictionary playerPhase; private Dictionary stonesPlaced; private Dictionary currentStones; @@ -293,6 +295,8 @@ namespace Morris // Weiteres Error Checking ist nicht notwendig, da dieses in IsValidMove vorgenommen wurde + history.Add((Occupation[])Board.Clone()); + // ggf. wegbewegter Stein if (move.From.HasValue) Board[move.From.Value] = Occupation.Free; @@ -306,11 +310,15 @@ namespace Morris // Hinbewegter Stein Board[move.To] = (Occupation)NextToMove; + // Wiederholte Stellung + if (!playerPhase.Values.Contains(Phase.Placing) && history.Any(pastBoard => Board.SequenceEqual(pastBoard))) + Result = GameResult.Draw; + // ggf. entfernter Stein if (move.Remove.HasValue) { Board[move.Remove.Value] = Occupation.Free; - if (--currentStones[NextToMove.Opponent()] == FLYING_MAX) + if (playerPhase[NextToMove.Opponent()] == Phase.Moving & --currentStones[NextToMove.Opponent()] == FLYING_MAX) playerPhase[NextToMove.Opponent()] = Phase.Flying; }