示例#1
0
    private static bool CheckWinVerticalIA(ModelGrid grid, Cell cell)
    {
        Cell      neighbour;
        BallColor color = BallColor.Black;
        int       count = 1;

        List <Cell> patternCells = new List <Cell> ();

        patternCells.Add(cell);

        // down
        for (int i = 1; i < nBallToAlignVertically; i++)
        {
            neighbour = grid.GetCellFromModel(cell.x, cell.y - i * 2);

            if (!neighbour)
            {
                break;
            }

            if (neighbour.HasBall(color))
            {
                count++;
                patternCells.Add(neighbour);
            }

            else
            {
                break;
            }
        }

        //up
        for (int i = 1; i < nBallToAlignVertically; i++)
        {
            neighbour = grid.GetCellFromModel(cell.x, cell.y + i * 2);

            if (!neighbour)
            {
                break;
            }

            if (neighbour.HasBall(color))
            {
                count++;
                patternCells.Add(neighbour);
            }

            else
            {
                break;
            }
        }

        /*if(count >= nBallToAlignVertically)
         *      HighlighCells (patternCells, Color.red);*/


        return(count >= nBallToAlignVertically);
    }
示例#2
0
 private static bool CheckWinCrossNormal(ModelGrid grid, Cell cell, bool mustHighlight = true)
 {
     return(CheckCrossNormal(grid, cell, mustHighlight) ||
            CheckCrossNormal(grid, grid.GetCellFromModel(cell.x - 1, cell.y), mustHighlight) ||
            CheckCrossNormal(grid, grid.GetCellFromModel(cell.x + 1, cell.y), mustHighlight) ||
            CheckCrossNormal(grid, grid.GetCellFromModel(cell.x, cell.y + 2), mustHighlight) ||
            CheckCrossNormal(grid, grid.GetCellFromModel(cell.x, cell.y - 2), mustHighlight));
 }
示例#3
0
 private static bool CheckWinCrossNormalIA(ModelGrid grid, Cell cell)
 {
     return(CheckCrossNormalIA(grid, cell) ||
            CheckCrossNormalIA(grid, grid.GetCellFromModel(cell.x - 1, cell.y)) ||
            CheckCrossNormalIA(grid, grid.GetCellFromModel(cell.x + 1, cell.y)) ||
            CheckCrossNormalIA(grid, grid.GetCellFromModel(cell.x, cell.y + 2)) ||
            CheckCrossNormalIA(grid, grid.GetCellFromModel(cell.x, cell.y - 2)));
 }
示例#4
0
    private static bool CheckWinHorizontalIA(ModelGrid grid, Cell cell)
    {
        Cell neighbour;

        BallColor color = BallColor.Black;

        List <Cell> patternCells = new List <Cell> ();

        patternCells.Add(cell);
        int count = 1;

        // left
        for (int i = 1; i < nBallToAlignHorizontally; i++)
        {
            neighbour = grid.GetCellFromModel(cell.x - i, cell.y);

            if (!neighbour)
            {
                break;
            }

            if (neighbour.HasBall(color))
            {
                patternCells.Add(neighbour);
                count++;
            }
            else
            {
                break;
            }
        }

        //right
        for (int i = 1; i < nBallToAlignHorizontally; i++)
        {
            neighbour = grid.GetCellFromModel(cell.x + i, cell.y);

            if (!neighbour)
            {
                break;
            }

            if (neighbour.HasBall(color))
            {
                patternCells.Add(neighbour);
                count++;
            }
            else
            {
                break;
            }
        }

        /*if(count >= nBallToAlignHorizontally)
         *      HighlighCells (patternCells, Color.red);*/

        return(count >= nBallToAlignHorizontally);
    }
示例#5
0
    private static bool CheckWinCrossDiagonalIA(ModelGrid grid, Cell cell)
    {
        int offset = cell.y % 2;

        return(CheckCrossDiagonalIA(grid, cell) ||
               CheckCrossDiagonalIA(grid, grid.GetCellFromModel(cell.x - 1 + offset, cell.y + 1)) ||
               CheckCrossDiagonalIA(grid, grid.GetCellFromModel(cell.x + offset, cell.y + 1)) ||
               CheckCrossDiagonalIA(grid, grid.GetCellFromModel(cell.x - 1 + offset, cell.y - 1)) ||
               CheckCrossDiagonalIA(grid, grid.GetCellFromModel(cell.x + offset, cell.y - 1)));
    }
