public async Task GetWordVector(string word) { var vector = await _wordVectors.Vector(word); if (vector == null) { await TypingReplyAsync("I don't know that word"); return; } var arr = new StringBuilder(vector.Count * 4); arr.Append('['); for (var i = 0; i < vector.Count; i++) { if (i != 0) { arr.Append(", "); } var num = vector[i] * 100; if (Math.Abs(num) < 1) { arr.Append('0'); } else { arr.Append(num.ToString("##")); } } arr.Append(']'); await ReplyAsync(arr.ToString()); }
public async Task StartGame(Mode mode, Mode autoMode = Mode.Hard, bool auto = true) { var values = Get(mode); string?prev = null; var played = new HashSet <string>(); while (played.Count < values.TurnLimit) { { //Check if we failed to find a valid response var myWord = Pick(prev, played, mode, values); if (myWord == null) { await TypingReplyAsync("I can't think of a good followup for that. You win!"); return; } //Play our turn await TypingReplyAsync($"{played.Count + 1}. {myWord}"); prev = myWord; played.Add(myWord); } string?theirWord; if (auto) { //Generate a response theirWord = Pick(prev, played, autoMode, Get(autoMode)); if (theirWord == null || string.IsNullOrEmpty(theirWord)) { await TypingReplyAsync("I can't think of a good followup for that. You win!"); return; } await TypingReplyAsync(theirWord); await Task.Delay(TimeSpan.FromSeconds(1)); } else { //Get response, break out if they lose (too slow) var response = await NextMessageAsync(true, true, values.TimeLimit); if (response == null) { await TypingReplyAsync("Too slow! I win :D"); return; } theirWord = response.Content.ToLowerInvariant(); } //Check for repeats if (played.Contains(theirWord)) { await TypingReplyAsync("That word was already played! I win :D"); return; } //Check length rule if (theirWord.Length < 4) { await TypingReplyAsync("Too short! I win :D"); return; } //Check letters if (theirWord.First() != prev.Last()) { await TypingReplyAsync("Wrong letter! I win :D"); return; } //Check that this word is in the dictionary or if it's not, check if it's got a valid word vector if (!_words.Contains(theirWord) && await _wordVectors.Vector(theirWord) == null) { await TypingReplyAsync("That's not a real word! I win :D"); return; } //They pass, add word to game state prev = theirWord; played.Add(theirWord); } await TypingReplyAsync($"Wow, {played.Count} turns! I surrender, you win."); }