public static GameStates GetGameState(Fields.Field field, Player.Player currentPlayer) { if (currentPlayer == null) { return(GameStates.Laufend); } foreach (char symbol in GetAllPlayerSymbols(field)) { if (WinChecker.Pruefe(symbol, field)) { if (currentPlayer.Symbol == symbol) { return(GameStates.Gewonnen); } else { return(GameStates.Verloren); } } } if (!FieldHelper.HasEmptyFields(field)) { return(GameStates.Unentschieden); } return(GameStates.Laufend); }
public static string GetString(Fields.Field field) { string ret = null; for (int i = 0; i < field.Length; i++) { ret += field.GetField(i); } return(ret); }
public static int GetRandomZug(Fields.Field field) { int zug = -1; do { zug = _rnd.Next(0, field.Length); } while (!field.IsFieldEmpty(zug)); return(zug); }
public static bool HasEmptyFields(Fields.Field field) { for (int i = 0; i < field.Length; i++) { if (field.IsFieldEmpty(i)) { return(true); } } return(false); }
public static Fields.Field GetRandomField(Fields.Field field) { char player = '2'; for (int i = 0; i < field.Length; i++) { field.SetField(GetRandomZug(field), player); player = Player.Player.PlayerChange(player); } return(field); }
public static List <char> GetAllPlayerSymbols(Fields.Field field) { List <char> ret = new List <char>(); for (int i = 0; i < field.Length; i++) { if (!ret.Contains(field.GetField(i)) && !String.IsNullOrEmpty(field.GetField(i).ToString().Trim())) { ret.Add(field.GetField(i)); } } return(ret); }
public static int GetFullFields(Fields.Field field) { int count = 0; for (int i = 0; i < field.Length; i++) { if (!field.IsFieldEmpty(i)) { count++; } } return(count); }
/// <summary> /// /// </summary> /// <param name="field">Das Spielfeld</param> /// <param name="dir">Die Richtung, in die überprüft werden soll.</param> /// <param name="player"></param> /// <param name="from">Der inklusive untere Vector der Startposition.</param> /// <returns></returns> private static int DoCheck(Fields.Field field, Directories dir, char player, Vector2i from) { int counter = 0; for (int a = 0; a < GewinnBedingung; a++) { if (field.GetField(from) == player) { counter++; } else { break; } from = NextField(dir, from); } return(counter); }
public static bool Pruefe(char player, Fields.Field field) { if (GewinnBedingung == -1) { GewinnBedingung = field.Width > field.Height ? field.Height : field.Width; } List <Fields.FieldRegion> panels = field.FieldRegions; foreach (Fields.FieldRegion region in panels) { if (region.Count <char>(player) == GewinnBedingung) { return(true); } } return(false); }