Ejemplo n.º 1
0
        private async Task StartGame(Core.Game game)
        {
            game.Finished    += Game_Finished;
            game.TurnChanged += Game_TurnChanged;
            this.game         = game;
            began             = DateTime.Now;

            mainField.Game   = game;
            handlerView.Game = game;

            if (game.Team1.TeamHandler is Core.ManualTeamHandler manual1)
            {
                manual1.NeedIntent1 += Manual1_NeedIntent1;
                manual1.NeedIntent2 += Manual1_NeedIntent2;
            }

            if (game.Team2.TeamHandler is Core.ManualTeamHandler manual2)
            {
                manual2.NeedIntent1 += Manual2_NeedIntent1;
                manual2.NeedIntent2 += Manual2_NeedIntent2;
            }

            game.Length = handlerView.Turns;
            var t = game.Start(tokenSource.Token);

            gameTask = t;

            abortGameItem.Visibility = Visibility.Visible;
            newGameItem.Visibility   = Visibility.Collapsed;

            await t;
        }
Ejemplo n.º 2
0
        private void ExportGame(Core.Game game, DateTime date)
        {
            System.IO.Directory.CreateDirectory("Games");
            var path = System.IO.Path.Combine("Games", $"{date.Month}{date.Day}{date.Hour}{date.Minute}{date.Second}.pgame");

            Core.Export.GameSerializer.Serialize(game, path);
        }
Ejemplo n.º 3
0
        private async void newField_Click(object sender, RoutedEventArgs e)
        {
            await AbortGameAsync();

            var muB  = double.TryParse(muT.Text, out var mu);
            var sigB = double.TryParse(sigmaT.Text, out var sig);

            if (!muB)
            {
                MessageBox.Show("μの値が数値ではありません");
                return;
            }

            if (!sigB)
            {
                MessageBox.Show("σの値が数値ではありません");
                return;
            }

            var random = new Core.Algorithms.NormalDistribution()
            {
                Mu     = mu,
                Sigma  = sig,
                UseCos = cosC.IsChecked ?? false
            };

            var field = new Core.Field(new Core.FieldGenerators.RandomFieldGenerator((int)widthS.Value, (int)heightS.Value, random));
            var hw    = widthS.Value / 2;
            var hh    = heightS.Value / 2;

            Random rnd = new Random();

            int agentMaxW = (int)(widthS.Value % 2 == 0 ? hw + 1 : hw);
            int agentMaxH = (int)(widthS.Value % 2 == 0 ? hh + 1 : hh);

            Core.Point agent = new Core.Point(rnd.Next(0, agentMaxH), rnd.Next(0, agentMaxW));

            int crossX = ((int)widthS.Value) - agent.X - 1;
            int crossY = ((int)heightS.Value) - agent.Y - 1;

            var g = new Core.Game(field, new Core.Team(agent, new Core.Point(crossX, crossY)), new Core.Team(new Core.Point(crossX, agent.Y), new Core.Point(agent.X, crossY)));

            await StartGame(g);
        }