Example #1
0
        // Auto complete all itmes that has only one available move
        public int AutoCompleteSingle()
        {
            int found = 0;

            for (int x = 0; x < 9; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    var moves = game.AvailableRanks(x, y);
                    if (moves.Count == 1)
                    {
                        found++;
                        CellFocus = new GridLocation(x, y);
                        SetRank(moves[0]);
                    }
                }
            }
            return(found);
        }
Example #2
0
        public Cell GetCell(GridLocation location)
        {
            GridLocation localLoacation = new GridLocation(location.Xpos % 3, location.Ypos % 3);

            // Top
            if (localLoacation.Ypos == 0)
            {
                return(Cells[localLoacation.Xpos]);
            }

            // Center
            if (localLoacation.Ypos == 1)
            {
                return(Cells[localLoacation.Xpos + 3]);
            }

            // Bootom
            return(Cells[localLoacation.Xpos + 6]);
        }
Example #3
0
        public void UndoLastMove()
        {
            if (MoveHistory.Count == 0)
            {
                return;
            }
            UnSelect(CellFocus);
            GridLocation loc = MoveHistory[MoveHistory.Count - 1];

            UnSelect(loc);
            game[loc.Xpos, loc.Ypos] = new CellContent(0);
            SodokuBoard.SetRank(loc, 0);
            MoveHistory.Remove(loc);
            LoadAvailableMoves();
            if (MoveHistory.Count > 0)
            {
                Select(MoveHistory[MoveHistory.Count - 1]);
            }
        }
Example #4
0
        public void SetRank(GridLocation location, int rank)  // location here is absolute the the overall board
        {
            //GridLocation localLoacation = new GridLocation(location.Xpos % 3, location.Ypos % 3);
            if (rank < 0 || rank > 9)
            {
                rank = 0;
            }
            Cell cell = GetCell(location);

            if (InputFixedValues)
            {
                cell.Rank = rank; cell.IsFixed = rank == 0 ? false : true;
            }
            else
            {
                if (!cell.IsFixed)
                {
                    cell.Rank = rank;
                }
            }
        }
Example #5
0
 public bool ValidateMove(GridLocation location, int rank)
 {
     if (rank == 0)
     {
         return(true);
     }
     // if cell is not empty, clear it temporarily to check if the move could be valid
     if (!game[location.Xpos, location.Ypos].IsEmpty)
     {
         int curRank = game[location.Xpos, location.Ypos].Rank;
         // Clear temp
         game[location.Xpos, location.Ypos] = new CellContent(0);
         if (game.ValidateMove(location.Xpos, location.Ypos, rank))
         {
             game[location.Xpos, location.Ypos] = new CellContent(curRank);
             return(true);
         }
         game[location.Xpos, location.Ypos] = new CellContent(curRank);
         return(false);
     }
     return(game.ValidateMove(location.Xpos, location.Ypos, rank));
 }
Example #6
0
 public void UnSelect(GridLocation location)
 {
     HasSelection = true;
     SodokuBoard.UnSelect(location);
 }
Example #7
0
 public void Select(GridLocation location)
 {
     SodokuBoard.Select(location);
 }
Example #8
0
        /// <summary>
        /// Sets the CellFocus item x and Y ofr 9x9 grid
        /// </summary>
        /// <param name="boardPoint"></param>
        public void SetCellFocus(Point boardPoint)
        {
            HasSelection   = true;
            CellFocus      = new GridLocation();
            CellFocus.Xpos = -1;
            CellFocus.Ypos = -1;
            if (boardPoint.X < gridAnchor.X || boardPoint.Y < gridAnchor.Y || boardPoint.X >= gridAnchor.X + frameSize || boardPoint.Y >= gridAnchor.Y + frameSize)
            {
                HasSelection = false; return;
            }
            if (boardPoint.X < gridAnchor.X + cellSize)
            {
                CellFocus.Xpos = 0;
            }
            else
            {
                if (boardPoint.X < gridAnchor.X + 2 * cellSize + 1)
                {
                    CellFocus.Xpos = 1;
                }
                else
                {
                    if (boardPoint.X < gridAnchor.X + 3 * cellSize + 2)
                    {
                        CellFocus.Xpos = 2;
                    }
                    else
                    {
                        if (boardPoint.X < gridAnchor.X + 4 * cellSize + 4)
                        {
                            CellFocus.Xpos = 3;
                        }
                        else
                        {
                            if (boardPoint.X < gridAnchor.X + 5 * cellSize + 5)
                            {
                                CellFocus.Xpos = 4;
                            }
                            else
                            {
                                if (boardPoint.X < gridAnchor.X + 6 * cellSize + 6)
                                {
                                    CellFocus.Xpos = 5;
                                }
                                else
                                {
                                    if (boardPoint.X < gridAnchor.X + 7 * cellSize + 8)
                                    {
                                        CellFocus.Xpos = 6;
                                    }
                                    else
                                    {
                                        if (boardPoint.X < gridAnchor.X + 8 * cellSize + 9)
                                        {
                                            CellFocus.Xpos = 7;
                                        }
                                        else
                                        {
                                            CellFocus.Xpos = 8;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (boardPoint.Y < gridAnchor.Y + cellSize)
            {
                CellFocus.Ypos = 0; return;
            }
            if (boardPoint.Y < gridAnchor.Y + 2 * cellSize + 1)
            {
                CellFocus.Ypos = 1; return;
            }
            if (boardPoint.Y < gridAnchor.Y + 3 * cellSize + 2)
            {
                CellFocus.Ypos = 2; return;
            }
            if (boardPoint.Y < gridAnchor.Y + 4 * cellSize + 4)
            {
                CellFocus.Ypos = 3; return;
            }
            if (boardPoint.Y < gridAnchor.Y + 5 * cellSize + 5)
            {
                CellFocus.Ypos = 4; return;
            }
            if (boardPoint.Y < gridAnchor.Y + 6 * cellSize + 6)
            {
                CellFocus.Ypos = 5; return;
            }
            if (boardPoint.Y < gridAnchor.Y + 7 * cellSize + 8)
            {
                CellFocus.Ypos = 6; return;
            }
            if (boardPoint.Y < gridAnchor.Y + 8 * cellSize + 9)
            {
                CellFocus.Ypos = 7; return;
            }

            CellFocus.Ypos = 8;
        }
Example #9
0
 public void ClearRank(GridLocation location) => SetRank(location, 0);
Example #10
0
        public void UnSelect(GridLocation location)
        {
            Cell cell = GetCell(location);

            cell.IsSelected = false;
        }
Example #11
0
        public void MakeFixed(GridLocation location)
        {
            Cell cell = GetCell(location);

            cell.IsFixed = true;
        }
Example #12
0
        public void UnSelect(GridLocation location)
        {
            SubGrid grid = GetSubgrid(location);

            grid.UnSelect(location);
        }
Example #13
0
        public void SetAvailableRanks(GridLocation location, List <int> ranks)
        {
            SubGrid grid = GetSubgrid(location);

            grid.SetAvailableRanks(location, ranks);
        }
Example #14
0
        public void MakeFixed(GridLocation location)
        {
            SubGrid grid = GetSubgrid(location);

            grid.MakeFixed(location);
        }