public bool CheckIfNoAvaliableMoves(IValidPositionVerifier ver) { var cows = GetBoard(); var cw = Turn(turn).GetCow().Get(); int i = 0; foreach (Cow x in cows) { if (x.Get() == cw && ver.VerifyAdjacent(CurrentBoard.GetAdjacent(i))) { return(false); } i++; } return(true); }
/// <summary> /// Sets a node at a given index to a Cow and then checks for a valid mill /// </summary> /// <param name="index"></param> /// <returns></returns> /// <summary> /// Move takes in a index of an ellipse and then uses the game state variables it has within it to call various methods to facilitate appropriate actions. /// </summary> /// <param name="index"></param> public IBoard Move(int index) { verifier = new ValidPositionVerifier(CurrentBoard); if (command != null) { command.Execute(); } if (removing) { if (verifier.VerifyCanShoot(index, Turn(!turn))) { CurrentBoard.SetEmpty(index); CowKilled(); removing = false; NextTurn(); } } else { switch (Turn(turn).GetPhase()) { case (Phase.Moving): if (CheckIfNoAvaliableMoves(verifier)) { PlayerLost(); } else if (verifier.VerifyMoving(index, Turn(turn))) { CurrentBoard.Moving(index); SetTurnPhase(Phase.Moving2); } break; case (Phase.Moving2): if (verifier.VerifyMoving2(index)) { removing = CurrentBoard.PlaceCow(index, Turn(turn)); SetTurnPhase(Phase.Moving); if (!removing) { NextTurn(); } } break; case (Phase.Placing): if (verifier.VerifyPlacing(index)) { CowPlaced(); removing = CurrentBoard.PlaceCow(index, Turn(turn)); if (!removing) { NextTurn(); } } break; case (Phase.Flying): if (verifier.VerifyFlying(index, Turn(turn))) { CurrentBoard.SetEmpty(index); SetTurnPhase(Phase.Flying2); } break; case (Phase.Flying2): if (verifier.VerifyFlying2(index)) { removing = CurrentBoard.PlaceCow(index, Turn(turn)); SetTurnPhase(Phase.Flying); if (!removing) { NextTurn(); } } break; } } return(CurrentBoard); }