private bool NoStall(Coordinate position, BarrierOrientation orientation) { var barrierPosition = new Barrier(position, orientation, BarrierPiece.Head); var barrierH = new Barrier(new Coordinate(position.First + 1, position.Second), orientation, BarrierPiece.Tail); var barrierV = new Barrier(new Coordinate(position.First, position.Second + 1), orientation, BarrierPiece.Tail); if (orientation.Equals(BarrierOrientation.Horizontal)) { var playerBarrier = new List <IBarrier> { barrierPosition, barrierH }; if (this.barriers.GetBarriersAsGraph().ContainsPath(BarriersGraph.BarriersAsEdgesToRemove(playerBarrier), this.player1Position, this.player1FinishLine)) { if (this.barriers.GetBarriersAsGraph().ContainsPath(BarriersGraph.BarriersAsEdgesToRemove(playerBarrier), this.player2Position, this.player2FinishLine)) { return(true); } } return(false); } else { var playerBarrier = new List <IBarrier> { barrierPosition, barrierV }; if (this.barriers.GetBarriersAsGraph().ContainsPath(BarriersGraph.BarriersAsEdgesToRemove(playerBarrier), this.player1Position, this.player1FinishLine)) { if (this.barriers.GetBarriersAsGraph().ContainsPath(BarriersGraph.BarriersAsEdgesToRemove(playerBarrier), this.player2Position, this.player2FinishLine)) { return(true); } } return(false); } }
private bool IsEmptyPosition(Coordinate position, BarrierOrientation orientation) { if (this.barriers.Contains(new Barrier(position, BarrierOrientation.Horizontal, BarrierPiece.Head))) { return(false); } if (this.barriers.Contains(new Barrier(position, BarrierOrientation.Vertical, BarrierPiece.Head))) { Console.WriteLine("Not empty!!"); return(false); } if (this.barriers.Contains(new Barrier(position, BarrierOrientation.Horizontal, BarrierPiece.Tail))) { if (orientation.Equals(BarrierOrientation.Horizontal)) { Console.WriteLine("Not empty!!"); return(false); } else { if (!this.CheckEmptyNextPosition(position, orientation)) { return(false); } } } if (this.barriers.Contains(new Barrier(position, BarrierOrientation.Vertical, BarrierPiece.Tail))) { if (orientation.Equals(BarrierOrientation.Vertical)) { Console.WriteLine("Not empty!!"); return(false); } else { if (!this.CheckEmptyNextPosition(position, orientation)) { return(false); } } } if (!this.CheckEmptyNextPosition(position, orientation)) { return(false); } return(true); }
private bool CheckEmptyNextPosition(Coordinate position, BarrierOrientation orientation) { if (this.barriers.Contains(new Barrier(new Coordinate(position.First + 1, position.Second), BarrierOrientation.Horizontal, BarrierPiece.Head))) { if (orientation.Equals(BarrierOrientation.Horizontal)) { Console.WriteLine("Not empty!!"); return(false); } } if (this.barriers.Contains(new Barrier(new Coordinate(position.First, position.Second + 1), BarrierOrientation.Vertical, BarrierPiece.Head))) { if (orientation.Equals(BarrierOrientation.Vertical)) { Console.WriteLine("Not empty!!"); return(false); } } return(true); }
public void PlaceBarrier(Coordinate position, BarrierOrientation orientation) { if (this.CheckPlacement(position, orientation)) { this.player1Barriers--; if (orientation.Equals(BarrierOrientation.Horizontal)) { this.barriers.Add(new Barrier(position, orientation, BarrierPiece.Head)); this.barriers.Add(new Barrier(new Coordinate(position.First + 1, position.Second), orientation, BarrierPiece.Tail)); } else { this.barriers.Add(new Barrier(position, orientation, BarrierPiece.Head)); this.barriers.Add(new Barrier(new Coordinate(position.First, position.Second + 1), orientation, BarrierPiece.Tail)); } } else { Console.WriteLine("Bad move! Still your turn!"); } }