private SingleTree ComputerPlaysToWin(SingleTree nodeToPlay) { SingleTree winnerNode = null; foreach (var child in nodeToPlay.GetChilds().Values) { if (!child.NodeWithoutChilds()) { winnerNode = child; foreach (var grandParent in child.GetChilds().Values) { if (!(ComputerPlaysToWin(grandParent) != null || grandParent.NodeWithoutChilds())) { winnerNode = null; break; } } if (winnerNode != null) { break; } } } return(winnerNode); }
private SingleTree ComputerPlaysToGetLongestWord(SingleTree nodeToPlay) { SingleTree winnerNode = null; foreach (var child in nodeToPlay.GetChilds().Values) { if ((winnerNode == null) || child.MaximumLength() > winnerNode.MaximumLength()) { winnerNode = child; } } return(winnerNode); }