public virtual bool RemoveStartingPeg(Dictionary <char, bool> pegs) { startingPeg = nextStartingPeg < GameInterface.PegChars.Length ? GameInterface.PegChars[nextStartingPeg] : (char?)null; if (startingPeg.HasValue) { history.TryAdd(startingPeg.Value, new List <History.GameRecord>()); wins.TryAdd(startingPeg.Value, new List <History.GameRecord>()); currentPath = new History.JumpList(); if (history.ContainsKey(startingPeg.Value)) { var paths = history[startingPeg.Value]; lastPath = paths.Count > 0 ? paths[paths.Count - 1].JumpList : (History.JumpList)null; } GameInterface.RemovePeg(pegs, startingPeg.Value); return(true); } currentPath = (History.JumpList)null; lastPath = (History.JumpList)null; return(false); }
public virtual bool PlayAgain(Dictionary <char, bool> pegs) { var pegsRemaining = GameInterface.GetRemainingPegs(pegs); var gameRecord = new History.GameRecord(currentPath, pegsRemaining); history[startingPeg.Value].Add(gameRecord); if (pegsRemaining.Length == 1) { wins[startingPeg.Value].Add(gameRecord); } PrintStats(); bool hasMoreMoves = false; foreach (var jump in history[startingPeg.Value][history[startingPeg.Value].Count - 1].JumpList) { if (jump.JumpIndex > 0) { hasMoreMoves = true; } } if (!hasMoreMoves || (maxAttemptsPerPeg.HasValue && history[startingPeg.Value].Count >= maxAttemptsPerPeg.Value)) { nextStartingPeg++; lastPath = null; } return(Math.Min(GameInterface.PegChars.Length, lastStartingPeg + 1) > nextStartingPeg); }
static bool PathsEqual(History.JumpList pastPath, History.JumpList currentPath) { if (pastPath.Count < currentPath.Count) { return(false); } for (var j = 0; j < currentPath.Count; j++) { if (!currentPath[j].Jump.Equals(pastPath[j].Jump)) { return(false); } } return(true); }