public void Play() { shuffler.Shuffle(rnd, gameGrid); finder.FindEmptyElement(gameGrid, emptyPos); do { Draw(gameGrid); Menu(); if (gameGrid.Cast <string>().SequenceEqual(completedGrid.Cast <string>())) { Draw(gameGrid); Console.WriteLine("\n\n***** Y O U W O N *****"); Console.WriteLine("Do you want to play again? y/n"); do { ConsoleKeyInfo answer = Console.ReadKey(); if (Char.ToLower(answer.KeyChar) == 'y') { shuffler.Shuffle(rnd, gameGrid); finder.FindEmptyElement(gameGrid, emptyPos); break; } if (Char.ToLower(answer.KeyChar) == 'n') { return; } } while (true); } } while (true); }
private static void VerifyDoesNotHaveNulls(string[,] output) { if (output.Cast <string>().Any(x => x == null)) { throw new Exception("nulls found"); } }
private static void VerifyCountsAreEqual(string[,] input, string[,] output) { if (input.Cast <string>().Count() != output.Cast <string>().Count()) { throw new Exception("items count do not match"); } }
static void Main(string[] args) { string[,] array = new string[,] { { "ab","ab","ab","FREE","me","me","me","FREE","mo","mo","FREE","FREE"}, { "so","so","FREE","no","no","FREE","to","to","to","FREE","do","do"} }; Console.WriteLine(string.Join(", ", string.Join(", ", array.Cast<string>()))); List<PackedItem> packed = Pack(array); Shuffle(packed); int rows = array.GetLength(0); int columns = array.GetLength(1); string[,] unpacked = Unpack(packed, rows, columns); Console.WriteLine(string.Join(", ", string.Join(", ", unpacked.Cast<string>()))); Console.ReadKey(); }
private void CheckWin(int row, int column) { if (CheckForDiagonal(row, column) || CheckForLines(row, column)) { WinTextBlock.Text = $"{_player} won! Poggers"; } else if (!_board.Cast <string>().Contains("Empty")) { WinTextBlock.Text = "It was a tie! Poggers"; } else { return; } WinTextBlock.Visibility = Visibility.Visible; winnerSelected = true; }
public TypeGenerator(CodeGenerator.Context context) { var template = "Packages/com.unity.netcode/Editor/CodeGenTemplates/GhostComponentSerializer.cs"; if (!context.typeCodeGenCache.TryGetValue(template, out var generator)) { generator = new GhostCodeGen(template); context.typeCodeGenCache.Add(template, generator); } m_TargetGenerator = generator.Clone(); foreach (var frag in k_OverridableFragments.Cast <string>()) { if (!m_OverridableFragmentsList.Contains(frag)) { m_OverridableFragmentsList += " " + frag; } } ; }
private void PartOne() { foreach (var line in _input) { var temp = ""; if (line.StartsWith("rect")) { temp = line.Replace("rect ", ""); ActivateRectangle(int.Parse(temp.Substring(0, temp.IndexOf("x", StringComparison.Ordinal))), int.Parse(temp.Substring(temp.IndexOf("x", StringComparison.Ordinal) + 1))); } else if (line.StartsWith("rotate row")) { temp = line.Replace("rotate row ", ""); RotateRow(int.Parse(temp.Substring(temp.IndexOf("y", StringComparison.Ordinal) + 2, 1)), int.Parse(temp.Substring(temp.IndexOf("by ", StringComparison.Ordinal) + 3))); } else if (line.StartsWith("rotate column")) { temp = line.Replace("rotate column ", ""); RotateColumn(int.Parse(temp.Substring(temp.IndexOf("x", StringComparison.Ordinal) + 2, 2).Trim()), int.Parse(temp.Substring(temp.IndexOf("by ", StringComparison.Ordinal) + 3))); } } Console.WriteLine(_screen.Cast <string>().Count(x => x != "*")); }
public virtual IEnumerator <string> GetEnumerator() { return(matrix.Cast <string>().GetEnumerator()); }
public int MinesLeft() { return(Squares.Cast <string>().Count(square => square == "*")); }
/// <summary> /// Parsuje HTML kód a ukladá do pola /// </summary> private void ParseData(string year) { int tmp = 0; string browserContents = webBrowser.DocumentText; if (browserContents == "") { return; } HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); //Parsovanie tabulky indexu do query doc.LoadHtml(browserContents); var query = from table in doc.DocumentNode.SelectNodes("//table") from row in table.SelectNodes("tr") from cell in row.SelectNodes("th|td") select new { Table = table.Id, CellText = cell.InnerText }; Regex regex = new Regex("(B|J|K|M|X)[A-Z0-9]{3}"); int length = 0; foreach (var cell in query) { Match match = regex.Match(Convert.ToString(cell.CellText)); if (match.Success) { length++; } if (cell.CellText == "Akademický rok: " + year) { break; } } int line = 0; int col = 0; int identity = -1; foreach (var cell in query) { Match match = regex.Match(Convert.ToString(cell.CellText)); if (match.Success) { identity++; col = 0; line = identity; } if ((identity != -1) && (col <= 11) && (line < length)) { temp[line, col] = Convert.ToString(cell.CellText); if (temp[line, col].Contains(" ")) { temp[line, col] = temp[line, col].Replace(" ", ""); } col++; } } if (!partition || !lastYear.Equals(year)) { for (int m = 0; m < length; m++) { for (int n = 0; n <= 11; n++) { pole[m, n] = temp[m, n]; } } partition = true; } else { var equal = pole.Rank == temp.Rank && Enumerable.Range(0, pole.Rank).All(dimension => pole.GetLength(dimension) == temp.GetLength(dimension)) && pole.Cast <string>().SequenceEqual(temp.Cast <string>()); if (!equal) { for (int m = 0; m < length; m++) { for (int n = 0; n <= 11; n++) { if (string.CompareOrdinal(pole[m, n], temp[m, n]) != 0) { tmp = m; for (int k = 0; k <= 11; k++) { change[k] = temp[m, k]; } break; } } } string msg = null; if (change[7].Contains("ano") && (pole[tmp, 7].Contains("ne") || pole[tmp, 7].Contains("nie")) && (string.CompareOrdinal(change[8], pole[tmp, 8]) != 0)) { msg = $"Získal si zápočet z {change[0]} - {change[8]}"; } else if (change[7].Contains("ano") && (pole[tmp, 7].Contains("ne") || pole[tmp, 7].Contains("nie"))) { msg = $"Získal si zápočet z {change[0]}"; } else { change[9] = change[9].Length > 1 ? change[9].Substring(0, 1) : change[9]; msg = $"Update: {change[0]} - {change[8]} - {change[9]}"; } for (int m = 0; m < length; m++) { for (int n = 0; n <= 11; n++) { pole[m, n] = temp[m, n]; } } if (WindowState == FormWindowState.Minimized) { notifyIcon.BalloonTipText = msg; notifyIcon.ShowBalloonTip(3000); } if (chb_mail.Checked) { SendMail(msg); } MessageBox.Show(msg); } } FillArray(pole, length); }
static void Main(string[] args) { SetBackgroundColor(); Ocean ocean = new Ocean(); Console.Write("Player board"); Console.WriteLine(); ocean.drawCordinates(); Console.WriteLine(); Console.Write("Computer board"); Console.WriteLine(); ocean.drawCordinates(); origRow = Console.CursorTop; origCol = Console.CursorLeft; //WriteAt("OOO", 2, 2); string[] cords = { "AD", "FG" }; Ships sh1 = new Ships(ShipType.small, cords); Ships sh2 = new Ships(ShipType.small, cords); Ships hs1 = new Ships(ShipType.huge, cords); Logger.Write(sh1.ShipName + " " + sh1.ShipPosition[0]); Logger.Write(sh2.ShipName + " " + sh2.ShipPosition[0]); Logger.Write(hs1.ShipName + " " + hs1.ShipPosition[0]); CoordinateSystem coordSys = new CoordinateSystem(0, 0); CoordinateSystem.WriteAt("O", 5, 3); Console.SetCursorPosition(0, 40); Logger.Write(Console.CursorLeft + " " + Console.CursorTop); AI ai = new AI(); ai.test(); string[,] matrix = coordSys.getMatrix(); List <string> validMoves = matrix.Cast <string>().ToList(); string input; //Console.WriteLine("Press ESC to stop"); do { input = Console.ReadLine().TrimEnd(Environment.NewLine.ToCharArray()).Trim(); if (validMoves.IndexOf(input.ToUpper()) > -1) { Logger.Write("Player position: " + input); } else { Logger.Write("Invalid move: " + input); } } while (Console.ReadKey(true).Key != ConsoleKey.Escape); Logger.SaveToFile(); }
public long CountSafe() { return(_tiles.Cast <string>().LongCount(tile => tile == ".")); }