Ejemplo n.º 1
0
 /// <summary>
 /// This undoes placement of a domino
 /// </summary>
 /// <param name="domino"></param>
 private void FreeDominoPosition(DominoController domino)
 {
     if (domino.IsHorizontal())
     {
         mGameGrid[domino.Row, domino.Column - 1].Clear();
         mGameGrid[domino.Row, domino.Column].Clear();
         mGameGrid[domino.Row, domino.Column + 1].Clear();
     }
     else
     {
         mGameGrid[domino.Row + 1, domino.Column].Clear();
         mGameGrid[domino.Row, domino.Column].Clear();
         mGameGrid[domino.Row - 1, domino.Column].Clear();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Is this domino in a scoring position
        /// </summary>
        /// <param name="domino"></param>
        /// <returns></returns>
        public bool DominoScoresPlayer2(DominoController domino)
        {
            if (domino.IsHorizontal())
            {
                if ((domino.Column == 1 &&
                    (mBoardController.HasSquareExit(domino.Row, 0, CardinalPoint.W))))
                {
                    return true;
                }
                else if ((domino.Column == (mBoardController.Size - 2) &&
                    (mBoardController.HasSquareExit(domino.Row, mBoardController.Size - 1, CardinalPoint.E))))
                {
                    return true;
                }
            }
            else //Domino Vertical
            {
                if (domino.Column == 0)
                {
                    for (int row = -1; row < 2; row++)
                    {
                        if (mBoardController.HasSquareExit(domino.Row + row, 0, CardinalPoint.W))
                        {
                            return true;
                        }
                    }
                }
                else if (domino.Column == mBoardController.Size - 1)
                {
                    for (int row = -1; row < 2; row++)
                    {
                        if (mBoardController.HasSquareExit(domino.Row + row, mBoardController.Size - 1, CardinalPoint.E))
                        {
                            return true;
                        }
                    }
                }

            }
            return false;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Is this domino in a scoring position
 /// </summary>
 /// <param name="domino"></param>
 /// <returns></returns>
 public bool DominoScoresPlayer1(DominoController domino)
 {
     if (domino.IsHorizontal())
     {
         if (domino.Row == 0)
         {
             for (int col = -1; col < 2; col++)
             {
                 if (mBoardController.HasSquareExit(0, domino.Column + col, CardinalPoint.S))
                 {
                     return true;
                 }
             }
         }
         else if (domino.Row == mBoardController.Size - 1)
         {
             for (int col = -1; col < 2; col++)
             {
                 if (mBoardController.HasSquareExit(domino.Row, domino.Column + col, CardinalPoint.N))
                 {
                     return true;
                 }
             }
         }
     }
     else //Domino Vertical
     {
         if ((domino.Row == 1 && (mBoardController.HasSquareExit(0, domino.Column, CardinalPoint.S))))
         {
             return true;
         }
         else if ((domino.Row == (mBoardController.Size - 2) && (mBoardController.HasSquareExit(mBoardController.Size - 1, domino.Column, CardinalPoint.N))))
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Keep Track of all open Exit for each direction.
        /// </summary>
        /// <param name="domino"></param>
        private void UpdateOpenExitsArray(DominoController domino)
        {
            int[, ,] openExits = mOpenExitStack.GetOpenExists();

            if (domino.IsHorizontal())
            {
                for (int i = -1; i < 2; i++)
                {
                    //North Exit
                    if (openExits[0, 0, domino.Column + i] < domino.Row)
                    {
                        if ((mGameGrid[domino.Row, domino.Column + i].NorthExit) &&
                            (openExits[1, 0, domino.Column + i] < domino.Row))
                        {
                            openExits[0, 0, domino.Column + i] = domino.Row;
                        }
                        else
                        {
                            openExits[0, 0, domino.Column + i] = -1;
                            openExits[1, 0, domino.Column + i] = Math.Max(domino.Row, openExits[1, 0, domino.Column + i]);
                        }
                    }

                    //South Exit

                    if (openExits[0, 2, domino.Column + i] > domino.Row)
                    {
                        if (mGameGrid[domino.Row, domino.Column + i].SouthExit &&
                            openExits[1, 2, domino.Column + i] > domino.Row)
                        {
                            openExits[0, 2, domino.Column + i] = domino.Row;
                        }
                        else
                        {
                            openExits[0, 2, domino.Column + i] = Size;
                            openExits[1, 2, domino.Column + i] = Math.Min(domino.Row, openExits[1, 2, domino.Column + i]);
                        }
                    }
                }

                //West Exit
                if (openExits[0, 1, domino.Row] > domino.Column)
                {
                    if (mGameGrid[domino.Row, domino.Column - 1].WestExit &&
                        openExits[1, 1, domino.Row] > domino.Column)
                    {
                        openExits[0, 1, domino.Row] = domino.Column - 1;
                    }
                    else
                    {
                        openExits[0, 1, domino.Row] = Size;
                        openExits[1, 1, domino.Row] = Math.Min(openExits[1, 1, domino.Row], domino.Column - 1);
                    }
                }


                //East Exit
                if (openExits[0, 3, domino.Row] < domino.Column)
                {
                    if (mGameGrid[domino.Row, domino.Column + 1].EastExit &&
                        (openExits[1, 3, domino.Row] < domino.Column))
                    {
                        openExits[0, 3, domino.Row] = domino.Column + 1;
                    }
                    else
                    {
                        openExits[0, 3, domino.Row] = -1;
                        openExits[1, 3, domino.Row] = Math.Max(openExits[1, 3, domino.Row], domino.Column + 1);
                    }
                }
            }
            else //domino vertical
            {
                for (int i = -1; i < 2; i++)
                {
                    //East Exit
                    if (openExits[0, 3, domino.Row + i] < domino.Column)
                    {
                        if (mGameGrid[domino.Row + i, domino.Column].EastExit &&
                            (openExits[1, 3, domino.Row + i] < domino.Column))
                        {
                            openExits[0, 3, domino.Row + i] = domino.Column;
                        }
                        else
                        {
                            openExits[0, 3, domino.Row + i] = -1;
                            openExits[1, 3, domino.Row + i] = Math.Max(openExits[1, 3, domino.Row + i], domino.Column);
                        }
                    }

                    //West Exit

                    if (openExits[0, 1, domino.Row + i] > domino.Column)
                    {
                        if (mGameGrid[domino.Row + i, domino.Column].WestExit &&
                            openExits[1, 1, domino.Row + i] > domino.Column)
                        {
                            openExits[0, 1, domino.Row + i] = domino.Column;
                        }
                        else
                        {
                            openExits[0, 1, domino.Row + i] = Size;
                            openExits[1, 1, domino.Row + i] = Math.Min(openExits[1, 1, domino.Row + i], domino.Column);
                        }
                    }
                }


                //North Exit
                if (openExits[0, 0, domino.Column] < domino.Row)
                {
                    if (mGameGrid[domino.Row + 1, domino.Column].NorthExit &&
                        openExits[1, 0, domino.Column] < domino.Row)
                    {
                        openExits[0, 0, domino.Column] = domino.Row + 1;
                    }
                    else
                    {
                        openExits[0, 0, domino.Column] = -1;
                        openExits[1, 0, domino.Column] = Math.Max(openExits[1, 0, domino.Column], domino.Row + 1);
                    }
                }

                //South Exit
                if (openExits[0, 2, domino.Column] > domino.Row)
                {
                    if (mGameGrid[domino.Row - 1, domino.Column].SouthExit &&
                        openExits[1, 2, domino.Column] > domino.Row)
                    {
                        openExits[0, 2, domino.Column] = domino.Row - 1;
                    }
                    else
                    {
                        openExits[0, 2, domino.Column] = Size;
                        openExits[1, 2, domino.Column] = Math.Min(openExits[1, 2, domino.Column], domino.Row - 1);
                    }
                }
            }

#if DEEPTEST
            for (int i = 0; i < 2; i++)
            {
                for (int card = 0; card < 4; card++)
                {
                    for (int mr = 0; mr < Size; mr++)
                    {
                        if ((openExits[i, card, mr] > -1) && (openExits[i, card, mr] < Size))
                        {
                            Console.WriteLine(" OpenExit/(MinMax) " + i + " Card Point " + card + " Row/Column " + mr + " Value " + openExits[i, card, mr]);
                        }
                    }
                }
            }
#endif
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Expands bbox
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        public void Grow(DominoController domino)
        {
            if (domino.IsHorizontal())
            {
                if ((domino.Row) < RowMin)
                {
                    mRowMin = domino.Row;
                }
                if (domino.Row > mRowMax)
                {
                    mRowMax = domino.Row;
                }

                if ((domino.Column - 1) < mColumnMin)
                {
                    mColumnMin = domino.Column - 1;
                }
                if ((domino.Column + 1) > mColumnMax)
                {
                    mColumnMax = domino.Column + 1;
                }
            }
            else
            {
                if ((domino.Row - 1) < RowMin)
                {

                    mRowMin = domino.Row - 1;
                }
                if ((domino.Row + 1) > mRowMax)
                {
                    mRowMax = domino.Row + 1;
                }

                if ((domino.Column) < mColumnMin)
                {
                    mColumnMin = domino.Column;
                }
                if ((domino.Column) > mColumnMax)
                {
                    mColumnMax = domino.Column;
                }
            }
        }
Ejemplo n.º 6
0
        private bool PositionFree(DominoController domino)
        {
            UnityEngine.Debug.DebugBreak();
            bool positionEmpty = false;

            if (domino.IsHorizontal() && domino.Column > 0 && domino.Column < mSize - 1)
            {
                if (((domino.Row > (mBBox.RowMax + 1)) || (domino.Row < (mBBox.RowMin - 1))) ||
                    //North Border search area
                      (domino.Row == (mBBox.RowMax + 1) &&
                            (mGameGrid[mBBox.RowMax, domino.Column - 1].Occupied == false) &&
                           (mGameGrid[mBBox.RowMax, domino.Column].Occupied == false) &&
                               (mGameGrid[mBBox.RowMax, domino.Column + 1].Occupied == false))
                    //South Border search area
                    || (domino.Row == (mBBox.RowMin - 1) &&
                        (mGameGrid[mBBox.RowMin, domino.Column - 1].Occupied == false) &&
                                (mGameGrid[mBBox.RowMin, domino.Column].Occupied == false) &&
                                    (mGameGrid[mBBox.RowMin, domino.Column + 1].Occupied == false))
                        ||
                    //East Border search area
                   (domino.Column == (mBBox.ColumnMax + 2) &&
                        (mGameGrid[domino.Row, mBBox.ColumnMax].Occupied == false)) ||
                    //West Border search area
                        (domino.Column == (mBBox.ColumnMin - 2) &&
                        (mGameGrid[domino.Row, mBBox.ColumnMin].Occupied == false))
                        )
                {
            #if TEST
                        Console.WriteLine("No connections");
            #endif
                    return false;
                }

                //Inside search area

                if ((mGameGrid[domino.Row, domino.Column - 1].Occupied == false) &&
                          (mGameGrid[domino.Row, domino.Column].Occupied == false) &&
                              (mGameGrid[domino.Row, domino.Column + 1].Occupied == false))

                    positionEmpty = true;

            }

              //  Domino vertical

            else if (!domino.IsHorizontal() && domino.Row > 0 && domino.Row < Size - 1)
            {
                if (((domino.Column > (mBBox.ColumnMax + 1)) || (domino.Column < (mBBox.ColumnMin - 1))) ||
                    //East Border search area
                    (domino.Column == (mBBox.ColumnMax + 1) &&
                    (mGameGrid[domino.Row - 1, mBBox.ColumnMax].Occupied == false) &&
                    (mGameGrid[domino.Row, mBBox.ColumnMax].Occupied == false) &&
                    (mGameGrid[domino.Row + 1, mBBox.ColumnMax].Occupied == false)) ||
                    //West Border search area
                    (domino.Column == (mBBox.ColumnMin - 1) &&
                    (mGameGrid[domino.Row - 1, mBBox.ColumnMin].Occupied == false) &&
                        (mGameGrid[domino.Row, mBBox.ColumnMin].Occupied == false) &&
                                 (mGameGrid[domino.Row + 1, mBBox.ColumnMin].Occupied == false))
                      ||
                    //North Border search area
                    (domino.Row == (mBBox.RowMax + 2) &&
                    (mGameGrid[mBBox.RowMax, domino.Column].Occupied == false)) ||
                    //South Border search area
                    (domino.Row == (mBBox.RowMin - 2) && (mGameGrid[mBBox.RowMin, domino.Column].Occupied == false)))
                {
            #if TEST
                        Console.WriteLine("No connections");
            #endif
                    return false;
                }

                //Inside search area

                if ((mGameGrid[domino.Row + 1, domino.Column].Occupied == false) &&
                                     (mGameGrid[domino.Row, domino.Column].Occupied == false) &&
                                         (mGameGrid[domino.Row - 1, domino.Column].Occupied == false))
                {
                    positionEmpty = true;
                }
            }
            else
            {
            #if TEST
                Console.WriteLine("No connections");
            #endif
                return false;
            }

            #if TEST
            if (domino.Row == 6 && domino.Column == 9 && domino.RotationState == 2&& domino.Label==9)

            {
                Console.WriteLine("");
            }

            Console.WriteLine("position available " + mPositionEmpty);
            #endif

            return positionEmpty;
        }
Ejemplo n.º 7
0
        void MarkInsideJunction(DominoController domino)
        {
            int row = domino.Row;
            int column = domino.Column;
            if (
               ((domino.GetWaterExitSquareID(0) == -1) || (domino.GetWaterExitSquareID(1) == -1) || (domino.GetWaterExitSquareID(2) == -1))

               &&
                (domino.GetWaterExitSquareID(0) == 1) || (domino.GetWaterExitSquareID(1) == 1) || (domino.GetWaterExitSquareID(2) == 1))
            {
                if (domino.IsHorizontal())
                {
                    MarkSquareExit(row, column - 1, CardinalPoint.E);
                    MarkSquareExit(row, column, CardinalPoint.W);
                    MarkSquareExit(row, column, CardinalPoint.E);
                    MarkSquareExit(row, column + 1,CardinalPoint.W);
                }
                else
                {
                    MarkSquareExit(row - 1, column,CardinalPoint.N);
                    MarkSquareExit(row, column, CardinalPoint.N);
                    MarkSquareExit(row, column, CardinalPoint.S);
                    MarkSquareExit(row + 1, column,CardinalPoint.S);
                }

            }
            else if ((domino.GetWaterExitSquareID(0) == 0) || (domino.GetWaterExitSquareID(1) == 0) || (domino.GetWaterExitSquareID(2) == 0))
            {
                if ((domino.GetWaterExitSquareID(0) == -1) || (domino.GetWaterExitSquareID(1) == -1) || (domino.GetWaterExitSquareID(2) == -1))
                {
                    switch (domino.RotationState)
                    {
                        case 0:
                            MarkSquareExit(row, column - 1, CardinalPoint.E);
                            MarkSquareExit(row, column, CardinalPoint.W);
                            break;
                        case 1:
                            MarkSquareExit(row - 1, column, CardinalPoint.N);
                            MarkSquareExit(row, column, CardinalPoint.S);
                            break;
                        case 2:
                            MarkSquareExit(row, column + 1, CardinalPoint.W);
                            MarkSquareExit(row, column, CardinalPoint.E);
                            break;
                        case 3:
                            MarkSquareExit(row + 1, column, CardinalPoint.S);
                            MarkSquareExit(row, column, CardinalPoint.N);
                            break;
                    }
                }
                else if ((domino.GetWaterExitSquareID(0) == 1) || (domino.GetWaterExitSquareID(1) == 1) || (domino.GetWaterExitSquareID(2) == 1))
                {
                    switch (domino.RotationState)
                    {
                        case 0:
                            MarkSquareExit(row, column + 1, CardinalPoint.W);
                            MarkSquareExit(row, column, CardinalPoint.E);
                            break;
                        case 1:
                            MarkSquareExit(row + 1, column, CardinalPoint.S);
                            MarkSquareExit(row, column, CardinalPoint.N);
                            break;
                        case 2:
                            MarkSquareExit(row, column - 1, CardinalPoint.E);
                            MarkSquareExit(row, column, CardinalPoint.W);
                            break;
                        case 3:
                            MarkSquareExit(row - 1, column, CardinalPoint.N);
                            MarkSquareExit(row, column, CardinalPoint.S);
                            break;
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private void FreeDominoPosition(DominoController domino)
 {
     if (domino.IsHorizontal())
     {
         mGameGrid[domino.Row, domino.Column - 1].Clear();
         mGameGrid[domino.Row, domino.Column].Clear();
         mGameGrid[domino.Row, domino.Column + 1].Clear();
     }
     else
     {
         mGameGrid[domino.Row + 1, domino.Column].Clear();
         mGameGrid[domino.Row, domino.Column].Clear();
         mGameGrid[domino.Row - 1, domino.Column].Clear();
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// When we found a Domino to be Valid we can add it to the Board. 
        /// We will then reserve the corresponding Squares.
        /// We will check as well if the new picked Domino is changing both Player Scores.
        /// </summary>
        /// <param name="domino"></param>
        public void AddDomino(DominoController domino)
        {
            if (domino.IsHorizontal())
            {
                for (int i = -1; i < 2; i++)

                {
                    mGameGrid[domino.Row, domino.Column + i].Occupied = true;
                }
            }
            else
            {

                for (int i = -1; i < 2; i++)
                {
                mGameGrid[domino.Row + i, domino.Column].Occupied = true;
                }
            }

            // This maintains a structure of outflows (for the AI)
            MarkDominoExits(domino);

            // Add to the undo stack
            mOpenExitStack.PushOpenExits();

            // Update Boards Data
            UpdateOpenExitsArray(domino);
            UpdateMinMaxCoordinates(domino);

            #if TESTALPHABETA
            Debug.WriteLine("Add to the board  Domino with Label "
                        + domino.Label + " RotationState" +
                        domino.RotationState + " Row " + domino.Row + " Column " + domino.Column );
            #endif
        }
Ejemplo n.º 10
0
        private void UpdateOpenExitsArray(DominoController domino)
        {
            int[, ,] openExits = mOpenExitStack.GetOpenExists();

            if (domino.IsHorizontal())
            {

                for (int i = -1; i < 2; i++)
                {
                    //North Exit
                    if (openExits[0, 0, domino.Column + i] < domino.Row)
                    {
                        if ((mGameGrid[domino.Row, domino.Column + i].NorthExit)
                            && (openExits[1, 0, domino.Column + i] < domino.Row))
                        {
                            openExits[0, 0, domino.Column + i] = domino.Row;
                        }
                        else
                        {
                            openExits[0, 0, domino.Column + i] = -1;
                            openExits[1, 0, domino.Column + i] = Math.Max(domino.Row, openExits[1, 0, domino.Column + i]);
                        }
                    }

                    //South Exit

                    if (openExits[0, 2, domino.Column + i] > domino.Row)
                    {
                        if (mGameGrid[domino.Row, domino.Column + i].SouthExit
                            && openExits[1, 2, domino.Column + i] > domino.Row)
                        {
                            openExits[0, 2, domino.Column + i] = domino.Row;
                        }
                        else
                        {
                            openExits[0, 2, domino.Column + i] = Size;
                            openExits[1, 2, domino.Column + i] = Math.Min(domino.Row, openExits[1, 2, domino.Column + i]);
                        }
                    }
                }

                //West Exit
                if (openExits[0, 1, domino.Row] > domino.Column)
                {
                    if (mGameGrid[domino.Row, domino.Column - 1].WestExit
                        && openExits[1, 1, domino.Row] > domino.Column)
                    {
                        openExits[0, 1, domino.Row] = domino.Column - 1;
                    }
                    else
                    {
                        openExits[0, 1, domino.Row] = Size;
                        openExits[1, 1, domino.Row] = Math.Min(openExits[1, 1, domino.Row], domino.Column - 1);
                    }
                }

                //East Exit
                if (openExits[0, 3, domino.Row] < domino.Column)
                {
                    if (mGameGrid[domino.Row, domino.Column + 1].EastExit
                        && (openExits[1, 3, domino.Row] < domino.Column))
                    {
                        openExits[0, 3, domino.Row] = domino.Column + 1;
                    }
                    else
                    {
                        openExits[0, 3, domino.Row] = -1;
                        openExits[1, 3, domino.Row] = Math.Max(openExits[1, 3, domino.Row], domino.Column + 1);
                    }
                }
            }
            else //domino vertical
            {
                for (int i = -1; i < 2; i++)
                {
                    //East Exit
                    if (openExits[0, 3, domino.Row + i] < domino.Column)
                    {
                        if (mGameGrid[domino.Row + i, domino.Column].EastExit
                            && (openExits[1, 3, domino.Row + i] < domino.Column))
                        {
                            openExits[0, 3, domino.Row + i] = domino.Column;
                        }
                        else
                        {
                            openExits[0, 3, domino.Row + i] = -1;
                            openExits[1, 3, domino.Row + i] = Math.Max(openExits[1, 3, domino.Row + i], domino.Column);
                        }
                    }

                    //West Exit

                    if (openExits[0, 1, domino.Row + i] > domino.Column)
                    {
                        if (mGameGrid[domino.Row + i, domino.Column].WestExit
                            && openExits[1, 1, domino.Row + i] > domino.Column)
                        {
                            openExits[0, 1, domino.Row + i] = domino.Column;
                        }
                        else
                        {
                            openExits[0, 1, domino.Row + i] = Size;
                            openExits[1, 1, domino.Row + i] = Math.Min(openExits[1, 1, domino.Row + i], domino.Column);
                        }
                    }
                }

                //North Exit
                if (openExits[0, 0, domino.Column] < domino.Row)
                {
                    if (mGameGrid[domino.Row + 1, domino.Column].NorthExit
                        && openExits[1, 0, domino.Column] < domino.Row)
                    {
                        openExits[0, 0, domino.Column] = domino.Row + 1;
                    }
                    else
                    {
                        openExits[0, 0, domino.Column] = -1;
                        openExits[1, 0, domino.Column] = Math.Max(openExits[1, 0, domino.Column], domino.Row + 1);
                    }
                }

                //South Exit
                if (openExits[0, 2, domino.Column] > domino.Row)
                {
                    if (mGameGrid[domino.Row - 1, domino.Column].SouthExit
                        && openExits[1, 2, domino.Column] > domino.Row)
                    {
                        openExits[0, 2, domino.Column] = domino.Row - 1;
                    }
                    else
                    {
                        openExits[0, 2, domino.Column] = Size;
                        openExits[1, 2, domino.Column] = Math.Min(openExits[1, 2, domino.Column], domino.Row - 1);
                    }
                }
            }

            #if DEEPTEST
            for (int i = 0; i < 2; i++)
            {
                for (int card = 0; card < 4; card++)
                {
                    for (int mr = 0; mr < Size; mr++)
                    {
                        if ((openExits[i, card, mr] > -1) && (openExits[i, card, mr] < Size))
                        {
                            Console.WriteLine(" OpenExit/(MinMax) " + i + " Card Point " + card + " Row/Column " + mr + " Value " + openExits[i, card, mr]);

                        }
                    }
                }
               }
            #endif
        }