示例#6
0
    private static bool CheckWinCrossDiagonal(ModelGrid grid, Cell cell, bool mustHighlight = true)
    {
        int offset = cell.y % 2;

        return(CheckCrossDiagonal(grid, cell, mustHighlight) ||
               CheckCrossDiagonal(grid, grid.GetCellFromModel(cell.x - 1 + offset, cell.y + 1), mustHighlight) ||
               CheckCrossDiagonal(grid, grid.GetCellFromModel(cell.x + offset, cell.y + 1), mustHighlight) ||
               CheckCrossDiagonal(grid, grid.GetCellFromModel(cell.x - 1 + offset, cell.y - 1), mustHighlight) ||
               CheckCrossDiagonal(grid, grid.GetCellFromModel(cell.x + offset, cell.y - 1), mustHighlight));
    }
示例#7
0
    public int GetScore(ModelGrid grid)
    {
        int score = 0;

        score += grid.GetCellFromModel((int)cells[0].y, (int)cells[0].x).ball.Score;
        score += grid.GetCellFromModel((int)cells[1].y, (int)cells[1].x).ball.Score;
        score += grid.GetCellFromModel((int)cells[2].y, (int)cells[2].x).ball.Score;
        score += grid.GetCellFromModel((int)cells[3].y, (int)cells[3].x).ball.Score;
        score += grid.GetCellFromModel((int)cells[4].y, (int)cells[4].x).ball.Score;

        return(score);
    }
示例#8
0
 public void UpdateOptimizedGridPoints(ModelGrid modelGrid)
 {
     for (int i = 0; i < cells.Length; ++i)
     {
         for (int j = 0; j < cells[i].Length; ++j)
         {
             if (modelGrid.GetCellFromModel(i, j).ball != null && modelGrid.GetCellFromModel(i, j).ball.Score > 0)
             {
                 cells[i][j].isPoint = true;
             }
             else
             {
                 cells[i][j].isPoint = false;
             }
         }
     }
 }
示例#9
0
    public static List <Cell> GetCrossDiagonalCells(ModelGrid grid, Cell cell)
    {
        Cell        neighbour;
        List <Cell> crossDiagonal = new List <Cell> ();

        if (!cell)
        {
            return(crossDiagonal);
        }

        int offset = cell.y % 2;

        crossDiagonal.Add(cell);


        neighbour = grid.GetCellFromModel(cell.x - 1 + offset, cell.y + 1);
        if (neighbour)
        {
            crossDiagonal.Add(neighbour);
        }

        //top right
        neighbour = grid.GetCellFromModel(cell.x + offset, cell.y + 1);
        if (neighbour)
        {
            crossDiagonal.Add(neighbour);
        }

        //bottom left
        neighbour = grid.GetCellFromModel(cell.x - 1 + offset, cell.y - 1);
        if (neighbour)
        {
            crossDiagonal.Add(neighbour);
        }

        //bottom right
        neighbour = grid.GetCellFromModel(cell.x + offset, cell.y - 1);

        if (neighbour)
        {
            crossDiagonal.Add(neighbour);
        }

        return(crossDiagonal);
    }
示例#10
0
    public static List <Cell> GetCrossNormalCells(ModelGrid grid, Cell cell)
    {
        Cell        neighbour;
        List <Cell> crossNormalCells = new List <Cell> ();

        if (!cell)
        {
            return(crossNormalCells);
        }

        crossNormalCells.Add(cell);

        //left
        neighbour = grid.GetCellFromModel(cell.x - 1, cell.y);
        if (neighbour)
        {
            crossNormalCells.Add(neighbour);
        }

        //right
        neighbour = grid.GetCellFromModel(cell.x + 1, cell.y);
        if (neighbour)
        {
            crossNormalCells.Add(neighbour);
        }

        //up
        neighbour = grid.GetCellFromModel(cell.x, cell.y + 2);
        if (neighbour)
        {
            crossNormalCells.Add(neighbour);
        }

        //down
        neighbour = grid.GetCellFromModel(cell.x, cell.y - 2);
        if (neighbour)
        {
            crossNormalCells.Add(neighbour);
        }
        return(crossNormalCells);
    }
示例#11
0
    public static List <Cell> GetHorizontalCells(ModelGrid grid, Cell cell)
    {
        Cell        neighbour;
        List <Cell> horizontalCells = new List <Cell> ();

        for (int i = 0; i < nBallToAlignVertically; i++)
        {
            neighbour = grid.GetCellFromModel(i, cell.y);

            if (!neighbour)
            {
                continue;
            }

            horizontalCells.Add(neighbour);
        }

        return(horizontalCells);
    }
