/// <summary>
 /// Creates a new game state by applying the given move to the given starting
 /// state. Verifies the move's validity, throwing an exception if the move is
 /// illegal.
 /// </summary>
 /// <param name="initialState"></param>
 /// <param name="applyMe"></param>
 private GameState(GameState initialState, Move applyMe)
 {
     rowCount = initialState.rowCount;
     occupiedHoles = new List<Coordinate>(initialState.occupiedHoles);
     if (!occupiedHoles.Remove(applyMe.GetFrom()))
     {
         throw new ArgumentException(
                 "Move is not consistent with game state: 'from' hole was unoccupied.");
     }
     if (!occupiedHoles.Remove(applyMe.GetJumped()))
     {
         throw new ArgumentException(
                 "Move is not consistent with game state: jumped hole was unoccupied.");
     }
     if (occupiedHoles.Contains(applyMe.GetTo()))
     {
         throw new ArgumentException(
                 "Move is not consistent with game state: 'to' hole was occupied.");
     }
     if (applyMe.GetTo().GetRow() > rowCount || applyMe.GetTo().GetRow() < 1)
     {
         throw new ArgumentException(
                 "Move is not legal because the 'to' hole does not exist: " + applyMe.GetTo());
     }
     occupiedHoles.Add(applyMe.GetTo());
 }
 public GameState Apply(Move move)
 {
     return new GameState(this, move);
 }
Beispiel #3
0
 public GameState Apply(Move move)
 {
     return(new GameState(this, move));
 }