示例#1
0
        public static Tuple <int, int> GetNextTuple(MatrixViewModel matrixVM)
        {
            Tuple <int, int> tuple = null;

            if (matrixVM.PossibleValues.Count > 0)
            {
                int randomPosition = random.Next(0, matrixVM.PossibleValues.Count);
                tuple = matrixVM.PossibleValues.ElementAt(randomPosition);
                matrixVM.PossibleValues.RemoveAt(randomPosition);
            }

            return(tuple);
        }
示例#2
0
        private void prepareMatrix()
        {
            MatrixViewModel vm = new MatrixViewModel(Graph.NodesNr);

            for (int y = vm.NodeCount - 1; y >= 0; --y)
            {
                for (int x = 0; x < vm.NodeCount; ++x)
                {
                    vm.Connections[x, y] = Graph.GetConnection(x, y) ? Graph.getWeight(x, y) : 0;
                }
            }

            MatrixControl.DataContext = vm;
        }
        public IActionResult BlockField(string coordinates)
        {
            //Executes the Block part of the move , it checks whether a field is available and blocks it if it is , after which it checks whether the enemy player has lost the match
            MatrixViewModel mvm   = new MatrixViewModel(7);
            var             game  = _context.Games.Where(g => g.Id.ToString() == HttpContext.Session.GetString("GameId")).FirstOrDefault();
            var             field = JsonConvert.DeserializeObject <int[, ]>(game.Field);

            mvm.Field = field;
            for (int i = 0; i < mvm.Field.GetLength(0); i++)
            {
                for (int j = 0; j < mvm.Field.GetLength(1); j++)
                {
                    if (mvm.Field[i, j] == 2)
                    {
                        mvm.PlayerOneCoordinates = $"{i}_{j}";
                    }
                    else if (mvm.Field[i, j] == 3)
                    {
                        mvm.PlayerTwoCoordinates = $"{i}_{j}";
                    }
                }
            }
            string[] coords = coordinates.Split('_').ToArray();
            int      x      = int.Parse(coords[0]);
            int      y      = int.Parse(coords[1]);


            mvm.Field[x, y] = 1;
            _context.Games.Where(g => g.Id.ToString() == HttpContext.Session.GetString("GameId")).FirstOrDefault().Field = JsonConvert.SerializeObject(mvm.Field);
            _context.SaveChanges();

            if (game.PlayerOneId == User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                if (CheckIfLost(mvm, mvm.PlayerTwoCoordinates))
                {
                    _context.Games.Where(g => g.Id.ToString() == HttpContext.Session.GetString("GameId")).FirstOrDefault().CurrentPlayerAndTurn = 5;
                    _context.SaveChanges();
                }
            }
            if (game.PlayerTwoId == User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                if (CheckIfLost(mvm, mvm.PlayerOneCoordinates))
                {
                    _context.Games.Where(g => g.Id.ToString() == HttpContext.Session.GetString("GameId")).FirstOrDefault().CurrentPlayerAndTurn = 6;
                    _context.SaveChanges();
                }
            }
            return(new EmptyResult());
        }
