public StoneInformation(IStone stone) { Type = stone.GetType().Name; Color = stone.Color.ToString(); Location = $"{stone.Location.X}|{stone.Location.Y}"; MoveCount = stone.MoveCount; }
public override bool TryMove(Location target, Table table, out IStone willEated) { willEated = null; if (CheckMove(target, table) == false) { return(false); } var span = target - Location; // yatay - dikey hareket if (span.XDiff == 0 || span.YDiff == 0) { if (MovementRules.HorizontalOrVerticalCheck(Location, target, table) == false) { return(false); } } // çapraz else { if (MovementRules.DiagonalCheck(Location, target, table) == false) { return(false); } } willEated = table.Stones.GetFromLocation(target); return(true); }
private MovementResult PreMove() { if (MovingStone is King) { return(CheckKingMove()); } else { var targetLocationStone = Session.Table.Stones.GetFromLocation(Target); MovingStone.GhostMove(Target); bool couldMove = true; IStone willEated = null; foreach (var nextPlayerStone in Session.NextPlayer.Stones) { if (nextPlayerStone == targetLocationStone) { continue; } if (nextPlayerStone.TryMove(Session.CurrentPlayer.GetKing().Location, Session.Table, out willEated)) { couldMove = false; break; } } MovingStone.UndoGhost(); return(new MovementResult(couldMove, MovingStone, willEated, Target, couldMove ? "OK" : "Protect your KING!")); } }
private Instruction(IStone stone, Location target, Session session, string rawCommand) { MovingStone = stone; Target = target; Session = session; RawCommand = rawCommand; FromLocation = stone.Location; }
public MovementResult(bool isOk, IStone stone, IStone eated, Location location, string message, bool checkRemoved = false) { IsOK = isOk; Stone = stone; Eated = isOk ? eated : null; Location = location; Message = message; CheckRemoved = checkRemoved; }
public virtual bool Move(Location target, Table table, out IStone eated) { if (TryMove(target, table, out eated)) { Move(target); return(true); } return(false); }
public override bool TryMove(Location target, Table table, out IStone willEated) { willEated = default; if (CheckMove(target, table) == false) { return(false); } //int currentX = Location.X; //int currentY = Location.Y; //var span = target - Location; //for (int i = 1; i <= span.XDiff; i++) //{ // currentX += span.XMovement == MovementDirection.Forward ? 1 : -1; // currentY += span.YMovement == MovementDirection.Forward ? 1 : -1; // var checkLocation = table.GetLocation(currentX, currentY); // if (checkLocation == null) // { // return false; // } // var checkLocationStone = table.Stones.GetFromLocation(checkLocation); // if (checkLocationStone != null) // { // if (i != span.XDiff) // { // // son nokta değil arada taş var // return false; // } // else // { // willEated = checkLocationStone; // break; // } // } //} if (MovementRules.DiagonalCheck(Location, target, table) == false) { return(false); } willEated = table.Stones.GetFromLocation(target); if (willEated == this) { willEated = null; } return(true); }
public override bool TryMove(Location target, Table table, out IStone willEated) { willEated = default; if (CheckMove(target, table) == false) { return(false); } if (MovementRules.HorizontalOrVerticalCheck(Location, target, table) == false) { return(false); } willEated = table.Stones.GetFromLocation(target); return(true); }
public override bool TryMove(Location target, Table table, out IStone willEated) { willEated = default; if (CheckMove(target, table) == false) { return(false); } var targetLocationStone = table.Stones.FirstOrDefault(s => s.Location == target); if (targetLocationStone != null) { willEated = targetLocationStone; } return(true); }
/// <summary> /// Adds the given type of stone to current player. /// </summary> /// <param name="type"> /// <see cref="Type"/> information of stone /// </param> /// <param name="x"> /// The x-coordinate of position of stone /// </param> /// <param name="y"> /// The y-coordinate of position of stone /// </param> /// <returns> /// <see cref="PlayerBuilder"/> /// </returns> /// <exception cref="InvalidOperationException"></exception> public PlayerBuilder AddStone(Type type, int x, int y) { if (type.BaseType == null || type.BaseType != typeof(Stone)) { throw new InvalidOperationException("Type is not Stone type!"); } var stoneCount = _player.Stones.Count(s => s.GetType() == type); if (stoneCount == StoneTypeCountMap[type]) { throw new InvalidOperationException($"Player has already {stoneCount} piece of {type.Name}."); } IStone stone = (IStone)Activator.CreateInstance(type, _player.Color, x, y); _player.AddStone(stone); return(this); }
private void IsCheck(IStone stone) { King king = NextPlayer.GetKing(); if (stone.TryMove(king.Location, Table, out IStone k)) { Check = true; CheckStone = stone; } if (Check) { IsCheckmate(stone); if (Checkmate) { Check = false; } } }
public override bool TryMove(Location target, Table table, out IStone willEated) { willEated = default; if (CheckMove(target, table) == false) { return(false); } var targetLocationStone = table.Stones.GetFromLocation(target); var span = target - Location; // çapraz gidiş if (span.XDiff == span.YDiff) { var result = MovementRules.DiagonalCheck(Location, target, table); if (result == false) { return(result); } if (targetLocationStone != null) { willEated = targetLocationStone; } } // yatay || dikey gidiş if (span.XDiff == 0 || span.YDiff == 0) { var result = MovementRules.HorizontalOrVerticalCheck(Location, target, table); if (result == false) { return(result); } if (targetLocationStone != null) { willEated = targetLocationStone; } } return(true); }
public bool PlaceStone(int Y) { var activePlayer = _players.Where(x => x.IsActive == true).FirstOrDefault(); if (activePlayer == null) { return(false); } foreach (var row in _playField) { if (row[Y].Content == null) { LastStone = new Stone(activePlayer, row[Y]); row[Y].Content = LastStone; SwitchActivePlayer(); return(true); } } return(false); }
private MovementResult CheckKingMove() { MovingStone.GhostMove(Target); bool couldMove = true; IStone willEated = null; IStone eater = null; foreach (var nextPlayerStone in Session.NextPlayer.Stones) { if (nextPlayerStone.TryMove(MovingStone.Location, Session.Table, out willEated)) { couldMove = false; eater = nextPlayerStone; break; } } MovingStone.UndoGhost(); return(new MovementResult(couldMove, MovingStone, willEated, Target, couldMove ? "OK" : $"No way man.. {eater.Name} will kill your King!")); }
public override bool TryMove(Location target, Table table, out IStone willEated) { willEated = default; if (CheckMove(target, table) == false) { return(false); } var span = target - Location; // çapraz hareket if (span.XDiff == 1 && span.YDiff == 1) { var enemyStone = table.Stones.FirstOrDefault(s => s.Location == target); if (enemyStone == null || enemyStone.Player == this.Player) { return(false); } willEated = enemyStone; } return(true); }
private static bool OnDownLayer(IStone stone) { return(stone.GetPositions().Any(p => p.Face == DOWN)); }
public bool CouldRun(Table table, Location checkLocation) { IStone _s = null; bool leftOpen = false; bool leftTopOpen = false; bool topOpen = false; bool rightTopOpen = false; bool rightOpen = false; bool rightBottomOpen = false; bool bottomOpen = false; bool leftBottomOpen = false; var enemyStones = table.Stones.Where(s => s.Player != this.Player); #region check left-open // left var left = table.GetLocation(Location.X - 1, Location.Y); if (left != null && left != checkLocation && TryMove(left, table, out _s)) { leftOpen = true; GhostMove(left); foreach (var enemyStone in enemyStones) { if (enemyStone.TryMove(left, table, out IStone _e)) { leftOpen = false; break; } } UndoGhost(); } if (leftOpen) { return(true); } #endregion #region check leftTop-open // left-top var leftTop = table.GetLocation(Location.X - 1, Location.Y + 1); if (leftTop != null && leftTop != checkLocation && TryMove(leftTop, table, out _s)) { leftTopOpen = true; GhostMove(leftTop); foreach (var enemyStone in enemyStones) { if (enemyStone.TryMove(leftTop, table, out IStone _e)) { leftTopOpen = false; break; } } UndoGhost(); } if (leftTopOpen) { return(true); } #endregion #region check top open // top var top = table.GetLocation(Location.X, Location.Y + 1); if (top != null && top != checkLocation && TryMove(top, table, out _s)) { topOpen = true; GhostMove(top); foreach (var enemtStone in enemyStones) { if (enemtStone.TryMove(top, table, out IStone _e)) { topOpen = false; } } UndoGhost(); } if (topOpen) { return(true); } #endregion #region check rightTop-open // right-top var rightTop = table.GetLocation(Location.X + 1, Location.Y + 1); if (rightTop != null && rightTop != checkLocation && TryMove(rightTop, table, out _s)) { rightTopOpen = true; GhostMove(rightTop); foreach (var enemtStone in enemyStones) { if (enemtStone.TryMove(rightTop, table, out IStone _e)) { rightTopOpen = false; } } UndoGhost(); } if (rightTopOpen) { return(true); } #endregion #region check right open // right var right = table.GetLocation(Location.X + 1, Location.Y); if (right != null && right != checkLocation && TryMove(right, table, out _s)) { rightOpen = false; GhostMove(right); foreach (var enemtStone in enemyStones) { if (enemtStone.TryMove(right, table, out IStone _e)) { rightOpen = false; } } UndoGhost(); } if (rightOpen) { return(true); } #endregion #region check rightBottom-open // right-bottom var rightBottom = table.GetLocation(Location.X + 1, Location.Y - 1); if (rightBottom != null && rightBottom != checkLocation && TryMove(rightBottom, table, out _s)) { rightBottomOpen = true; GhostMove(rightBottom); foreach (var enemtStone in enemyStones) { if (enemtStone.TryMove(rightBottom, table, out IStone _e)) { rightBottomOpen = false; } } UndoGhost(); } if (rightBottomOpen) { return(true); } #endregion #region check bottom-open // bottom var bottom = table.GetLocation(Location.X, Location.Y - 1); if (bottom != null && bottom != checkLocation && TryMove(bottom, table, out _s)) { bottomOpen = true; GhostMove(bottom); foreach (var enemtStone in enemyStones) { if (enemtStone.TryMove(bottom, table, out IStone _e)) { bottomOpen = false; } } UndoGhost(); } if (bottomOpen) { return(true); } #endregion #region check leftBottom-open // left-bottom var leftBottom = table.GetLocation(Location.X - 1, Location.Y - 1); if (leftBottom != null && leftBottom != checkLocation && TryMove(leftBottom, table, out _s)) { leftBottomOpen = true; GhostMove(leftBottom); foreach (var enemtStone in enemyStones) { if (enemtStone.TryMove(leftBottom, table, out IStone _e)) { leftBottomOpen = false; } } UndoGhost(); } return(leftBottomOpen); #endregion }
public void PlaceBlackStone() { Stone = new BlackStone(); }
public void getaAdditionalStone(Stone stone) { this.additionalStone = stone; }
public void RemoveStone() { Stone = null; }
public static Instruction CreateOne(IStone stone, Location target, Session session, string rawCommand) { return(new Instruction(stone, target, session, rawCommand)); }
private void IsCheckmate(IStone stone) { var king = NextPlayer.GetKing(); // check yapan taşı yiyebilecek bir taş var mı? bool checkStoneCouldEated = false; IStone checkStoneEater = null; foreach (var nextPlayerStone in NextPlayer.Stones) { if (nextPlayerStone.TryMove(stone.Location, Table, out IStone _s)) { bool checkStoneEaterCouldMove = true; // şah çeken taşı yiyebilecek olan taş bu hareketi yapabilir mi? nextPlayerStone.GhostMove(stone.Location); foreach (var currentPlayerStone in CurrentPlayer.Stones) { if (currentPlayerStone == stone) { // şah çeken taşı yediğini varsayıyoruz continue; } if (currentPlayerStone.TryMove(stone.Location, Table, out IStone _k)) { // danger // nextPlayerStone could not move!! checkStoneEaterCouldMove = false; break; } } nextPlayerStone.UndoGhost(); if (checkStoneEaterCouldMove) { checkStoneCouldEated = true; checkStoneEater = nextPlayerStone; break; } } } if (checkStoneCouldEated) { if (checkStoneEater is King) { // stone'u o lokasyondan geçici olarak alalım // daha sonra o lokasyona bir taş gidebilir mi ona bakalım. // gidemiyorsa stone'u o laskyona geri alalım stone.GhostMove(null); foreach (var currentPlayerStone in CurrentPlayer.Stones) { if (currentPlayerStone == stone) { continue; } if (currentPlayerStone.TryMove(stone.StoredLocation, Table, out IStone _k)) { //Checkmate = true; //stone.UndoGhost(); //return; checkStoneCouldEated = false; break; } } stone.UndoGhost(); } //return; } // başka bir taş kral ile check yapan taş arasına girebilir mi? bool someStoneBroked = false; List <Location> checkLocations = stone.GetMovementLocations(king.Location, Table); if (checkLocations != null) { foreach (var checkLocation in checkLocations) { foreach (var nextPlayerStone in NextPlayer.Stones) { if (nextPlayerStone is King) { continue; } if (nextPlayerStone.TryMove(checkLocation, Table, out IStone _s)) { someStoneBroked = true; break; } } if (someStoneBroked) { break; } } } // king kaçabilir mi? if (checkStoneCouldEated == false && someStoneBroked == false && king.CouldRun(Table, stone.Location) == false) { Checkmate = true; Check = false; } }
internal void Eat(IStone stone) { stone.Player.Stones.Remove(stone); Eats.Add(stone); }
public MovementResult TryDo() { IStone willEated = default; var preMoveResult = PreMove(); if (preMoveResult.IsOK == false) { return(preMoveResult); } if (MovingStone.TryMove(Target, Session.Table, out willEated) != true) { return(new MovementResult(false, MovingStone, null, Target, "Oraya olmaz!")); } bool isOk = true; bool checkRemoved = false; string message = string.Empty; if (Session.Check) { if (willEated == Session.CheckStone) { isOk = true; checkRemoved = true; } // kralın önüne geçtiyse ve check-i bitirdiyse else { // CurrentPlayer'ın MovingStone'u o lokasyona ghostMove yapar. MovingStone.GhostMove(Target); // Şuanki durumda CurrentPlayer'a sıra geçecektir. var king = Session.CurrentPlayer.GetKing(); if (Session.CheckStone.TryMove(king.Location, Session.Table, out IStone _k)) { // hala check-i kaldıramıyor. isOk = false; } else { isOk = true; checkRemoved = true; } MovingStone.UndoGhost(); } } if (isOk) { message = $"<strong>{Session.CurrentPlayer.Nickname}</strong> oyuncusu <strong>{FromLocation.Name}</strong> -> <strong>{Target.Name}</strong> oynadı."; MovingStone.Move(Target, Session.Table, out willEated); return(new MovementResult(true, MovingStone, willEated, Target, message, checkRemoved)); } return(new MovementResult(false, MovingStone, null, Target, message)); }
public static Instruction CreateOne(IStone stone, Location target, Session session, string command) { var log = $"{DateTime.Now} - [player: {session.CurrentPlayer.Nickname}]>{command}"; return(new Instruction(stone, target, session, command, log)); }
public void getMainStone(Stone stone) { this.mainStone = stone; }
public void getSecondaryStone(Stone stone) { this.secondaryStone = stone; }
public void PlaceWhiteStone() { Stone = new WhiteStone(); }
internal void AddStone(IStone stone) { this.Stones.Add(stone); stone.SetPlayer(this); }
public abstract bool TryMove(Location target, Table table, out IStone willEated);