示例#12
0
    public static List <Cell> GetVerticalCells(ModelGrid grid, Cell cell)
    {
        Cell        neighbour;
        List <Cell> verticalCells = new List <Cell> ();

        if (cell.y % 2 == 1)
        {
            return(verticalCells);
        }

        for (int i = 0; i < nBallToAlignVertically; i++)
        {
            neighbour = grid.GetCellFromModel(cell.x, i * 2);

            if (!neighbour)
            {
                continue;
            }

            verticalCells.Add(neighbour);
        }

        return(verticalCells);
    }
示例#13
0
    private static bool CheckWinDiagonalBottomRightToTopLeftIA(ModelGrid grid, Cell cell)
    {
        Cell      neighbour;
        BallColor color;

        if (!cell.ball)
        {
            color = BallColor.Black;
        }
        else
        {
            color = cell.ball.Color;
        }
        int count = 1;

        List <Cell> patternCells = new List <Cell> ();

        patternCells.Add(cell);

        int offset = cell.y % 2;

        if (offset == 0)
        {
            //top
            for (int i = 1; i < nBallToAlignVertically; i++)
            {
                neighbour = grid.GetCellFromModel(cell.x - Mathf.CeilToInt(i / 2f), cell.y + i);

                if (!neighbour)
                {
                    break;
                }

                if (neighbour.HasBall(color))
                {
                    patternCells.Add(neighbour);
                    count++;
                }
                else
                {
                    break;
                }
            }

            //bottom
            for (int i = 1; i < nBallToAlignVertically; i++)
            {
                neighbour = grid.GetCellFromModel(cell.x + i / 2, cell.y - i);

                if (!neighbour)
                {
                    break;
                }

                if (neighbour.HasBall(color))
                {
                    patternCells.Add(neighbour);
                    count++;
                }
                else
                {
                    break;
                }
            }
        }
        else
        {
            //top
            for (int i = 1; i < nBallToAlignVertically; i++)
            {
                neighbour = grid.GetCellFromModel(cell.x - i / 2, cell.y + i);

                if (!neighbour)
                {
                    break;
                }

                if (neighbour.HasBall(color))
                {
                    patternCells.Add(neighbour);
                    count++;
                }
                else
                {
                    break;
                }
            }

            //bottom
            for (int i = 1; i < nBallToAlignVertically; i++)
            {
                neighbour = grid.GetCellFromModel(cell.x + Mathf.CeilToInt(i / 2f), cell.y - i);

                if (!neighbour)
                {
                    break;
                }

                if (neighbour.HasBall(color))
                {
                    patternCells.Add(neighbour);
                    count++;
                }
                else
                {
                    break;
                }
            }
        }

        /*if(count >= nBallToAlignHorizontally)
         *      HighlighCells (patternCells, Color.red);*/

        return(count >= nBallToAlignHorizontally);
    }
示例#14
0
    public static List <Cell> GetDiagonalBottomLeftToTopRightCells(ModelGrid grid, Cell cell)
    {
        Cell        neighbour;
        List <Cell> diagonalCells = new List <Cell> ();
        int         offset        = cell.y % 2;

        diagonalCells.Add(cell);

        if (offset == 0)
        {
            //top
            for (int i = 1; i < nBallToAlignVertically; i++)
            {
                neighbour = grid.GetCellFromModel(cell.x + i / 2, cell.y + i);

                if (!neighbour)
                {
                    continue;
                }

                diagonalCells.Add(neighbour);
            }

            //bottom
            for (int i = 1; i < nBallToAlignVertically; i++)
            {
                neighbour = grid.GetCellFromModel(cell.x - Mathf.CeilToInt(i / 2f), cell.y - i);

                if (!neighbour)
                {
                    continue;
                }

                diagonalCells.Add(neighbour);
            }
        }
        else
        {
            //top
            for (int i = 1; i < nBallToAlignVertically; i++)
            {
                neighbour = grid.GetCellFromModel(cell.x + Mathf.CeilToInt(i / 2f), cell.y + i);

                if (!neighbour)
                {
                    continue;
                }

                diagonalCells.Add(neighbour);
            }

            //bottom
            for (int i = 1; i < nBallToAlignVertically; i++)
            {
                neighbour = grid.GetCellFromModel(cell.x - i / 2, cell.y - i);

                if (!neighbour)
                {
                    continue;
                }

                diagonalCells.Add(neighbour);
            }
        }
        return(diagonalCells);
    }