示例#4
0
        private async void OpenFileExecute(object parameter)
        {
            var progress = new Progress <ProgressInfo>(p =>
            {
                _progressViewModel.Update(p);
            });

            _progressViewModel.Action = "Reading";
            string fileToOpen = parameter as string;

            if (fileToOpen != null)
            {
                await _application.OpenModel(fileToOpen, progress);

                ModelFilename = fileToOpen;
                Title         = $"DSM Viewer ({ModelFilename})";
                IsLoaded      = true;
                ActiveMatrix  = new MatrixViewModel(this, _application, GetRootElements());
            }
        }
        private bool CheckIfLost(MatrixViewModel game, string playerCoord)
        {
            //checks if the player's coordinates are surrounded by non available cells
            var gameInContext = _context.Games.Where(g => g.Id.ToString() == HttpContext.Session.GetString("GameId")).FirstOrDefault();

            game.Field = JsonConvert.DeserializeObject <int[, ]>(gameInContext.Field);
            int[] playerCoordinates = playerCoord.Split('_').Select(int.Parse).ToArray();
            int   playerX           = playerCoordinates[0];
            int   playerY           = playerCoordinates[1];

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    if (InRange(game, playerX + i, playerY + j) && game.Field[playerX + i, playerY + j] == 0)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#6
0
 protected virtual void createLabels(MatrixViewModel vm)
 {
     for (int y = 0; y < vm.NodeCount; ++y)
     {
         for (int x = 0; x < vm.NodeCount; ++x)
         {
             MatrixControlItem item = new MatrixControlItem();
             var ivm = new MatrixItemViewModel()
             {
                 Text       = vm.Connections[x, y].ToString(),
                 Background = vm.Connections[x, y] != 0
                 ? new SolidColorBrush(Color.FromArgb(50, 0, 255, 0)) : new SolidColorBrush(Colors.Transparent),
                 Visibility = vm.NodeCount <= 7 ? Visibility.Visible : Visibility.Collapsed,
                 Hint       = string.Format("[{0}, {1}] - {2}", x, y, vm.Connections[x, y])
             };
             item.DataContext = ivm;
             MatrixGrid.Children.Add(item);
             Grid.SetRow(item, y + 1);
             Grid.SetColumn(item, x + 1);
         }
     }
 }
示例#7
0
        public static void BuildBody(MatrixViewModel matrixVM)
        {
            for (int i = 0; i < matrixVM.Matrix.GetLength(0); i++)
            {
                matrixVM.Html.Append("<tr " + (matrixVM.IsCompleteLine(i, matrixVM.Log) ? "class='complete'" : "") + "><td class='lightGray'> " + (i + 1) + "</td>");
                if (matrixVM.IsCompleteLine(i, matrixVM.Log) && !matrixVM.CompleteLines.Contains(i))
                {
                    matrixVM.CompleteLines.Add(i);
                    LogHelper.LogComplete(matrixVM, EnumFillMatrixType.Line, i + 1);
                }

                for (int j = 0; j < matrixVM.Matrix.GetLength(1); j++)
                {
                    matrixVM.Html.Append("<td " + (matrixVM.IsCompleteColumn(j, matrixVM.Log) ? "class='complete'" : "") + ">" + matrixVM.Matrix[i, j].IsChecked + "</td>");
                    if (matrixVM.IsCompleteColumn(j, matrixVM.Log) && !matrixVM.CompleteColumns.Contains(j))
                    {
                        matrixVM.CompleteColumns.Add(j);
                        LogHelper.LogComplete(matrixVM, EnumFillMatrixType.Column, j + 1);
                    }
                }

                matrixVM.Html.Append("</tr>");
            }
        }
        public bool Move(string coordinates)
        {
            //Logic for the move action of the game - checks whether the coordinates given are available and in range and if they are, moves the current player to them
            MatrixViewModel mvm = new MatrixViewModel(7);

            var game  = _context.Games.Where(g => g.Id.ToString() == HttpContext.Session.GetString("GameId")).FirstOrDefault();
            var field = JsonConvert.DeserializeObject <int[, ]>(game.Field);

            mvm.Field = field;
            for (int i = 0; i < mvm.Field.GetLength(0); i++)
            {
                for (int j = 0; j < mvm.Field.GetLength(1); j++)
                {
                    if (mvm.Field[i, j] == 2)
                    {
                        mvm.PlayerOneCoordinates = $"{i}_{j}";
                    }
                    else if (mvm.Field[i, j] == 3)
                    {
                        mvm.PlayerTwoCoordinates = $"{i}_{j}";
                    }
                }
            }

            string[] coords = coordinates.Split('_').ToArray();
            int      x      = int.Parse(coords[0]);
            int      y      = int.Parse(coords[1]);
            int      playerMoving;

            string[] playerCoordinates = new string[2];
            if (game.PlayerOneId == User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                playerCoordinates = mvm.PlayerOneCoordinates.Split('_').ToArray();
                playerMoving      = 2;
            }
            else
            {
                playerCoordinates = mvm.PlayerTwoCoordinates.Split('_').ToArray();
                playerMoving      = 3;
            }
            //check if available

            if (InRangeToMove(mvm, playerCoordinates[0] + "_" + playerCoordinates[1], x + "_" + y))
            {
                if (mvm.Field[x, y] == 0)
                {
                    int coordX = int.Parse(playerCoordinates[0]);
                    int coordY = int.Parse(playerCoordinates[1]);
                    mvm.Field[coordX, coordY] = 0;
                    mvm.Field[x, y]           = playerMoving;
                    _context.Games.Where(g => g.Id.ToString() == HttpContext.Session.GetString("GameId")).FirstOrDefault().Field = JsonConvert.SerializeObject(mvm.Field);
                    _context.SaveChanges();
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            //if (game.PlayerOneId == User.FindFirst(ClaimTypes.NameIdentifier).Value)
            //{
            //    if (CheckIfLost(mvm, mvm.PlayerTwoCoordinates))
            //    {
            //        _context.Games.Where(g => g.Id.ToString() == HttpContext.Session.GetString("GameId")).FirstOrDefault().CurrentPlayerAndTurn = 5;
            //        _context.SaveChanges();


            //    }
            //}
            //if (game.PlayerTwoId == User.FindFirst(ClaimTypes.NameIdentifier).Value)
            //{
            //    if (CheckIfLost(mvm, mvm.PlayerOneCoordinates))
            //    {
            //        _context.Games.Where(g => g.Id.ToString() == HttpContext.Session.GetString("GameId")).FirstOrDefault().CurrentPlayerAndTurn = 6;
            //        _context.SaveChanges();


            //    }
            //}

            return(true);
        }
示例#9
0
 public static void LogCheck(MatrixViewModel matrixVM, int posX, int posY, DateTime time)
 {
     matrixVM.Log.AppendLine(String.Format("L{0},C{1} - {2}", posX, posY, time.ToString("H:mm:ss:ffff")));
 }
示例#10
0
 private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     _viewModel = DataContext as MatrixViewModel;
 }
示例#11
0
 private void GetMatrix()
 {
     matrixVM             = TempData["matrixVM"] as MatrixViewModel;
     TempData["matrixVM"] = matrixVM;
     TempData.Keep("matrixVM");
 }
示例#12
0
        public MainViewModel(IDsmApplication application)
        {
            _application                  = application;
            _application.Modified        += OnModelModified;
            _application.ActionPerformed += OnActionPerformed;

            OpenFileCommand = new RelayCommand <object>(OpenFileExecute, OpenFileCanExecute);
            SaveFileCommand = new RelayCommand <object>(SaveFileExecute, SaveFileCanExecute);

            HomeCommand = new RelayCommand <object>(HomeExecute, HomeCanExecute);

            MoveUpElementCommand   = new RelayCommand <object>(MoveUpElementExecute, MoveUpElementCanExecute);
            MoveDownElementCommand = new RelayCommand <object>(MoveDownElementExecute, MoveDownElementCanExecute);
            SortElementCommand     = new RelayCommand <object>(SortElementExecute, SortElementCanExecute);

            ShowElementDetailMatrixCommand  = new RelayCommand <object>(ShowElementDetailMatrixExecute, ShowElementDetailMatrixCanExecute);
            ShowElementContextMatrixCommand = new RelayCommand <object>(ShowElementContextMatrixExecute, ShowElementContextMatrixCanExecute);
            ShowCellDetailMatrixCommand     = new RelayCommand <object>(ShowCellDetailMatrixExecute, ShowCellDetailMatrixCanExecute);

            ZoomInCommand  = new RelayCommand <object>(ZoomInExecute, ZoomInCanExecute);
            ZoomOutCommand = new RelayCommand <object>(ZoomOutExecute, ZoomOutCanExecute);
            ToggleElementExpandedCommand = new RelayCommand <object>(ToggleElementExpandedExecute, ToggleElementExpandedCanExecute);

            UndoCommand = new RelayCommand <object>(UndoExecute, UndoCanExecute);
            RedoCommand = new RelayCommand <object>(RedoExecute, RedoCanExecute);

            OverviewReportCommand = new RelayCommand <object>(OverviewReportExecute, OverviewReportCanExecute);

            NavigateToNextCommand     = new RelayCommand <object>(NavigateToNextExecute, NavigateToNextCanExecute);
            NavigateToPreviousCommand = new RelayCommand <object>(NavigateToPreviousExecute, NavigateToPreviousCanExecute);

            CreateElementCommand       = new RelayCommand <object>(CreateElementExecute, CreateElementCanExecute);
            DeleteElementCommand       = new RelayCommand <object>(DeleteElementExecute, DeleteElementCanExecute);
            ChangeElementParentCommand = new RelayCommand <object>(MoveElementExecute, MoveElementCanExecute);
            ChangeElementNameCommand   = new RelayCommand <object>(ChangeElementNameExecute, ChangeElementNameCanExecute);
            ChangeElementTypeCommand   = new RelayCommand <object>(ChangeElementTypeExecute, ChangeElementTypeCanExecute);

            CreateRelationCommand       = new RelayCommand <object>(CreateRelationExecute, CreateRelationCanExecute);
            DeleteRelationCommand       = new RelayCommand <object>(DeleteRelationExecute, DeleteRelationCanExecute);
            ChangeRelationWeightCommand = new RelayCommand <object>(ChangeRelationWeightExecute, ChangeRelationWeightCanExecute);
            ChangeRelationTypeCommand   = new RelayCommand <object>(ChangeRelationTypeExecute, ChangeRelationTypeCanExecute);

            MakeSnapshotCommand = new RelayCommand <object>(MakeSnapshotExecute, MakeSnapshotCanExecute);
            ShowHistoryCommand  = new RelayCommand <object>(ShowHistoryExecute, ShowHistoryCanExecute);
            ShowSettingsCommand = new RelayCommand <object>(ShowSettingsExecute, ShowSettingsCanExecute);

            TakeScreenshotCommand = new RelayCommand <object>(TakeScreenshotExecute);

            _modelFilename = "";
            _title         = "DSM Viewer";
            _isModified    = false;
            _isLoaded      = false;

            _searchText  = "";
            _searchState = SearchState.NoMatch;

            _selectedSortAlgorithm = SupportedSortAlgorithms[0];

            _progressViewModel = new ProgressViewModel();

            ActiveMatrix = new MatrixViewModel(this, _application, new List <IDsmElement>());
        }
示例#13
0
 private void HomeExecute(object parameter)
 {
     ActiveMatrix = new MatrixViewModel(this, _application, GetRootElements());
 }
示例#14
0
        //
        // GET: /Page/
        public ActionResult Index(int page = 1)
        {
            var matrices = _matrixRepository.GetAll()
                           .OrderByDescending(m => m.Id)
                           .Skip((page - 1) * PAGE_SIZE)
                           .Take(PAGE_SIZE);

            var matrixListViewModel = new MatrixListViewModel()
            {
                Matrices   = new List <MatrixViewModel>(),
                PagingInfo = new PagingInfo {
                    CurrentPage  = page,
                    ItemsPerPage = PAGE_SIZE,
                    TotalItems   = _matrixRepository.GetAll().Count()
                }
            };


            if (matrices.Any())
            {
                foreach (var matrix in matrices)
                {
                    var model = new MatrixViewModel();

                    var buildingPart = (matrix.BuildingPartId.HasValue)
                        ? _buildingPartRepository.SingleOrDefault(matrix.BuildingPartId.Value)
                        : null;

                    var defectDescription = (matrix.DefectDescriptionId.HasValue)
                        ? _defectDescriptionRepository.SingleOrDefault(matrix.DefectDescriptionId.Value)
                        : null;

                    model.Id = matrix.Id;
                    model.BuildingPartCode = (buildingPart != null) ? (double?)buildingPart.Code : null;
                    model.BuildingPartText = (buildingPart != null) ? buildingPart.Name : null;

                    model.DefectDescriptionText = (defectDescription != null) ? defectDescription.Description : null;

                    model.Gebr      = matrix.ImportanceId;
                    model.Intencity = matrix.IntencityId;
                    model.Omvang    = matrix.ExtentId;
                    model.Condition = matrix.Condition;

                    if (matrix.ActieId.HasValue)
                    {
                        model.Action = _actionRepository.SingleOrDefault(matrix.ActieId.Value).Name;
                    }

                    model.CountHvh = matrix.HvhId;
                    model.Eenh     = ((Eenh)matrix.EenhId).ToString();
                    model.Percent  = matrix.Percent.HasValue ? matrix.Percent.Value.ToString() : string.Empty;

                    model.Cost  = matrix.Cost;
                    model.Total = matrix.Total.HasValue ? matrix.Total.Value : 0;
                    model.BTW   = matrix.BTW;
                    model.Cycle = matrix.Cycle;

                    model.StartYear = matrix.StartYear;


                    // render calendar cost
                    model.CalendarBuilder = RenderCalendarCostString(model.Total, matrix.BTW, matrix.Cycle,
                                                                     matrix.StartYear);

                    // append to list
                    matrixListViewModel.Matrices.Add(model);
                }
            }


            return(View(matrixListViewModel));
        }