/// <summary> /// Instantiates both bots, giving then fixed names. /// </summary> protected override void SetupPlayers() { Output.WriteLine(); players[PLAYER_ONE] = new Player($"Bot 1 (Advanced)"); players[PLAYER_TWO] = new Player($"Bot 2"); bots[PLAYER_ONE] = new BotCheaty(players[PLAYER_TWO].Board); bots[PLAYER_TWO] = new BotRealistic(players[PLAYER_ONE].Board); }
/// <summary> /// Gets the player ship positions and places them on the board. /// </summary> protected override void SetupShipPlacements() { ShipType[] shipTypes = (ShipType[])Enum.GetValues(typeof(ShipType)); // For each ship type.. foreach (ShipType shipType in shipTypes) { for (int i = 0; i < MAX_PLAYERS; i++) { // Ask the player for the ships they want to place. if (i == PLAYER_ONE) { Output.ClearScreen(); Output.PrintBoard(players[PLAYER_ONE], true); string shipName = shipType.ToString().ToLower(); PlaceShipRequest placeRequest = new PlaceShipRequest(); placeRequest.ShipType = shipType; ShipPlacement placeResponse; do { Output.PrintPlacementQuestion(shipName); placeRequest.Coordinate = Input.GetCoordinate(); Output.PrintDirectionQuestion(shipName); placeRequest.Direction = Input.GetDirection(); placeResponse = players[PLAYER_ONE].Board.PlaceShip(placeRequest); Output.ClearScreen(); Output.PrintBoard(players[PLAYER_ONE], true); if (placeResponse == ShipPlacement.Ok) { Output.PrintPlacementResponse(shipName, placeResponse); } } while (placeResponse != ShipPlacement.Ok); } // The bot will randomly pick positions to place their ships. else { PlaceShipRequest placeRequest = new PlaceShipRequest(); placeRequest.ShipType = shipType; do { placeRequest.Coordinate = BotRealistic.GetRandomCoordinate(); placeRequest.Direction = BotRealistic.GetRandomDirection(); } while (players[PLAYER_TWO].Board.PlaceShip(placeRequest) != ShipPlacement.Ok); } } } }