// Performs full consistency checks, only the first time private GameBoard(int boardSize, FullPlayerSpecPair specs) { BoardSize = boardSize; (Player1, Player2) = specs.Map(x => x.Player); var positions = specs.Map(x => x.Positions.ToList()); #if DEBUG CheckPieces(boardSize, positions); #endif (BallCarrier1, BallCarrier2) = positions.Zip(specs, (l, spec) => l[spec.BallIndex]); (_player1Positions, _player2Positions) = positions.Map(ImmutableHashSet.CreateRange); var lookupBuilder = ImmutableDictionary.CreateBuilder <Position2D, Player>(); specs.Map(spec => spec.Positions.Select(p => new KeyValuePair <Position2D, Player>(p, spec.Player))) .ForEach(lookupBuilder.AddRange); _boardLookup = lookupBuilder.ToImmutable(); }
/// <summary> /// Creates a new game, initialised with the given player specs. /// The first player to play is chosen randomly. /// </summary> /// <param name="size">Size of the board</param> /// <param name="specs">Board configuration for each player</param> /// <returns>A new game</returns> public static Game Init(int size, FullPlayerSpecPair specs) { return(new Game(size, specs, Rng.Next(0, 2) == 1)); }
/// <summary> /// Creates a new game, initialised with the given player specs. /// </summary> /// <param name="size">Size of the board</param> /// <param name="specs">Board configurations for each player</param> /// <param name="isFirstPlayerPlaying">Whether player 1 is the first to start playing or not</param> /// <returns>A new game</returns> public static Game Init(int size, FullPlayerSpecPair specs, bool isFirstPlayerPlaying) { return(new Game(size, specs, isFirstPlayerPlaying)); }
// Only to initialise the game private Game(int size, FullPlayerSpecPair specs, bool isFirstPlayerPlaying) { Memento = new RootMemento(specs, size, isFirstPlayerPlaying); }
// Called to build an initial state private GameState(int size, FullPlayerSpecPair specs, bool isFirstPlayerPlaying) : base(GameBoard.Create(size, specs)) { CurrentPlayer = isFirstPlayerPlaying ? Player1 : Player2; }
public RootMemento(FullPlayerSpecPair specs, int boardSize, bool isFirstPlayerPlaying) : base(null) { IsFirstPlayerPlaying = isFirstPlayerPlaying; BoardSize = boardSize; Specs = specs; }