Esempio n. 1
0
 private void CheckCaptureDLDiagonal(int x, int y)
 {
     try {
         Stone[,] stones = gameScreen.Stones;
         StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;
         if (x - 1 < 0 || y + 1 > stones.GetLength(0) - 1)
         {
             return;
         }
         if (stones[y + 1, x - 1].CurrentState == currentState || stones[y + 1, x - 1].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x - 2 < 0 || y + 2 > stones.GetLength(0) - 1)
         {
             return;
         }
         if (stones[y + 2, x - 2].CurrentState == currentState || stones[y + 2, x - 2].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x - 3 < 0 || y + 3 > stones.GetLength(0) - 1)
         {
             return;
         }
         if (stones[y + 3, x - 3].CurrentState != currentState)
         {
             return;
         }
         CurrentPlayer.Captures++;
         stones[y + 1, x - 1].CurrentState = StoneState.Open;
         stones[y + 2, x - 2].CurrentState = StoneState.Open;
     } catch { }
 }
Esempio n. 2
0
 private void CheckCaptureURDiagonal(int x, int y)
 {
     try {
         Stone[,] stones = gameScreen.Stones;
         StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;
         if (x + 1 > stones.GetLength(1) - 1 || y - 1 < 0)
         {
             return;
         }
         if (stones[y - 1, x + 1].CurrentState == currentState || stones[y - 1, x + 1].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x + 2 > stones.GetLength(1) - 1 || y - 1 < 0)
         {
             return;
         }
         if (stones[y - 2, x + 2].CurrentState == currentState || stones[y - 2, x + 2].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x + 3 > stones.GetLength(1) - 1 || y - 1 < 0)
         {
             return;
         }
         if (stones[y - 3, x + 3].CurrentState != currentState)
         {
             return;
         }
         CurrentPlayer.Captures++;
         stones[y - 1, x + 1].CurrentState = StoneState.Open;
         stones[y - 2, x + 2].CurrentState = StoneState.Open;
     } catch { }
 }