示例#15
0
    private static bool CheckCrossDiagonalIA(ModelGrid grid, Cell cell)
    {
        if (!cell)
        {
            return(false);
        }
        {
            if (!cell.HasBall())
            {
                return(false);
            }
        }

        Cell      neighbour;
        BallColor color;

        if (!cell.ball)
        {
            color = BallColor.White;
        }
        else
        {
            color = cell.ball.Color;
        }
        int offset = cell.y % 2;

        List <Cell> patternCells = new List <Cell> ();

        patternCells.Add(cell);

        //top left


        neighbour = grid.GetCellFromModel(cell.x - 1 + offset, cell.y + 1);


        if (!neighbour)
        {
            return(false);
        }

        if (!neighbour.HasBall(color))
        {
            return(false);
        }

        patternCells.Add(neighbour);

        //top right
        neighbour = grid.GetCellFromModel(cell.x + offset, cell.y + 1);


        if (!neighbour)
        {
            return(false);
        }

        if (!neighbour.HasBall(color))
        {
            return(false);
        }


        patternCells.Add(neighbour);

        //bottom left
        neighbour = grid.GetCellFromModel(cell.x - 1 + offset, cell.y - 1);

        if (!neighbour)
        {
            return(false);
        }

        if (!neighbour.HasBall(color))
        {
            return(false);
        }

        patternCells.Add(neighbour);

        //bottom right
        neighbour = grid.GetCellFromModel(cell.x + offset, cell.y - 1);


        if (!neighbour)
        {
            return(false);
        }

        if (!neighbour.HasBall(color))
        {
            return(false);
        }

        patternCells.Add(neighbour);

        //HighlighCells (patternCells, Color.red);

        return(true);
    }
示例#16
0
    public void PlayerTurnEnded(List <Vector2> movements, int ballId)
    {
        lastTurnMoves  = movements;
        lastTurnBallId = ballId;

        Cell cell = modelGrid.GetCellFromModel((int)movements[movements.Count - 1].x, (int)movements[movements.Count - 1].y);

        bool justWon = Utils.CheckWin(modelGrid, cell, false);

        if (justWon || isEqualityTurn)
        {
            if (justWon)
            {
                DOVirtual.DelayedCall(timeBeforeVictoryAnimation, PlayVictoryAnimation);
                //SendLastTurnData();
                //AlreadySentLastTurnData = true;
            }

            if (!isEqualityTurn && (PlayerManager.Instance.Player1.NbOfTurn != PlayerManager.Instance.Player2.NbOfTurn))
            {
                isEqualityTurn = true;
            }
            else
            {
                EndGame(justWon);
                return;
            }
        }

        if (PlayerManager.Instance.GetPlayer(BallColor.Black).NbOfTurn == 10 && PlayerManager.Instance.GetPlayer(BallColor.White).NbOfTurn == 10 && isPlayingTutorial)
        {
            OnPhase2Begin();
            return;
        }

        if (!justWon && !isEqualityTurn)
        {
            NextTurn();
        }
    }
示例#17
0
    private static bool CheckCrossNormalIA(ModelGrid grid, Cell cell)
    {
        if (!cell)
        {
            return(false);
        }


        if (!cell.HasBall())
        {
            return(false);
        }

        Cell      neighbour;
        BallColor color;

        if (!cell.ball)
        {
            color = BallColor.White;
        }
        else
        {
            color = cell.ball.Color;
        }

        List <Cell> patternCells = new List <Cell> ();

        patternCells.Add(cell);

        //left
        neighbour = grid.GetCellFromModel(cell.x - 1, cell.y);

        if (!neighbour)
        {
            return(false);
        }

        if (!neighbour.HasBall(color))
        {
            return(false);
        }

        patternCells.Add(neighbour);

        //right
        neighbour = grid.GetCellFromModel(cell.x + 1, cell.y);

        if (!neighbour)
        {
            return(false);
        }

        if (!neighbour.HasBall(color))
        {
            return(false);
        }


        patternCells.Add(neighbour);

        //up
        neighbour = grid.GetCellFromModel(cell.x, cell.y + 2);

        if (!neighbour)
        {
            return(false);
        }

        if (!neighbour.HasBall(color))
        {
            return(false);
        }


        patternCells.Add(neighbour);

        //down
        neighbour = grid.GetCellFromModel(cell.x, cell.y - 2);

        if (!neighbour)
        {
            return(false);
        }

        if (!neighbour.HasBall(color))
        {
            return(false);
        }

        patternCells.Add(neighbour);

        //HighlighCells (patternCells, Color.red);

        return(true);
    }