/// <summary> /// Builds and returns the game specified by this builder. /// </summary> /// <returns>A new game</returns> public Game Build() { DiaballikUtil.Assert(CanBuild, ErrorMessage); var players = (PlayerBuilder1, PlayerBuilder2).Map(x => x.Build()); var specs = InitStrategy.InitPositions(BoardSize) .Zip(players, (spec, player) => new FullPlayerBoardSpec(player, spec)); return(Game.Init(BoardSize, specs)); }
/// When the board size is the same, we only need to update pieces that have changed, /// no need to create everything from scratch. private void ResetDifferential(GameState state) { DiaballikUtil.Assert(state.BoardSize == BoardSize, "Cannot reset differentially when changing board size"); var modifiedPs = new HashSet <Position2D>(); CurrentState.PositionsPair.ForEach(ps => modifiedPs.UnionWith(ps)); state.PositionsPair.ForEach(ps => modifiedPs.UnionWith(ps)); foreach (var p in modifiedPs) { UpdateTile(p, state); } UnlockedPlayer = null; CurrentState = state; }
/// <summary> /// Builds a player with the specified configuration. /// </summary> /// <returns>A new player</returns> public Player Build() { DiaballikUtil.Assert(CanBuild, ErrorMessage); return(new Player(Color, Name, SelectedPlayerType)); }