/// <summary> /// Plays for a specific turn. /// </summary> /// <param name="turn"></param> /// <returns></returns> public abstract Action Play(Turn turn);
/// <summary> /// Plays for a specific turn. /// </summary> /// <param name="turn"></param> /// <returns></returns> public override Action Play(Turn turn) { throw new NotImplementedException(); }
/// <summary> /// Instantiates the next <see cref="Turn"/> by playing an <paramref name="action"/>. /// The returned new <see cref="Turn"/> is null if the <paramref name="action"/> breaks the rules. /// </summary> /// <param name="action"></param> /// <returns>The next <see cref="Turn"/> can be null if <paramref name="action"/> breaks the rules.</returns> public Turn NextTurn(Action action) { if (action == null) { return(null); } if (action.Player != CurrentPlayer) { return(null); } if (action is PassHand) { return(initializeNextTurn()); } else if (action is PlaceStone) { var placeStone = action as PlaceStone; var stone = placeStone.Stone; if (!FreePositions.Contains(stone.Position)) { return(null); } Turn nextTurn = initializeNextTurn(); // Remove captured groups for (int g = 0; g < nextTurn._groups.Count; g++) { var group = nextTurn._groups.ElementAt(g); if (group.Player != stone.Player) { var f = GetFreedoms(group); if (f.Count() == 1 && f.Contains(stone.Position)) { nextTurn._groups.Remove(group); g--; } } } // Create a new group with the new stone Group newGroup = new Group(stone); // Merge adjacent groups for (int g = 0; g < nextTurn._groups.Count; g++) { var group = nextTurn._groups.ElementAt(g); if (group.Player == stone.Player && group.AdjacentPositions.Contains(stone.Position)) { newGroup += group; nextTurn._groups.Remove(group); g--; } } nextTurn._groups.Add(newGroup); // Check that newGroup hast freedom in nextTurn if (!nextTurn.GetFreedoms(newGroup).Any()) { return(null); } // Check Ko rule if (nextTurn.isSameState(Previous)) { return(null); } // Action is valid, nextTurn is well created return(nextTurn); } else { throw new ArgumentException("Action expected to be PlaceStone or PassHand."); } }