public void Play(int mapSize) { var map = PrepareMap(mapSize); while (true) { WriteBattleScore(); WriteMap(map); var input = Console.ReadLine(); if (ValidateFormat(mapSize, input)) { Console.WriteLine("Incorrect format"); continue; } var coordinates = new FieldCoordinates(input); var result = battleService.Shoot(coordinates.Row, coordinates.Column); WriteBattleStatusMessage(result); if (result.Score.Sinks == 3) { Console.WriteLine("Game is over! You won!"); break; } } Console.ReadKey(); }
private void MainBoardControl_OnAction(object sender, Point e) { FieldCoordinates action = FieldCoordinates.Get((uint)e.X, (uint)e.Y); MainNavigator1.Navigator.Play(action); MainNavigator1.Forward(this, action); }
private void button2_Click(object sender, EventArgs e) { var rounds = MainNavigator1.Navigator.RoundWithDetails((int)numberOfPlayoutsControl.Value); playoutListControl.Items.Clear(); int playoutNumber = 1; var whiteTrigger = FieldCoordinates.Get(0, 5); foreach (var round in rounds) { string trigger = " "; var played = round.Playout?.FirstOrDefault(m => whiteTrigger.Equals(m.Item1)); if (played != null) { if (played.Item2.CurrentPlayer.Opposite.Color.State == FieldState.White) { trigger = "*"; } } string result = round.GetLastGameState().GetWinner().Color.State == FieldState.Black ? "B" : "W"; playoutListControl.Items.Add(new NamedObject <GoMctsRound>($"{playoutNumber:000} {result}{trigger}", round)); playoutNumber++; } GoBoardControlFieldFeaturesHelper.RefreshBoard(goBoardControl1, MainNavigator1); }
private void CreateBoard(int width, int height) { this.height = height; this.width = width; //division grid to rows and cols boardGrid.ColumnDefinitions.Clear(); for (int i = 0; i < width; i++) { boardGrid.ColumnDefinitions.Add(new ColumnDefinition()); } boardGrid.RowDefinitions.Clear(); for (int j = 0; j < height; j++) { boardGrid.RowDefinitions.Add(new RowDefinition()); } //creating conditions array boardConditions = new FieldCondition[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { boardConditions[i, j] = FieldCondition.Empty; } } //creating buttons boardButtons = new Button[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Button button = new Button(); button.Margin = new Thickness(0); boardGrid.Children.Add(button); Grid.SetColumn(button, i); Grid.SetRow(button, j); button.Tag = new FieldCoordinates { Horizontal = i, Vertical = j }; button.Click += new RoutedEventHandler( (s, e) => { Button clickingButton = s as Button; FieldCoordinates coordinates = (FieldCoordinates)clickingButton.Tag; int clickingHorizontal = coordinates.Horizontal; int clickingVertical = coordinates.Vertical; OnClickingField(coordinates); }); boardButtons[i, j] = button; } } ChangeColorsAllButtons(); }
private FieldCoordinates[] ToPosition(GameTree gameTree) { List <FieldCoordinates> result = new List <FieldCoordinates>(); while (gameTree != null) { foreach (var node in gameTree.Sequence.Nodes) { foreach (var color in new[] { "B", "W" }) { var m = node.Properties.FirstOrDefault(p => color.Equals(p.Ident.Text, StringComparison.OrdinalIgnoreCase)); if (m != null) { result.Add(FieldCoordinates.ParseSgf(m.Values.First())); } } } gameTree = null; } return(result.ToArray()); }
public static void RefreshBoard(GoBoardControl boardControl, IObservableGameTreeNavigator <MCTreeSearchNode <GameState, FieldCoordinates>, GameState, FieldCoordinates> navigator) { GameState currentState = navigator.CurrentNode.State; var allowedActions = currentState.GetAllowedActions(); for (uint y = 0; y < boardControl.BoardSize; y++) { for (uint x = 0; x < boardControl.BoardSize; x++) { FieldCoordinates field = FieldCoordinates.Get(x, y); FieldState fieldState = currentState.InternalState.BoardFields[x, y]; boardControl.Fields[x, y].State = fieldState; boardControl.Fields[x, y].Labels.Clear(); // Illegal boardControl.Fields[x, y].Borders[0] = fieldState == FieldState.Empty ? allowedActions.Contains(field) == false : false; boardControl.Fields[x, y].Borders[1] = false; boardControl.Fields[x, y].Borders[2] = false; } } var currentNode = navigator.CurrentNode; //double[] mctsWeights = null;// mcts.Selector.GetWeights(mcts.CurrentNode); if (currentNode.Children != null) { foreach (var childNode in currentNode.Children) { if (childNode.Key != FieldCoordinates.Pass) { if (childNode.Value.Visits > 0) { boardControl.Fields[childNode.Key.X, childNode.Key.Y].AddLabel(Brushes.Magenta, $"{childNode.Value.Visits}"); boardControl.Fields[childNode.Key.X, childNode.Key.Y].AddLabel(Brushes.Green, $"{childNode.Value.Value}"); } } } var mostFrequentlySimulated = currentNode.Children.Where(w => w.Key != FieldCoordinates.Pass && w.Value.Visits > 0).MaxItems(i => i.Value.Visits); foreach (var mostItem in mostFrequentlySimulated) { boardControl.Fields[mostItem.Key.X, mostItem.Key.Y].Borders[2] = true; } } //if (mctsWeights != null) //{ // mctsWeights = mctsWeights.Where(w => w.Item1.LastAction != null && w.Item1.LastAction != FieldCoordinates.Pass); // // foreach (var item in mctsWeights) // { // var move = item.Item1.LastAction; // // if (move != null && move != FieldCoordinates.Pass) // { // boardControl.Fields[move.X, move.Y].AddLabel(Brushes.Blue, $"{item.Item2:f2}"); // } // } // // var maxItem = mctsWeights.MaxItem(i => i.Item2); // var maxMove = maxItem.Item1.LastAction; // // boardControl.Fields[maxMove.X, maxMove.Y].Borders[1] = true; //} boardControl.Refresh(); }
private void PlayoutNavigator_Forwarded(object sender, FieldCoordinates action) { GoBoardControlFieldFeaturesHelper.RefreshBoard(playoutBoardControl, PlayoutNavigator.CurrentNode); }
private void MainNavigator_Forwarded(object sender, FieldCoordinates action) { GoBoardControlFieldFeaturesHelper.RefreshBoard(goBoardControl1, MainNavigator1); }