Esempio n. 3
0
        private bool CheckDiagonalTria(int x, int y)
        {
            StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;

            Stone[,] stones = gameScreen.Stones;
            bool tria = false;

            if (x - 1 >= 0 && y - 1 >= 0 && stones[y - 1, x - 1].CurrentState == StoneState.Open)
            {
                if (x + 1 <= stones.GetLength(1) - 1 && y - 1 <= stones.GetLength(0) - 1 &&
                    stones[y + 1, x + 1].CurrentState == StoneState.Open)
                {
                    tria = CheckDiagDLtoURTria(currentState, stones, x, y);
                }
                else if (x + 1 <= stones.GetLength(1) - 1 && y + 1 <= stones.GetLength(0) - 1 &&
                         stones[y + 1, x + 1].CurrentState == currentState)
                {
                    if (x + 2 <= stones.GetLength(1) - 1 && y + 2 <= stones.GetLength(0) - 1 &&
                        stones[y + 2, x + 2].CurrentState == currentState)
                    {
                        if (x + 3 <= stones.GetLength(1) - 1 && y + 3 <= stones.GetLength(0) - 1 &&
                            stones[y + 3, x + 3].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x + 1 <= stones.GetLength(1) - 1 && y + 1 <= stones.GetLength(0) - 1 &&
                     stones[y + 1, x + 1].CurrentState == StoneState.Open)
            {
                if (x - 1 >= 0 && y - 1 >= 0 && stones[y - 1, x - 1].CurrentState == currentState)
                {
                    if (x - 2 >= 0 && y - 2 >= 0 && stones[y - 2, x - 2].CurrentState == currentState)
                    {
                        if (x - 3 >= 0 && y - 3 >= 0 && stones[y - 3, x - 3].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x + 1 <= stones.GetLength(1) - 1 && y + 1 <= stones.GetLength(0) - 1 &&
                     stones[y + 1, x + 1].CurrentState == currentState)
            {
                if (x - 1 >= 0 && y - 1 >= 0 && stones[y - 1, x - 1].CurrentState == currentState)
                {
                    if (x - 2 >= 0 && y - 2 >= 0 && stones[y - 2, x - 2].CurrentState == StoneState.Open)
                    {
                        if (x + 2 <= stones.GetLength(1) - 1 && y + 2 <= stones.GetLength(0) - 1 &&
                            stones[y + 2, x + 2].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            return(tria);
        }
Esempio n. 4
0
        private bool CheckDiagDLtoURTria(StoneState currentState, Stone[,] stones, int x, int y)
        {
            bool tria      = false;
            int  maxYBound = stones.GetLength(0) - 1;
            int  maxXBound = stones.GetLength(1) - 1;

            if (x + 1 <= maxXBound && y - 1 >= 0 && stones[y - 1, x + 1].CurrentState == StoneState.Open)
            {
                if (x - 1 >= 0 && y + 1 <= maxYBound && stones[y + 1, x - 1].CurrentState == currentState)
                {
                    if (x - 2 >= 0 && y + 2 <= maxYBound && stones[y + 2, x - 2].CurrentState == currentState)
                    {
                        if (x - 3 >= 0 && y + 3 <= maxYBound && stones[y + 3, x - 3].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x - 1 >= 0 && y + 1 <= maxYBound && stones[y + 1, x - 1].CurrentState == StoneState.Open)
            {
                if (x + 1 <= maxXBound && y - 1 >= 0 && stones[y - 1, x + 1].CurrentState == currentState)
                {
                    if (x + 2 <= maxXBound && y - 2 >= 0 && stones[y - 2, x + 2].CurrentState == currentState)
                    {
                        if (x + 3 <= maxXBound && y - 3 >= 0 && stones[y - 3, x + 3].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x + 1 <= maxXBound && y - 1 >= 0 && stones[y - 1, x + 1].CurrentState == currentState)
            {
                if (x - 1 >= 0 && y + 1 <= maxYBound && stones[y + 1, x - 1].CurrentState == currentState)
                {
                    if (x - 2 >= 0 && y + 2 <= maxYBound && stones[y + 2, x - 2].CurrentState == StoneState.Open)
                    {
                        if (x + 2 <= maxXBound && y - 2 >= 0 && stones[y - 2, x + 2].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            return(tria);
        }
Esempio n. 5
0
    // private method
    private void changeColor(StoneState state, int x, int z)
    {
        switch (state)
        {
        case StoneState.Black:
            createStones[x, z].transform.Rotate(180, 0, 0);
            break;

        case StoneState.White:
            createStones[x, z].transform.Rotate(0, 0, 0);
            createStones[x, z].SetActive(true);
            break;

        default:
            break;
        }
    }
Esempio n. 6
0
        private int CheckRowDiagonalRL(int x, int y)
        {
            int        count        = 0;
            StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;

            Stone[,] stones = gameScreen.Stones;
            for (int i = 0; i < 5; i++)
            {
                if (x - i < 0 || y - i < 0)
                {
                    break;
                }
                else
                {
                    if (stones[y - i, x - i].CurrentState == currentState)
                    {
                        count++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            for (int i = 1; i < 5; i++)
            {
                if (x + i > stones.GetLength(1) - 1 || y + i > stones.GetLength(0) - 1)
                {
                    break;
                }
                else
                {
                    if (stones[y + i, x + i].CurrentState == currentState)
                    {
                        count++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(count);
        }
Esempio n. 7
0
        private bool CheckVerticalTessera(int x, int y)
        {
            StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;

            Stone[,] stones = gameScreen.Stones;
            bool tessera   = false;
            int  maxYValue = stones.GetLength(0) - 1;
            int  maxXValue = stones.GetLength(1) - 1;
            bool startedT  = false;
            int  count     = 0;

            for (var i = 0; i < maxYValue; i++)
            {
                if (stones[i, x].CurrentState == currentState)
                {
                    if (!startedT && i - 1 >= 0 && stones[i - 1, x].CurrentState == StoneState.Open)
                    {
                        startedT = true;
                    }
                    if (startedT)
                    {
                        count++;
                    }
                }
                else if (stones[i, x].CurrentState == StoneState.Open)
                {
                    if (count == 4 && i - 1 >= 0 && stones[i - 1, x].CurrentState == currentState)
                    {
                        tessera = true;
                    }
                    else
                    {
                        startedT = false;
                        count    = 0;
                    }
                }
                else
                {
                    startedT = false;
                    count    = 0;
                }
            }
            return(tessera);
        }
Esempio n. 8
0
        private bool CheckDLtoURTessera(int x, int y)
        {
            StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;

            Stone[,] stones = gameScreen.Stones;
            bool tessera         = true;
            int  maxYValue       = stones.GetLength(0) - 1;
            int  maxXValue       = stones.GetLength(1) - 1;
            int  disFromCurPoint = 0;

            while (CheckBounds(x - disFromCurPoint, y + disFromCurPoint) && stones[y + disFromCurPoint, x - disFromCurPoint].CurrentState == currentState)
            {
                disFromCurPoint++;
            }

            disFromCurPoint--;
            int startX = x - disFromCurPoint;
            int startY = y + disFromCurPoint;

            for (int i = 0; i < 4; i++)
            {
                if (CheckBounds(startX + i, startY - i) && stones[startY - i, startX + i].CurrentState != currentState)
                {
                    tessera = false;
                    break;
                }
            }

            if (!CheckBounds(startX - 1, startY + 1) ||
                (CheckBounds(startX - 1, startY + 1) && stones[startY + 1, startX - 1].CurrentState != StoneState.Open))
            {
                if (!CheckBounds(startX + 4, startY - 4) ||
                    (CheckBounds(startX + 4, startY - 4) && stones[startY - 4, startX + 4].CurrentState != StoneState.Open))
                {
                    tessera = false;
                }
            }
            return(tessera);
        }
Esempio n. 9
0
 private void CheckCaptureULDiagonal(int x, int y)
 {
     try {
         Stone[,] stones = gameScreen.Stones;
         if (x < 3 || y < 3)
         {
             return;
         }
         StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;
         if (x - 1 < 0 || y - 1 < 0)
         {
             return;
         }
         if (stones[y - 1, x - 1].CurrentState == currentState || stones[y - 1, x - 1].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x - 2 < 0 || y - 2 < 0)
         {
             return;
         }
         if (stones[y - 2, x - 2].CurrentState == currentState || stones[y - 2, x - 2].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x - 3 < 0 || y - 3 < 0)
         {
             return;
         }
         if (stones[y - 3, x - 3].CurrentState != currentState || stones[y - 3, x - 3].CurrentState == StoneState.Open)
         {
             return;
         }
         CurrentPlayer.Captures++;
         stones[y - 1, x - 1].CurrentState = StoneState.Open;
         stones[y - 2, x - 2].CurrentState = StoneState.Open;
     } catch { }
 }
Esempio n. 10
0
 private void CheckCaptureDown(int x, int y)
 {
     try {
         Stone[,] stones = gameScreen.Stones;
         if (y > stones.GetLength(0) - 4)
         {
             return;
         }
         StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;
         if (y + 1 > stones.GetLength(0) - 1)
         {
             return;
         }
         if (stones[y + 1, x].CurrentState == currentState || stones[y + 1, x].CurrentState == StoneState.Open)
         {
             return;
         }
         if (y + 2 > stones.GetLength(0) - 1)
         {
             return;
         }
         if (stones[y + 2, x].CurrentState == currentState || stones[y + 2, x].CurrentState == StoneState.Open)
         {
             return;
         }
         if (y + 3 > stones.GetLength(0) - 1)
         {
             return;
         }
         if (stones[y + 3, x].CurrentState != currentState)
         {
             return;
         }
         CurrentPlayer.Captures++;
         stones[y + 1, x].CurrentState = StoneState.Open;
         stones[y + 2, x].CurrentState = StoneState.Open;
     } catch { }
 }
Esempio n. 11
0
 private void CheckCaptureRight(int x, int y)
 {
     try {
         Stone[,] stones = gameScreen.Stones;
         if (x > stones.GetLength(1) - 4)
         {
             return;
         }
         StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;
         if (x + 1 > stones.GetLength(1) - 1)
         {
             return;
         }
         if (stones[y, x + 1].CurrentState == currentState || stones[y, x + 1].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x + 2 > stones.GetLength(1) - 1)
         {
             return;
         }
         if (stones[y, x + 2].CurrentState == currentState || stones[y, x + 2].CurrentState == StoneState.Open)
         {
             return;
         }
         if (x + 3 > stones.GetLength(1) - 1)
         {
             return;
         }
         if (stones[y, x + 3].CurrentState != currentState)
         {
             return;
         }
         CurrentPlayer.Captures++;
         stones[y, x + 1].CurrentState = StoneState.Open;
         stones[y, x + 2].CurrentState = StoneState.Open;
     } catch { }
 }
Esempio n. 12
0
        private bool CheckVerticalTria(int x, int y)
        {
            Stone[,] stones = gameScreen.Stones;
            StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;
            bool       tria         = false;

            if (y == 0 || x == stones.GetLength(0) - 1)
            {
                tria = false;
            }
            if (y - 1 >= 0 && stones[y - 1, x].CurrentState == currentState)
            {
                if (y - 2 >= 0 && stones[y - 2, x].CurrentState == StoneState.Open)
                {
                    if (y + 1 <= stones.GetLength(0) - 1 && stones[y + 1, x].CurrentState == currentState)
                    {
                        if (y + 2 <= stones.GetLength(0) - 1 && stones[y + 2, x].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
                else if (y - 2 >= 0 && stones[y - 2, x].CurrentState == currentState)
                {
                    if (y - 3 >= 0 && stones[y - 3, x].CurrentState == StoneState.Open)
                    {
                        if (y + 1 <= stones.GetLength(1) - 1 && stones[y + 1, x].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (y - 1 >= 0 && stones[y - 1, x].CurrentState == StoneState.Open)
            {
                if (y + 1 <= stones.GetLength(0) - 1 && stones[y + 1, x].CurrentState == currentState)
                {
                    if (y + 2 <= stones.GetLength(0) - 1 && stones[y + 2, x].CurrentState == currentState)
                    {
                        if (y + 3 <= stones.GetLength(0) - 1 && stones[y + 3, x].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (y + 1 <= stones.GetLength(0) - 1 && stones[y + 1, x].CurrentState == StoneState.Open)
            {
                if (y - 1 >= 0 && stones[y - 1, x].CurrentState == currentState)
                {
                    if (y - 2 >= 0 && stones[y - 2, x].CurrentState == currentState)
                    {
                        if (y - 3 >= 0 && stones[y - 3, x].CurrentState == currentState)
                        {
                            if (y - 4 >= 0 && stones[y - 4, x].CurrentState == StoneState.Open)
                            {
                                tria = true;
                            }
                        }
                    }
                }
            }
            return(tria);
        }
Esempio n. 13
0
        private bool CheckHorizontalTria(int x, int y)
        {
            StoneState currentState = CurrentPlayer == Player1 ? StoneState.Black : StoneState.White;

            Stone[,] stones = gameScreen.Stones;
            bool tria = false;

            if (x == 0 || x == stones.GetLength(1) - 1)
            {
                tria = false;
            }
            if (x - 1 >= 0 && stones[y, x - 1].CurrentState == currentState)
            {
                if (x - 2 >= 0 && stones[y, x - 2].CurrentState == StoneState.Open)
                {
                    if (x + 1 <= stones.GetLength(1) - 1 && stones[y, x + 1].CurrentState == currentState)
                    {
                        if (x + 2 <= stones.GetLength(1) - 1 && stones[y, x + 2].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
                else if (x - 2 >= 0 && stones[y, x - 2].CurrentState == currentState)
                {
                    if (x - 3 >= 0 && stones[y, x - 3].CurrentState == StoneState.Open)
                    {
                        if (x + 1 <= stones.GetLength(1) - 1 && stones[y, x + 1].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x - 1 >= 0 && stones[y, x - 1].CurrentState == StoneState.Open)
            {
                if (x + 1 <= stones.GetLength(1) - 1 && stones[y, x + 1].CurrentState == currentState)
                {
                    if (x + 2 <= stones.GetLength(1) - 1 && stones[y, x + 2].CurrentState == currentState)
                    {
                        if (x + 3 <= stones.GetLength(1) - 1 && stones[y, x + 3].CurrentState == StoneState.Open)
                        {
                            tria = true;
                        }
                    }
                }
            }
            else if (x + 1 <= stones.GetLength(1) - 1 && stones[y, x + 1].CurrentState == StoneState.Open)
            {
                if (x - 1 >= 0 && stones[y, x - 1].CurrentState == currentState)
                {
                    if (x - 2 >= 0 && stones[y, x - 2].CurrentState == currentState)
                    {
                        if (x - 3 >= 0 && stones[y, x - 3].CurrentState == currentState)
                        {
                            if (x - 4 >= 0 && stones[y, x - 4].CurrentState == StoneState.Open)
                            {
                                tria = true;
                            }
                        }
                    }
                }
            }
            return(tria);
        }
Esempio n. 14
0
 public static Brush GetBrush(this StoneState state)
 {
     return(StoneStateToColor[state]);
 }
Esempio n. 15
0
 public Stone()
 {
     CurrentState = StoneState.Open;
     Foreground   = new SolidColorBrush(Colors.Transparent);
 }